1 //===- PrettyCompilandDumper.cpp - llvm-pdbutil compiland 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 "PrettyCompilandDumper.h"
12 #include "LinePrinter.h"
13 #include "PrettyFunctionDumper.h"
14 #include "llvm-pdbutil.h"
16 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
17 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
18 #include "llvm/DebugInfo/PDB/IPDBSession.h"
19 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
20 #include "llvm/DebugInfo/PDB/PDBExtras.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
26 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
27 #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
28 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
29 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
30 #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
31 #include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h"
32 #include "llvm/Support/Format.h"
33 #include "llvm/Support/Path.h"
34 #include "llvm/Support/raw_ostream.h"
39 using namespace llvm::pdb;
41 CompilandDumper::CompilandDumper(LinePrinter &P)
42 : PDBSymDumper(true), Printer(P) {}
44 void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol) {}
46 void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol) {}
48 void CompilandDumper::start(const PDBSymbolCompiland &Symbol,
49 CompilandDumpFlags opts) {
50 std::string FullName = Symbol.getName();
51 if (Printer.IsCompilandExcluded(FullName))
55 WithColor(Printer, PDB_ColorItem::Path).get() << FullName;
57 if (opts & Flags::Lines) {
58 const IPDBSession &Session = Symbol.getSession();
59 if (auto Files = Session.getSourceFilesForCompiland(Symbol)) {
61 while (auto File = Files->getNext()) {
63 WithColor(Printer, PDB_ColorItem::Path).get() << File->getFileName();
64 if (File->getChecksumType() != PDB_Checksum::None) {
65 auto ChecksumType = File->getChecksumType();
66 auto ChecksumHexString = toHex(File->getChecksum());
67 WithColor(Printer, PDB_ColorItem::Comment).get()
68 << " (" << ChecksumType << ": " << ChecksumHexString << ")";
71 auto Lines = Session.findLineNumbers(Symbol, *File);
76 while (auto Line = Lines->getNext()) {
78 uint32_t LineStart = Line->getLineNumber();
79 uint32_t LineEnd = Line->getLineNumberEnd();
82 PDB_ColorItem StatementColor = Line->isStatement()
83 ? PDB_ColorItem::Keyword
84 : PDB_ColorItem::LiteralValue;
85 WithColor(Printer, StatementColor).get() << LineStart;
86 if (LineStart != LineEnd)
87 WithColor(Printer, StatementColor).get() << " - " << LineEnd;
89 uint32_t ColumnStart = Line->getColumnNumber();
90 uint32_t ColumnEnd = Line->getColumnNumberEnd();
91 if (ColumnStart != 0 || ColumnEnd != 0) {
92 Printer << ", Column: ";
93 WithColor(Printer, StatementColor).get() << ColumnStart;
94 if (ColumnEnd != ColumnStart)
95 WithColor(Printer, StatementColor).get() << " - " << ColumnEnd;
98 Printer << ", Address: ";
99 if (Line->getLength() > 0) {
100 uint64_t AddrStart = Line->getVirtualAddress();
101 uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
102 WithColor(Printer, PDB_ColorItem::Address).get()
103 << "[" << format_hex(AddrStart, 10) << " - "
104 << format_hex(AddrEnd, 10) << "]";
105 Printer << " (" << Line->getLength() << " bytes)";
107 uint64_t AddrStart = Line->getVirtualAddress();
108 WithColor(Printer, PDB_ColorItem::Address).get()
109 << "[" << format_hex(AddrStart, 10) << "] ";
110 Printer << "(0 bytes)";
119 if (opts & Flags::Children) {
120 if (auto ChildrenEnum = Symbol.findAllChildren()) {
122 while (auto Child = ChildrenEnum->getNext())
129 void CompilandDumper::dump(const PDBSymbolData &Symbol) {
130 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Data))
132 if (Printer.IsSymbolExcluded(Symbol.getName()))
137 switch (auto LocType = Symbol.getLocationType()) {
138 case PDB_LocType::Static:
140 WithColor(Printer, PDB_ColorItem::Address).get()
141 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
143 WithColor(Printer, PDB_ColorItem::Comment).get()
144 << " [sizeof = " << getTypeLength(Symbol) << "]";
147 case PDB_LocType::Constant:
148 Printer << "constant: ";
149 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
150 << "[" << Symbol.getValue() << "]";
151 WithColor(Printer, PDB_ColorItem::Comment).get()
152 << " [sizeof = " << getTypeLength(Symbol) << "]";
155 Printer << "data(unexpected type=" << LocType << ")";
159 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
162 void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
163 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Functions))
165 if (Symbol.getLength() == 0)
167 if (Printer.IsSymbolExcluded(Symbol.getName()))
171 FunctionDumper Dumper(Printer);
172 Dumper.start(Symbol, FunctionDumper::PointerType::None);
175 void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
176 if (Printer.IsSymbolExcluded(Symbol.getName()))
181 WithColor(Printer, PDB_ColorItem::Address).get()
182 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
183 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
186 void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
187 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Thunks))
189 if (Printer.IsSymbolExcluded(Symbol.getName()))
194 codeview::ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
195 uint64_t VA = Symbol.getVirtualAddress();
196 if (Ordinal == codeview::ThunkOrdinal::TrampIncremental) {
197 uint64_t Target = Symbol.getTargetVirtualAddress();
198 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
200 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
202 WithColor(Printer, PDB_ColorItem::Address).get()
203 << "[" << format_hex(VA, 10) << " - "
204 << format_hex(VA + Symbol.getLength(), 10) << "]";
207 WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
209 std::string Name = Symbol.getName();
211 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
214 void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
216 void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
218 Printer << "unknown (" << Symbol.getSymTag() << ")";
221 void CompilandDumper::dump(const PDBSymbolUsingNamespace &Symbol) {
222 if (Printer.IsSymbolExcluded(Symbol.getName()))
226 Printer << "using namespace ";
227 std::string Name = Symbol.getName();
228 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;