1 //===- CompilandDumper.cpp - llvm-pdbdump compiland symbol dumper *- C++ *-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "CompilandDumper.h"
11 #include "llvm-pdbdump.h"
13 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
14 #include "llvm/DebugInfo/PDB/IPDBSession.h"
15 #include "llvm/DebugInfo/PDB/PDBExtras.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
26 #include "llvm/Support/Format.h"
27 #include "llvm/Support/Path.h"
28 #include "llvm/Support/raw_ostream.h"
30 #include "FunctionDumper.h"
37 CompilandDumper::CompilandDumper() : PDBSymDumper(true) {}
39 void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol,
40 raw_ostream &OS, int Indent) {}
42 void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol, raw_ostream &OS,
45 void CompilandDumper::start(const PDBSymbolCompiland &Symbol, raw_ostream &OS,
46 int Indent, bool Children) {
47 std::string FullName = Symbol.getName();
48 OS << newline(Indent) << FullName;
52 auto ChildrenEnum = Symbol.findAllChildren();
53 while (auto Child = ChildrenEnum->getNext())
54 Child->dump(OS, Indent + 2, *this);
57 void CompilandDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS,
59 OS << newline(Indent);
60 switch (auto LocType = Symbol.getLocationType()) {
61 case PDB_LocType::Static:
63 OS << format_hex(Symbol.getRelativeVirtualAddress(), 10);
66 case PDB_LocType::Constant:
67 OS << "constant: [" << Symbol.getValue() << "]";
70 OS << "data(unexpected type=" << LocType << ")";
73 OS << " " << Symbol.getName();
76 void CompilandDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS,
78 uint32_t FuncStart = Symbol.getRelativeVirtualAddress();
79 uint32_t FuncEnd = FuncStart + Symbol.getLength();
80 OS << newline(Indent) << "func [" << format_hex(FuncStart, 8);
81 if (auto DebugStart = Symbol.findOneChild<PDBSymbolFuncDebugStart>())
82 OS << "+" << DebugStart->getRelativeVirtualAddress() - FuncStart;
83 OS << " - " << format_hex(FuncEnd, 8);
84 if (auto DebugEnd = Symbol.findOneChild<PDBSymbolFuncDebugEnd>())
85 OS << "-" << FuncEnd - DebugEnd->getRelativeVirtualAddress();
88 if (Symbol.hasFramePointer())
89 OS << "(" << Symbol.getLocalBasePointerRegisterId() << ")";
95 FunctionDumper Dumper;
96 Dumper.start(Symbol, OS);
100 void CompilandDumper::dump(const PDBSymbolLabel &Symbol, raw_ostream &OS,
102 OS << newline(Indent);
103 OS << "label [" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "] "
107 void CompilandDumper::dump(const PDBSymbolThunk &Symbol, raw_ostream &OS,
109 OS << newline(Indent) << "thunk ";
110 PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
111 uint32_t RVA = Symbol.getRelativeVirtualAddress();
112 if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) {
113 OS << format_hex(RVA, 10);
114 OS << " -> " << format_hex(Symbol.getTargetRelativeVirtualAddress(), 10);
116 OS << "[" << format_hex(RVA, 10);
117 OS << " - " << format_hex(RVA + Symbol.getLength(), 10) << "]";
119 OS << " (" << Ordinal << ") ";
120 std::string Name = Symbol.getName();
125 void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
128 void CompilandDumper::dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS,
130 OS << newline(Indent);
131 OS << "unknown (" << Symbol.getSymTag() << ")";