llvm.org GIT mirror llvm / 7c69a58
[llvm-pdbdump] Support dynamic load address and external symbols. This patch adds the --load-address command line option to llvm-pdbdump, which dumps all addresses assuming the module has loaded at the specified address. Additionally, this patch adds an option to llvm-pdbdump to support dumping of public symbols (i.e. symbols with external linkage). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236342 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 4 years ago
14 changed file(s) with 135 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
2929 std::unique_ptr getSymbolById(uint32_t SymbolId) const override;
3030
3131 std::unique_ptr
32 findSymbolByAddress(uint64_t Address) const override;
32 findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override;
33
3334 std::unique_ptr
3435 findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override;
3536
4343 }
4444
4545 virtual std::unique_ptr
46 findSymbolByAddress(uint64_t Address) const = 0;
46 findSymbolByAddress(uint64_t Address, PDB_SymType Type) const = 0;
4747 virtual std::unique_ptr
4848 findLineNumbersByAddress(uint64_t Address, uint32_t Length) const = 0;
4949
3131
3232 public:
3333 PDBContext(const object::COFFObjectFile &Object,
34 std::unique_ptr PDBSession);
34 std::unique_ptr PDBSession, bool RelativeAddress);
3535
3636 static bool classof(const DIContext *DICtx) {
3737 return DICtx->getKind() == CK_PDB;
140140 }
141141
142142 std::unique_ptr
143 DIASession::findSymbolByAddress(uint64_t Address) const {
143 DIASession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
144 enum SymTagEnum EnumVal = static_cast(Type);
145
144146 CComPtr Symbol;
145 if (S_OK != Session->findSymbolByVA(Address, SymTagNull, &Symbol))
146 return nullptr;
147 if (S_OK != Session->findSymbolByVA(Address, EnumVal, &Symbol)) {
148 ULONGLONG LoadAddr = 0;
149 if (S_OK != Session->get_loadAddress(&LoadAddr))
150 return nullptr;
151 DWORD RVA = static_cast(Address - LoadAddr);
152 if (S_OK != Session->findSymbolByRVA(RVA, EnumVal, &Symbol))
153 return nullptr;
154 }
147155 auto RawSymbol = llvm::make_unique(*this, Symbol);
148156 return PDBSymbol::create(*this, std::move(RawSymbol));
149157 }
0 // Compile with "cl /c /Zi /GR- LoadAddressTest.cpp"
1 // Link with "link LoadAddressTest.obj /debug /nodefaultlib /entry:main"
2
3 int main(int argc, char **argv) {
4 return 0;
5 }
0 ; RUN: llvm-pdbdump -externals %p/Inputs/LoadAddressTest.pdb \
1 ; RUN: | FileCheck --check-prefix=RVA %s
2 ; RUN: llvm-pdbdump -externals -load-address=0x40000000 \
3 ; RUN: %p/Inputs/LoadAddressTest.pdb | FileCheck --check-prefix=VA %s
4
5 ; RVA: ---EXTERNALS---
6 ; RVA: [0x00001010] _main
7
8 ; VA: ---EXTERNALS---
9 ; VA: [0x40001010] _main
88 ClassDefinitionDumper.cpp
99 CompilandDumper.cpp
1010 EnumDumper.cpp
11 ExternalSymbolDumper.cpp
1112 FunctionDumper.cpp
1213 LinePrinter.cpp
1314 TypeDumper.cpp
6868 case PDB_LocType::Static:
6969 Printer << "data: ";
7070 WithColor(Printer, PDB_ColorItem::Address).get()
71 << "[" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "]";
71 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
7272 break;
7373 case PDB_LocType::Constant:
7474 Printer << "constant: ";
101101 Printer.NewLine();
102102 Printer << "label ";
103103 WithColor(Printer, PDB_ColorItem::Address).get()
104 << "[" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "] ";
104 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
105105 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
106106 }
107107
112112 Printer.NewLine();
113113 Printer << "thunk ";
114114 PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
115 uint32_t RVA = Symbol.getRelativeVirtualAddress();
115 uint64_t VA = Symbol.getVirtualAddress();
116116 if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) {
117 uint32_t Target = Symbol.getTargetRelativeVirtualAddress();
118 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(RVA, 10);
117 uint64_t Target = Symbol.getTargetVirtualAddress();
118 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
119119 Printer << " -> ";
120120 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
121121 } else {
122122 WithColor(Printer, PDB_ColorItem::Address).get()
123 << "[" << format_hex(RVA, 10) << " - "
124 << format_hex(RVA + Symbol.getLength(), 10) << "]";
123 << "[" << format_hex(VA, 10) << " - "
124 << format_hex(VA + Symbol.getLength(), 10) << "]";
125125 }
126126 Printer << " (";
127127 WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
0 //===- ExternalSymbolDumper.cpp -------------------------------- *- 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 "ExternalSymbolDumper.h"
10 #include "LinePrinter.h"
11
12 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
13 #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
14 #include "llvm/Support/Format.h"
15
16 using namespace llvm;
17
18 ExternalSymbolDumper::ExternalSymbolDumper(LinePrinter &P)
19 : PDBSymDumper(true), Printer(P) {}
20
21 void ExternalSymbolDumper::start(const PDBSymbolExe &Symbol) {
22 auto Vars = Symbol.findAllChildren();
23 while (auto Var = Vars->getNext())
24 Var->dump(*this);
25 }
26
27 void ExternalSymbolDumper::dump(const PDBSymbolPublicSymbol &Symbol) {
28 std::string LinkageName = Symbol.getName();
29 if (Printer.IsSymbolExcluded(LinkageName))
30 return;
31
32 Printer.NewLine();
33 uint64_t Addr = Symbol.getVirtualAddress();
34
35 Printer << "[";
36 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Addr, 10);
37 Printer << "] ";
38 WithColor(Printer, PDB_ColorItem::Identifier).get() << LinkageName;
39 }
0 //===- ExternalSymbolDumper.h --------------------------------- *- 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_TOOLS_LLVMPDBDUMP_EXTERNALSYMBOLDUMPER_H
10 #define LLVM_TOOLS_LLVMPDBDUMP_EXTERNALSYMBOLDUMPER_H
11
12 #include "llvm/DebugInfo/PDB/PDBSymDumper.h"
13
14 namespace llvm {
15
16 class LinePrinter;
17
18 class ExternalSymbolDumper : public PDBSymDumper {
19 public:
20 ExternalSymbolDumper(LinePrinter &P);
21
22 void start(const PDBSymbolExe &Symbol);
23
24 void dump(const PDBSymbolPublicSymbol &Symbol) override;
25
26 private:
27 LinePrinter &Printer;
28 };
29 }
30
31 #endif
108108 }
109109
110110 void FunctionDumper::start(const PDBSymbolFunc &Symbol, PointerType Pointer) {
111 uint32_t FuncStart = Symbol.getRelativeVirtualAddress();
112 uint32_t FuncEnd = FuncStart + Symbol.getLength();
111 uint64_t FuncStart = Symbol.getVirtualAddress();
112 uint64_t FuncEnd = FuncStart + Symbol.getLength();
113113
114114 Printer << "func [";
115115 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(FuncStart, 10);
116116 if (auto DebugStart = Symbol.findOneChild()) {
117 uint32_t Prologue = DebugStart->getRelativeVirtualAddress() - FuncStart;
117 uint64_t Prologue = DebugStart->getVirtualAddress() - FuncStart;
118118 WithColor(Printer, PDB_ColorItem::Offset).get() << "+" << Prologue;
119119 }
120120 Printer << " - ";
121121 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(FuncEnd, 10);
122122 if (auto DebugEnd = Symbol.findOneChild()) {
123 uint32_t Epilogue = FuncEnd - DebugEnd->getRelativeVirtualAddress();
123 uint64_t Epilogue = FuncEnd - DebugEnd->getVirtualAddress();
124124 WithColor(Printer, PDB_ColorItem::Offset).get() << "-" << Epilogue;
125125 }
126126 Printer << "] (";
4343 Printer.NewLine();
4444 Printer << "data [";
4545 WithColor(Printer, PDB_ColorItem::Address).get()
46 << format_hex(Var.getRelativeVirtualAddress(), 10);
46 << format_hex(Var.getVirtualAddress(), 10);
4747 Printer << "] ";
4848 WithColor(Printer, PDB_ColorItem::Keyword).get() << "static ";
4949 dumpSymbolTypeAndName(*VarType, Var.getName());
1414
1515 #include "llvm-pdbdump.h"
1616 #include "CompilandDumper.h"
17 #include "ExternalSymbolDumper.h"
1718 #include "FunctionDumper.h"
1819 #include "LinePrinter.h"
1920 #include "TypeDumper.h"
5758
5859 cl::OptionCategory TypeCategory("Symbol Type Options");
5960 cl::OptionCategory FilterCategory("Filtering Options");
61 cl::OptionCategory OtherOptions("Other Options");
6062
6163 cl::opt Compilands("compilands", cl::desc("Display compilands"),
6264 cl::cat(TypeCategory));
6466 cl::cat(TypeCategory));
6567 cl::opt Globals("globals", cl::desc("Dump global symbols"),
6668 cl::cat(TypeCategory));
69 cl::opt Externals("externals", cl::desc("Dump external symbols"),
70 cl::cat(TypeCategory));
6771 cl::opt Types("types", cl::desc("Display types"), cl::cat(TypeCategory));
6872 cl::opt
6973 All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
7074 cl::cat(TypeCategory));
75
76 cl::opt LoadAddress(
77 "load-address",
78 cl::desc("Assume the module is loaded at the specified address"),
79 cl::cat(OtherOptions));
7180
7281 cl::list
7382 ExcludeTypes("exclude-types",
120129 << "'. An unknown error occured.\n";
121130 return;
122131 }
132 if (opts::LoadAddress)
133 Session->setLoadAddress(opts::LoadAddress);
123134
124135 LinePrinter Printer(2, outs());
125136
214225 }
215226 Printer.Unindent();
216227 }
228 if (opts::Externals) {
229 Printer.NewLine();
230 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---EXTERNALS---";
231 Printer.Indent();
232 ExternalSymbolDumper Dumper(Printer);
233 Dumper.start(*GlobalScope);
234 }
217235 outs().flush();
218236 }
219237
239257 opts::Symbols = true;
240258 opts::Globals = true;
241259 opts::Types = true;
260 opts::Externals = true;
242261 }
243262 if (opts::ExcludeCompilerGenerated) {
244263 opts::ExcludeTypes.push_back("__vc_attributes");