llvm.org GIT mirror llvm / 4dc79d9
[DebugInfo/PDB] Adding getUndecoratedNameEx and IPDB interfaces for IDiaEnumTables and IDiaTable. Initial changes to support debugging PE/COFF files with LLDB on Windows through DIA SDK. There is another set of changes required on the LLDB side before this does anything. Differential Revision: https://reviews.llvm.org/D39517 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318403 91177308-0d34-0410-b5e6-96231b3b80d8 Aaron Smith 1 year, 11 months ago
19 changed file(s) with 297 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
0 //===- DIAEnumTables.h - DIA Tables Enumerator Impl -------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_DEBUGINFO_PDB_DIA_DIAENUMTABLES_H
10 #define LLVM_DEBUGINFO_PDB_DIA_DIAENUMTABLES_H
11
12 #include "DIASupport.h"
13 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
14 #include "llvm/DebugInfo/PDB/IPDBTable.h"
15
16 namespace llvm {
17 namespace pdb {
18 class IPDBTable;
19
20 class DIAEnumTables : public IPDBEnumChildren {
21 public:
22 explicit DIAEnumTables(CComPtr DiaEnumerator);
23
24 uint32_t getChildCount() const override;
25 std::unique_ptr getChildAtIndex(uint32_t Index) const override;
26 std::unique_ptr getNext() override;
27 void reset() override;
28 DIAEnumTables *clone() const override;
29
30 private:
31 CComPtr Enumerator;
32 };
33 }
34 }
35
36 #endif // LLVM_DEBUGINFO_PDB_DIA_DIAENUMTABLES_H
9595 uint32_t getTypeId() const override;
9696 uint32_t getUavSlot() const override;
9797 std::string getUndecoratedName() const override;
98 std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override;
9899 uint32_t getUnmodifiedTypeId() const override;
99100 uint32_t getUpperBoundId() const override;
100101 Variant getValue() const override;
6363
6464 std::unique_ptr getDebugStreams() const override;
6565
66 std::unique_ptr getEnumTables() const override;
6667 private:
6768 CComPtr Session;
6869 };
0 //===- DIATable.h - DIA implementation of IPDBTable -------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_DEBUGINFO_PDB_DIA_DIATABLE_H
10 #define LLVM_DEBUGINFO_PDB_DIA_DIATABLE_H
11
12 #include "DIASupport.h"
13 #include "llvm/DebugInfo/PDB/IPDBTable.h"
14
15 namespace llvm {
16 namespace pdb {
17 class DIATable : public IPDBTable {
18 public:
19 explicit DIATable(CComPtr DiaTable);
20
21 uint32_t getItemCount() const override;
22 std::string getName() const override;
23 PDB_TableType getTableType() const override;
24
25 private:
26 CComPtr Table;
27 };
28 }
29 }
30
31 #endif // LLVM_DEBUGINFO_PDB_DIA_DIATABLE_H
107107 virtual uint32_t getTypeId() const = 0;
108108 virtual uint32_t getUavSlot() const = 0;
109109 virtual std::string getUndecoratedName() const = 0;
110 virtual std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const = 0;
110111 virtual uint32_t getUnmodifiedTypeId() const = 0;
111112 virtual uint32_t getUpperBoundId() const = 0;
112113 virtual Variant getValue() const = 0;
6666 getSourceFileById(uint32_t FileId) const = 0;
6767
6868 virtual std::unique_ptr getDebugStreams() const = 0;
69
70 virtual std::unique_ptr getEnumTables() const = 0;
6971 };
7072 }
7173 }
0 //===- IPDBTable.h - Base Interface for a PDB Symbol Context ----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_DEBUGINFO_PDB_IPDBTABLE_H
10 #define LLVM_DEBUGINFO_PDB_IPDBTABLE_H
11
12 #include "PDBTypes.h"
13
14 namespace llvm {
15 namespace pdb {
16 class IPDBTable {
17 public:
18 virtual ~IPDBTable();
19
20 virtual std::string getName() const = 0;
21 virtual uint32_t getItemCount() const = 0;
22 virtual PDB_TableType getTableType() const = 0;
23 };
24 }
25 }
26
27 #endif // LLVM_DEBUGINFO_PDB_IPDBTABLE_H
100100 uint32_t getTypeId() const override;
101101 uint32_t getUavSlot() const override;
102102 std::string getUndecoratedName() const override;
103 std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override;
103104 uint32_t getUnmodifiedTypeId() const override;
104105 uint32_t getUpperBoundId() const override;
105106 Variant getValue() const override;
8181
8282 std::unique_ptr getDebugStreams() const override;
8383
84 std::unique_ptr getEnumTables() const override;
85
8486 PDBFile &getPDBFile() { return *Pdb; }
8587 const PDBFile &getPDBFile() const { return *Pdb; }
8688
2323 class IPDBDataStream;
2424 class IPDBLineNumber;
2525 class IPDBSourceFile;
26 class IPDBTable;
2627 class PDBSymDumper;
2728 class PDBSymbol;
2829 class PDBSymbolExe;
6162 using IPDBEnumSourceFiles = IPDBEnumChildren;
6263 using IPDBEnumDataStreams = IPDBEnumChildren;
6364 using IPDBEnumLineNumbers = IPDBEnumChildren;
65 using IPDBEnumTables = IPDBEnumChildren;
6466
6567 /// Specifies which PDB reader implementation is to be used. Only a value
6668 /// of PDB_ReaderType::DIA is currently supported, but Native is in the works.
7173
7274 /// An enumeration indicating the type of data contained in this table.
7375 enum class PDB_TableType {
76 TableInvalid = 0,
7477 Symbols,
7578 SourceFiles,
7679 LineNumbers,
7780 SectionContribs,
7881 Segments,
7982 InjectedSources,
80 FrameData
83 FrameData,
84 InputAssemblyFiles,
85 Dbg
8186 };
8287
8388 /// Defines flags used for enumerating child symbols. This corresponds to the
240245 HResult = 31
241246 };
242247
248 /// These values correspond to the flags that can be combined to control the
249 /// return of an undecorated name for a C++ decorated name, and are documented
250 /// here: https://msdn.microsoft.com/en-us/library/kszfk0fs.aspx
251 enum PDB_UndnameFlags: uint32_t {
252 Undname_Complete = 0x0,
253 Undname_NoLeadingUnderscores = 0x1,
254 Undname_NoMsKeywords = 0x2,
255 Undname_NoFuncReturns = 0x4,
256 Undname_NoAllocModel = 0x8,
257 Undname_NoAllocLang = 0x10,
258 Undname_Reserved1 = 0x20,
259 Undname_Reserved2 = 0x40,
260 Undname_NoThisType = 0x60,
261 Undname_NoAccessSpec = 0x80,
262 Undname_NoThrowSig = 0x100,
263 Undname_NoMemberType = 0x200,
264 Undname_NoReturnUDTModel = 0x400,
265 Undname_32BitDecode = 0x800,
266 Undname_NameOnly = 0x1000,
267 Undname_TypeOnly = 0x2000,
268 Undname_HaveParams = 0x4000,
269 Undname_NoECSU = 0x8000,
270 Undname_NoIdentCharCheck = 0x10000,
271 Undname_NoPTR64 = 0x20000
272 };
273
243274 enum class PDB_MemberAccess { Private = 1, Protected = 2, Public = 3 };
244275
245276 struct VersionInfo {
1616 DIA/DIAEnumLineNumbers.cpp
1717 DIA/DIAEnumSourceFiles.cpp
1818 DIA/DIAEnumSymbols.cpp
19 DIA/DIAEnumTables.cpp
1920 DIA/DIAError.cpp
2021 DIA/DIALineNumber.cpp
2122 DIA/DIARawSymbol.cpp
2223 DIA/DIASession.cpp
2324 DIA/DIASourceFile.cpp
25 DIA/DIATable.cpp
2426 )
2527
2628 set(LIBPDB_ADDITIONAL_HEADER_DIRS "${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/PDB/DIA")
0 //===- DIAEnumTables.cpp - DIA Table Enumerator Impl ------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/DebugInfo/PDB/DIA/DIAEnumTables.h"
10 #include "llvm/DebugInfo/PDB/DIA/DIATable.h"
11
12 using namespace llvm;
13 using namespace llvm::pdb;
14
15 DIAEnumTables::DIAEnumTables(
16 CComPtr DiaEnumerator)
17 : Enumerator(DiaEnumerator) {}
18
19 uint32_t DIAEnumTables::getChildCount() const {
20 LONG Count = 0;
21 return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0;
22 }
23
24 std::unique_ptr
25 DIAEnumTables::getChildAtIndex(uint32_t Index) const {
26 CComPtr Item;
27 VARIANT Var;
28 Var.vt = VT_UINT;
29 Var.uintVal = Index;
30 if (S_OK != Enumerator->Item(Var, &Item))
31 return nullptr;
32
33 return std::unique_ptr(new DIATable(Item));
34 }
35
36 std::unique_ptr DIAEnumTables::getNext() {
37 CComPtr Item;
38 ULONG CeltFetched = 0;
39 if (S_OK != Enumerator->Next(1, &Item, &CeltFetched))
40 return nullptr;
41
42 return std::unique_ptr(new DIATable(Item));
43 }
44
45 void DIAEnumTables::reset() { Enumerator->Reset(); }
46
47 DIAEnumTables *DIAEnumTables::clone() const {
48 CComPtr EnumeratorClone;
49 if (S_OK != Enumerator->Clone(&EnumeratorClone))
50 return nullptr;
51 return new DIAEnumTables(EnumeratorClone);
52 }
438438 Symbol->get_dataBytes(DataSize, &DataSize, bytes.data());
439439 }
440440
441 std::string
442 DIARawSymbol::getUndecoratedNameEx(PDB_UndnameFlags Flags) const {
443 CComBSTR Result16;
444 if (S_OK != Symbol->get_undecoratedNameEx((DWORD)Flags, &Result16))
445 return std::string();
446
447 const char *SrcBytes = reinterpret_cast(Result16.m_str);
448 llvm::ArrayRef SrcByteArray(SrcBytes, Result16.ByteLength());
449 std::string Result8;
450 if (!llvm::convertUTF16ToUTF8String(SrcByteArray, Result8))
451 return std::string();
452 return Result8;
453 }
454
441455 PDB_MemberAccess DIARawSymbol::getAccess() const {
442456 return PrivateGetDIAValue(Symbol,
443457 &IDiaSymbol::get_access);
1010 #include "llvm/DebugInfo/PDB/DIA/DIAEnumDebugStreams.h"
1111 #include "llvm/DebugInfo/PDB/DIA/DIAEnumLineNumbers.h"
1212 #include "llvm/DebugInfo/PDB/DIA/DIAEnumSourceFiles.h"
13 #include "llvm/DebugInfo/PDB/DIA/DIAEnumTables.h"
1314 #include "llvm/DebugInfo/PDB/DIA/DIAError.h"
1415 #include "llvm/DebugInfo/PDB/DIA/DIARawSymbol.h"
1516 #include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h"
300301
301302 return llvm::make_unique(DiaEnumerator);
302303 }
304
305 std::unique_ptr DIASession::getEnumTables() const {
306 CComPtr DiaEnumerator;
307 if (S_OK != Session->getEnumTables(&DiaEnumerator))
308 return nullptr;
309
310 return llvm::make_unique(DiaEnumerator);
311 }
0 //===- DIATable.cpp - DIA implementation of IPDBTable -----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/DebugInfo/PDB/DIA/DIATable.h"
10 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/Support/ConvertUTF.h"
12
13 using namespace llvm;
14 using namespace llvm::pdb;
15
16 DIATable::DIATable(CComPtr DiaTable)
17 : Table(DiaTable) {}
18
19 uint32_t DIATable::getItemCount() const {
20 LONG Count = 0;
21 return (S_OK == Table->get_Count(&Count)) ? Count : 0;
22 }
23
24 std::string DIATable::getName() const {
25 CComBSTR Name16;
26 if (S_OK != Table->get_name(&Name16))
27 return std::string();
28
29 std::string Name8;
30 llvm::ArrayRef Name16Bytes(reinterpret_cast(Name16.m_str),
31 Name16.ByteLength());
32 if (!llvm::convertUTF16ToUTF8String(Name16Bytes, Name8))
33 return std::string();
34 return Name8;
35 }
36
37 PDB_TableType DIATable::getTableType() const {
38 CComBSTR Name16;
39 if (S_OK != Table->get_name(&Name16))
40 return PDB_TableType::TableInvalid;
41
42 if (Name16 == DiaTable_Symbols)
43 return PDB_TableType::Symbols;
44 if (Name16 == DiaTable_SrcFiles)
45 return PDB_TableType::SourceFiles;
46 if (Name16 == DiaTable_Sections)
47 return PDB_TableType::SectionContribs;
48 if (Name16 == DiaTable_LineNums)
49 return PDB_TableType::LineNumbers;
50 if (Name16 == DiaTable_SegMap)
51 return PDB_TableType::Segments;
52 if (Name16 == DiaTable_InjSrc)
53 return PDB_TableType::InjectedSources;
54 if (Name16 == DiaTable_FrameData)
55 return PDB_TableType::FrameData;
56 if (Name16 == DiaTable_InputAssemblyFiles)
57 return PDB_TableType::InputAssemblyFiles;
58 if (Name16 == DiaTable_Dbg)
59 return PDB_TableType::Dbg;
60 }
285285 return {};
286286 }
287287
288 std::string NativeRawSymbol::getUndecoratedNameEx(
289 PDB_UndnameFlags Flags) const {
290 return {};
291 }
292
288293 uint32_t NativeRawSymbol::getUnmodifiedTypeId() const {
289294 return 0;
290295 }
244244 std::unique_ptr NativeSession::getDebugStreams() const {
245245 return nullptr;
246246 }
247
248 std::unique_ptr NativeSession::getEnumTables() const {
249 return nullptr;
250 }
1414 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
1515 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
1616 #include "llvm/DebugInfo/PDB/IPDBSession.h"
17 #include "llvm/DebugInfo/PDB/IPDBTable.h"
1718
1819 using namespace llvm;
1920 using namespace llvm::pdb;
2526 IPDBRawSymbol::~IPDBRawSymbol() = default;
2627
2728 IPDBLineNumber::~IPDBLineNumber() = default;
29
30 IPDBTable::~IPDBTable() = default;
1313 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
1414 #include "llvm/DebugInfo/PDB/IPDBSession.h"
1515 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
16 #include "llvm/DebugInfo/PDB/IPDBTable.h"
1617
1718 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
1819 #include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h"
117118 std::unique_ptr getDebugStreams() const override {
118119 return nullptr;
119120 }
121
122 std::unique_ptr getEnumTables() const override {
123 return nullptr;
124 }
120125 };
121126
122127 class MockRawSymbol : public IPDBRawSymbol {
150155 void getBackEndVersion(VersionInfo &Version) const override {}
151156
152157 PDB_SymType getSymTag() const override { return Type; }
158
159 std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override {
160 return {};
161 }
153162
154163 MOCK_SYMBOL_ACCESSOR(getAccess)
155164 MOCK_SYMBOL_ACCESSOR(getAddressOffset)