xref: /llvm-project/llvm/lib/DebugInfo/PDB/DIA/DIASectionContrib.cpp (revision 523de05a1faafe9846608b796b5d7d5b51f4e6cf)
1 //===- DIASectionContrib.cpp - DIA impl. of IPDBSectionContrib ---- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/DebugInfo/PDB/DIA/DIARawSymbol.h"
11 #include "llvm/DebugInfo/PDB/DIA/DIASectionContrib.h"
12 #include "llvm/DebugInfo/PDB/DIA/DIASession.h"
13 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
14 
15 using namespace llvm;
16 using namespace llvm::pdb;
17 
18 DIASectionContrib::DIASectionContrib(const DIASession &PDBSession,
19                                      CComPtr<IDiaSectionContrib> DiaSection)
20   : Session(PDBSession), Section(DiaSection) {}
21 
22 std::unique_ptr<PDBSymbolCompiland> DIASectionContrib::getCompiland() const {
23   CComPtr<IDiaSymbol> Symbol;
24   if (FAILED(Section->get_compiland(&Symbol)))
25     return nullptr;
26 
27   auto RawSymbol = llvm::make_unique<DIARawSymbol>(Session, Symbol);
28   return llvm::make_unique<PDBSymbolCompiland>(Session, std::move(RawSymbol));
29 }
30 
31 template <typename ArgType>
32 ArgType PrivateGetDIAValue(
33     IDiaSectionContrib *Section,
34     HRESULT(__stdcall IDiaSectionContrib::*Method)(ArgType *)) {
35   ArgType Value;
36   if (S_OK == (Section->*Method)(&Value))
37     return static_cast<ArgType>(Value);
38 
39   return ArgType();
40 }
41 
42 template <typename ArgType, typename RetType>
43 RetType PrivateGetDIAValue(
44     IDiaSectionContrib *Section,
45     HRESULT(__stdcall IDiaSectionContrib::*Method)(ArgType *)) {
46   ArgType Value;
47   if (S_OK == (Section->*Method)(&Value))
48     return static_cast<RetType>(Value);
49 
50   return RetType();
51 }
52 
53 uint32_t DIASectionContrib::getAddressSection() const {
54   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_addressSection);
55 }
56 
57 uint32_t DIASectionContrib::getAddressOffset() const {
58   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_addressOffset);
59 }
60 
61 uint64_t DIASectionContrib::getVirtualAddress() const {
62   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_virtualAddress);
63 }
64 
65 uint32_t DIASectionContrib::getRelativeVirtualAddress() const {
66   return PrivateGetDIAValue(Section,
67                             &IDiaSectionContrib::get_relativeVirtualAddress);
68 }
69 uint32_t DIASectionContrib::getLength() const {
70   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_length);
71 }
72 
73 bool DIASectionContrib::isNotPaged() const {
74   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_notPaged);
75 }
76 
77 bool DIASectionContrib::hasCode() const {
78   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_code);
79 }
80 
81 bool DIASectionContrib::hasCode16Bit() const {
82   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_code16bit);
83 }
84 
85 bool DIASectionContrib::hasInitializedData() const {
86   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_initializedData);
87 }
88 
89 bool DIASectionContrib::hasUninitializedData() const {
90   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_uninitializedData);
91 }
92 
93 bool DIASectionContrib::isRemoved() const {
94   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_remove);
95 }
96 
97 bool DIASectionContrib::hasComdat() const {
98   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_comdat);
99 }
100 
101 bool DIASectionContrib::isDiscardable() const {
102   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_discardable);
103 }
104 
105 bool DIASectionContrib::isNotCached() const {
106   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_notCached);
107 }
108 
109 bool DIASectionContrib::isShared() const {
110   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_share);
111 }
112 
113 bool DIASectionContrib::isExecutable() const {
114   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_execute);
115 }
116 
117 bool DIASectionContrib::isReadable() const {
118   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_read);
119 }
120 
121 bool DIASectionContrib::isWritable() const {
122   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_write);
123 }
124 
125 uint32_t DIASectionContrib::getDataCrc32() const {
126   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_dataCrc);
127 }
128 
129 uint32_t DIASectionContrib::getRelocationsCrc32() const {
130   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_relocationsCrc);
131 }
132 
133 uint32_t DIASectionContrib::getCompilandId() const {
134   return PrivateGetDIAValue(Section, &IDiaSectionContrib::get_compilandId);
135 }
136