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 "LinePrinter.h"
12 #include "llvm-pdbdump.h"
14 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
15 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
16 #include "llvm/DebugInfo/PDB/IPDBSession.h"
17 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
18 #include "llvm/DebugInfo/PDB/PDBExtras.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
26 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
27 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
28 #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
29 #include "llvm/Support/Format.h"
30 #include "llvm/Support/Path.h"
31 #include "llvm/Support/raw_ostream.h"
33 #include "FunctionDumper.h"
38 using namespace llvm::pdb;
40 CompilandDumper::CompilandDumper(LinePrinter &P)
41 : PDBSymDumper(true), Printer(P) {}
43 void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol) {}
45 void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol) {}
47 void CompilandDumper::start(const PDBSymbolCompiland &Symbol,
48 CompilandDumpFlags opts) {
49 std::string FullName = Symbol.getName();
50 if (Printer.IsCompilandExcluded(FullName))
54 WithColor(Printer, PDB_ColorItem::Path).get() << FullName;
56 if (opts & Flags::Lines) {
57 const IPDBSession &Session = Symbol.getSession();
58 auto Files = Session.getSourceFilesForCompiland(Symbol);
60 while (auto File = Files->getNext()) {
62 WithColor(Printer, PDB_ColorItem::Path).get() << File->getFileName();
64 auto Lines = Session.findLineNumbers(Symbol, *File);
66 while (auto Line = Lines->getNext()) {
68 uint32_t LineStart = Line->getLineNumber();
69 uint32_t LineEnd = Line->getLineNumberEnd();
72 PDB_ColorItem StatementColor = Line->isStatement()
73 ? PDB_ColorItem::Keyword
74 : PDB_ColorItem::LiteralValue;
75 WithColor(Printer, StatementColor).get() << LineStart;
76 if (LineStart != LineEnd)
77 WithColor(Printer, StatementColor).get() << " - " << LineEnd;
79 uint32_t ColumnStart = Line->getColumnNumber();
80 uint32_t ColumnEnd = Line->getColumnNumberEnd();
81 if (ColumnStart != 0 || ColumnEnd != 0) {
82 Printer << ", Column: ";
83 WithColor(Printer, StatementColor).get() << ColumnStart;
84 if (ColumnEnd != ColumnStart)
85 WithColor(Printer, StatementColor).get() << " - " << ColumnEnd;
88 Printer << ", Address: ";
89 if (Line->getLength() > 0) {
90 uint64_t AddrStart = Line->getVirtualAddress();
91 uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
92 WithColor(Printer, PDB_ColorItem::Address).get()
93 << "[" << format_hex(AddrStart, 10) << " - "
94 << format_hex(AddrEnd, 10) << "]";
95 Printer << " (" << Line->getLength() << " bytes)";
97 uint64_t AddrStart = Line->getVirtualAddress();
98 WithColor(Printer, PDB_ColorItem::Address).get()
99 << "[" << format_hex(AddrStart, 10) << "] ";
100 Printer << "(0 bytes)";
108 if (opts & Flags::Children) {
109 auto ChildrenEnum = Symbol.findAllChildren();
111 while (auto Child = ChildrenEnum->getNext())
117 void CompilandDumper::dump(const PDBSymbolData &Symbol) {
118 if (Printer.IsSymbolExcluded(Symbol.getName()))
123 switch (auto LocType = Symbol.getLocationType()) {
124 case PDB_LocType::Static:
126 WithColor(Printer, PDB_ColorItem::Address).get()
127 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
129 case PDB_LocType::Constant:
130 Printer << "constant: ";
131 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
132 << "[" << Symbol.getValue() << "]";
135 Printer << "data(unexpected type=" << LocType << ")";
139 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
142 void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
143 if (Symbol.getLength() == 0)
145 if (Printer.IsSymbolExcluded(Symbol.getName()))
149 FunctionDumper Dumper(Printer);
150 Dumper.start(Symbol, FunctionDumper::PointerType::None);
153 void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
154 if (Printer.IsSymbolExcluded(Symbol.getName()))
159 WithColor(Printer, PDB_ColorItem::Address).get()
160 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
161 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
164 void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
165 if (Printer.IsSymbolExcluded(Symbol.getName()))
170 codeview::ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
171 uint64_t VA = Symbol.getVirtualAddress();
172 if (Ordinal == codeview::ThunkOrdinal::TrampIncremental) {
173 uint64_t Target = Symbol.getTargetVirtualAddress();
174 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
176 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
178 WithColor(Printer, PDB_ColorItem::Address).get()
179 << "[" << format_hex(VA, 10) << " - "
180 << format_hex(VA + Symbol.getLength(), 10) << "]";
183 WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
185 std::string Name = Symbol.getName();
187 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
190 void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
192 void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
194 Printer << "unknown (" << Symbol.getSymTag() << ")";