blob: 9cf7bf82a164331489995addbe51288cce2a9da1 [file] [log] [blame]
Zachary Turnera9054dd2017-01-11 00:35:43 +00001//===- PrettyCompilandDumper.cpp - llvm-pdbdump compiland dumper -*- C++ *-===//
Zachary Turner9a818ad2015-02-22 22:03:38 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Zachary Turnera9054dd2017-01-11 00:35:43 +000010#include "PrettyCompilandDumper.h"
11
Zachary Turner2d11c202015-02-27 09:15:59 +000012#include "LinePrinter.h"
Zachary Turnera9054dd2017-01-11 00:35:43 +000013#include "PrettyFunctionDumper.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000014#include "llvm-pdbdump.h"
15
16#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
Zachary Turnera99000d2016-03-08 21:42:24 +000017#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000018#include "llvm/DebugInfo/PDB/IPDBSession.h"
Zachary Turnera99000d2016-03-08 21:42:24 +000019#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000020#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"
34
Zachary Turner9a818ad2015-02-22 22:03:38 +000035#include <utility>
Zachary Turner9a818ad2015-02-22 22:03:38 +000036
37using namespace llvm;
Zachary Turnerec28fc32016-05-04 20:32:13 +000038using namespace llvm::pdb;
Zachary Turner9a818ad2015-02-22 22:03:38 +000039
Zachary Turner2d11c202015-02-27 09:15:59 +000040CompilandDumper::CompilandDumper(LinePrinter &P)
Zachary Turner94118282015-02-27 09:53:55 +000041 : PDBSymDumper(true), Printer(P) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +000042
Zachary Turnerb52d08d2015-03-01 06:51:29 +000043void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +000044
Zachary Turnerb52d08d2015-03-01 06:51:29 +000045void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +000046
Zachary Turnera99000d2016-03-08 21:42:24 +000047void CompilandDumper::start(const PDBSymbolCompiland &Symbol,
48 CompilandDumpFlags opts) {
Zachary Turner9a818ad2015-02-22 22:03:38 +000049 std::string FullName = Symbol.getName();
Zachary Turnerf5abda22015-03-01 06:49:49 +000050 if (Printer.IsCompilandExcluded(FullName))
51 return;
52
Zachary Turner2d11c202015-02-27 09:15:59 +000053 Printer.NewLine();
54 WithColor(Printer, PDB_ColorItem::Path).get() << FullName;
Zachary Turner9a818ad2015-02-22 22:03:38 +000055
Zachary Turnera99000d2016-03-08 21:42:24 +000056 if (opts & Flags::Lines) {
57 const IPDBSession &Session = Symbol.getSession();
58 auto Files = Session.getSourceFilesForCompiland(Symbol);
59 Printer.Indent();
60 while (auto File = Files->getNext()) {
61 Printer.NewLine();
62 WithColor(Printer, PDB_ColorItem::Path).get() << File->getFileName();
63
64 auto Lines = Session.findLineNumbers(Symbol, *File);
65 Printer.Indent();
66 while (auto Line = Lines->getNext()) {
67 Printer.NewLine();
68 uint32_t LineStart = Line->getLineNumber();
69 uint32_t LineEnd = Line->getLineNumberEnd();
70
71 Printer << "Line ";
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;
78
Adrian McCarthyd5ca7202016-08-17 23:01:03 +000079 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;
86 }
87
Zachary Turnera99000d2016-03-08 21:42:24 +000088 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)";
96 } else {
97 uint64_t AddrStart = Line->getVirtualAddress();
98 WithColor(Printer, PDB_ColorItem::Address).get()
99 << "[" << format_hex(AddrStart, 10) << "] ";
100 Printer << "(0 bytes)";
101 }
102 }
103 Printer.Unindent();
104 }
105 Printer.Unindent();
106 }
107
108 if (opts & Flags::Children) {
109 auto ChildrenEnum = Symbol.findAllChildren();
110 Printer.Indent();
111 while (auto Child = ChildrenEnum->getNext())
112 Child->dump(*this);
113 Printer.Unindent();
114 }
Zachary Turner9a818ad2015-02-22 22:03:38 +0000115}
116
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000117void CompilandDumper::dump(const PDBSymbolData &Symbol) {
Zachary Turner0683be22017-05-14 01:13:40 +0000118 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Data))
119 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +0000120 if (Printer.IsSymbolExcluded(Symbol.getName()))
121 return;
122
Zachary Turner2d11c202015-02-27 09:15:59 +0000123 Printer.NewLine();
124
Zachary Turner9a818ad2015-02-22 22:03:38 +0000125 switch (auto LocType = Symbol.getLocationType()) {
126 case PDB_LocType::Static:
Zachary Turner2d11c202015-02-27 09:15:59 +0000127 Printer << "data: ";
128 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000129 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
Zachary Turner0683be22017-05-14 01:13:40 +0000130
131 WithColor(Printer, PDB_ColorItem::Comment).get()
132 << " [sizeof = " << getTypeLength(Symbol) << "]";
133
Zachary Turner9a818ad2015-02-22 22:03:38 +0000134 break;
135 case PDB_LocType::Constant:
Zachary Turner2d11c202015-02-27 09:15:59 +0000136 Printer << "constant: ";
137 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
138 << "[" << Symbol.getValue() << "]";
Zachary Turner0683be22017-05-14 01:13:40 +0000139 WithColor(Printer, PDB_ColorItem::Comment).get()
140 << " [sizeof = " << getTypeLength(Symbol) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000141 break;
142 default:
Zachary Turner2d11c202015-02-27 09:15:59 +0000143 Printer << "data(unexpected type=" << LocType << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000144 }
145
Zachary Turner2d11c202015-02-27 09:15:59 +0000146 Printer << " ";
147 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000148}
149
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000150void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
Zachary Turner0683be22017-05-14 01:13:40 +0000151 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Functions))
152 return;
Zachary Turner29c69102015-02-23 05:58:34 +0000153 if (Symbol.getLength() == 0)
154 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +0000155 if (Printer.IsSymbolExcluded(Symbol.getName()))
156 return;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000157
Zachary Turner2d11c202015-02-27 09:15:59 +0000158 Printer.NewLine();
159 FunctionDumper Dumper(Printer);
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000160 Dumper.start(Symbol, FunctionDumper::PointerType::None);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000161}
162
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000163void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000164 if (Printer.IsSymbolExcluded(Symbol.getName()))
165 return;
166
Zachary Turner2d11c202015-02-27 09:15:59 +0000167 Printer.NewLine();
168 Printer << "label ";
169 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000170 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
Zachary Turner2d11c202015-02-27 09:15:59 +0000171 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000172}
173
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000174void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
Zachary Turner0683be22017-05-14 01:13:40 +0000175 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Thunks))
176 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +0000177 if (Printer.IsSymbolExcluded(Symbol.getName()))
178 return;
179
Zachary Turner2d11c202015-02-27 09:15:59 +0000180 Printer.NewLine();
181 Printer << "thunk ";
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000182 codeview::ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
Zachary Turnere5cb2692015-05-01 20:24:26 +0000183 uint64_t VA = Symbol.getVirtualAddress();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000184 if (Ordinal == codeview::ThunkOrdinal::TrampIncremental) {
Zachary Turnere5cb2692015-05-01 20:24:26 +0000185 uint64_t Target = Symbol.getTargetVirtualAddress();
186 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
Zachary Turner2d11c202015-02-27 09:15:59 +0000187 Printer << " -> ";
188 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000189 } else {
Zachary Turner2d11c202015-02-27 09:15:59 +0000190 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000191 << "[" << format_hex(VA, 10) << " - "
192 << format_hex(VA + Symbol.getLength(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000193 }
Zachary Turner7797c722015-03-02 04:39:56 +0000194 Printer << " (";
195 WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
196 Printer << ") ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000197 std::string Name = Symbol.getName();
198 if (!Name.empty())
Zachary Turner2d11c202015-02-27 09:15:59 +0000199 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000200}
201
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000202void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +0000203
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000204void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000205 Printer.NewLine();
206 Printer << "unknown (" << Symbol.getSymTag() << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000207}