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/Support/Format.h"
32 #include "llvm/Support/Path.h"
33 #include "llvm/Support/raw_ostream.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 (!shouldDumpSymLevel(opts::pretty::SymLevel::Data))
120 if (Printer.IsSymbolExcluded(Symbol.getName()))
125 switch (auto LocType = Symbol.getLocationType()) {
126 case PDB_LocType::Static:
128 WithColor(Printer, PDB_ColorItem::Address).get()
129 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
131 WithColor(Printer, PDB_ColorItem::Comment).get()
132 << " [sizeof = " << getTypeLength(Symbol) << "]";
135 case PDB_LocType::Constant:
136 Printer << "constant: ";
137 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
138 << "[" << Symbol.getValue() << "]";
139 WithColor(Printer, PDB_ColorItem::Comment).get()
140 << " [sizeof = " << getTypeLength(Symbol) << "]";
143 Printer << "data(unexpected type=" << LocType << ")";
147 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
150 void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
151 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Functions))
153 if (Symbol.getLength() == 0)
155 if (Printer.IsSymbolExcluded(Symbol.getName()))
159 FunctionDumper Dumper(Printer);
160 Dumper.start(Symbol, FunctionDumper::PointerType::None);
163 void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
164 if (Printer.IsSymbolExcluded(Symbol.getName()))
169 WithColor(Printer, PDB_ColorItem::Address).get()
170 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
171 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
174 void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
175 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Thunks))
177 if (Printer.IsSymbolExcluded(Symbol.getName()))
182 codeview::ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
183 uint64_t VA = Symbol.getVirtualAddress();
184 if (Ordinal == codeview::ThunkOrdinal::TrampIncremental) {
185 uint64_t Target = Symbol.getTargetVirtualAddress();
186 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
188 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
190 WithColor(Printer, PDB_ColorItem::Address).get()
191 << "[" << format_hex(VA, 10) << " - "
192 << format_hex(VA + Symbol.getLength(), 10) << "]";
195 WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
197 std::string Name = Symbol.getName();
199 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
202 void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
204 void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
206 Printer << "unknown (" << Symbol.getSymTag() << ")";