blob: b19b09873be1029c500d94db64f6241e582590e9 [file] [log] [blame]
Zachary Turnerbd336e42017-06-09 20:46:17 +00001//===- PrettyCompilandDumper.cpp - llvm-pdbutil 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 Turnerbd336e42017-06-09 20:46:17 +000014#include "llvm-pdbutil.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000015
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();
Aaron Smitha27b5e92018-03-07 02:23:08 +000058 if (auto Files = Session.getSourceFilesForCompiland(Symbol)) {
Zachary Turnera99000d2016-03-08 21:42:24 +000059 Printer.Indent();
Aaron Smitha27b5e92018-03-07 02:23:08 +000060 while (auto File = Files->getNext()) {
Zachary Turnera99000d2016-03-08 21:42:24 +000061 Printer.NewLine();
Aaron Smitha27b5e92018-03-07 02:23:08 +000062 WithColor(Printer, PDB_ColorItem::Path).get() << File->getFileName();
Zachary Turnera99000d2016-03-08 21:42:24 +000063
Aaron Smitha27b5e92018-03-07 02:23:08 +000064 auto Lines = Session.findLineNumbers(Symbol, *File);
65 if (!Lines)
66 continue;
Zachary Turnera99000d2016-03-08 21:42:24 +000067
Aaron Smitha27b5e92018-03-07 02:23:08 +000068 Printer.Indent();
69 while (auto Line = Lines->getNext()) {
70 Printer.NewLine();
71 uint32_t LineStart = Line->getLineNumber();
72 uint32_t LineEnd = Line->getLineNumberEnd();
Adrian McCarthyd5ca7202016-08-17 23:01:03 +000073
Aaron Smitha27b5e92018-03-07 02:23:08 +000074 Printer << "Line ";
75 PDB_ColorItem StatementColor = Line->isStatement()
76 ? PDB_ColorItem::Keyword
77 : PDB_ColorItem::LiteralValue;
78 WithColor(Printer, StatementColor).get() << LineStart;
79 if (LineStart != LineEnd)
80 WithColor(Printer, StatementColor).get() << " - " << LineEnd;
81
82 uint32_t ColumnStart = Line->getColumnNumber();
83 uint32_t ColumnEnd = Line->getColumnNumberEnd();
84 if (ColumnStart != 0 || ColumnEnd != 0) {
85 Printer << ", Column: ";
86 WithColor(Printer, StatementColor).get() << ColumnStart;
87 if (ColumnEnd != ColumnStart)
88 WithColor(Printer, StatementColor).get() << " - " << ColumnEnd;
89 }
90
91 Printer << ", Address: ";
92 if (Line->getLength() > 0) {
93 uint64_t AddrStart = Line->getVirtualAddress();
94 uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
95 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnera99000d2016-03-08 21:42:24 +000096 << "[" << format_hex(AddrStart, 10) << " - "
97 << format_hex(AddrEnd, 10) << "]";
Aaron Smitha27b5e92018-03-07 02:23:08 +000098 Printer << " (" << Line->getLength() << " bytes)";
99 } else {
100 uint64_t AddrStart = Line->getVirtualAddress();
101 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnera99000d2016-03-08 21:42:24 +0000102 << "[" << format_hex(AddrStart, 10) << "] ";
Aaron Smitha27b5e92018-03-07 02:23:08 +0000103 Printer << "(0 bytes)";
104 }
Zachary Turnera99000d2016-03-08 21:42:24 +0000105 }
Aaron Smitha27b5e92018-03-07 02:23:08 +0000106 Printer.Unindent();
Zachary Turnera99000d2016-03-08 21:42:24 +0000107 }
108 Printer.Unindent();
109 }
Zachary Turnera99000d2016-03-08 21:42:24 +0000110 }
111
112 if (opts & Flags::Children) {
Aaron Smitha27b5e92018-03-07 02:23:08 +0000113 if (auto ChildrenEnum = Symbol.findAllChildren()) {
114 Printer.Indent();
115 while (auto Child = ChildrenEnum->getNext())
116 Child->dump(*this);
117 Printer.Unindent();
118 }
Zachary Turnera99000d2016-03-08 21:42:24 +0000119 }
Zachary Turner9a818ad2015-02-22 22:03:38 +0000120}
121
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000122void CompilandDumper::dump(const PDBSymbolData &Symbol) {
Zachary Turner0683be22017-05-14 01:13:40 +0000123 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Data))
124 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +0000125 if (Printer.IsSymbolExcluded(Symbol.getName()))
126 return;
127
Zachary Turner2d11c202015-02-27 09:15:59 +0000128 Printer.NewLine();
129
Zachary Turner9a818ad2015-02-22 22:03:38 +0000130 switch (auto LocType = Symbol.getLocationType()) {
131 case PDB_LocType::Static:
Zachary Turner2d11c202015-02-27 09:15:59 +0000132 Printer << "data: ";
133 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000134 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
Zachary Turner0683be22017-05-14 01:13:40 +0000135
136 WithColor(Printer, PDB_ColorItem::Comment).get()
137 << " [sizeof = " << getTypeLength(Symbol) << "]";
138
Zachary Turner9a818ad2015-02-22 22:03:38 +0000139 break;
140 case PDB_LocType::Constant:
Zachary Turner2d11c202015-02-27 09:15:59 +0000141 Printer << "constant: ";
142 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
143 << "[" << Symbol.getValue() << "]";
Zachary Turner0683be22017-05-14 01:13:40 +0000144 WithColor(Printer, PDB_ColorItem::Comment).get()
145 << " [sizeof = " << getTypeLength(Symbol) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000146 break;
147 default:
Zachary Turner2d11c202015-02-27 09:15:59 +0000148 Printer << "data(unexpected type=" << LocType << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000149 }
150
Zachary Turner2d11c202015-02-27 09:15:59 +0000151 Printer << " ";
152 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000153}
154
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000155void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
Zachary Turner0683be22017-05-14 01:13:40 +0000156 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Functions))
157 return;
Zachary Turner29c69102015-02-23 05:58:34 +0000158 if (Symbol.getLength() == 0)
159 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +0000160 if (Printer.IsSymbolExcluded(Symbol.getName()))
161 return;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000162
Zachary Turner2d11c202015-02-27 09:15:59 +0000163 Printer.NewLine();
164 FunctionDumper Dumper(Printer);
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000165 Dumper.start(Symbol, FunctionDumper::PointerType::None);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000166}
167
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000168void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000169 if (Printer.IsSymbolExcluded(Symbol.getName()))
170 return;
171
Zachary Turner2d11c202015-02-27 09:15:59 +0000172 Printer.NewLine();
173 Printer << "label ";
174 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000175 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
Zachary Turner2d11c202015-02-27 09:15:59 +0000176 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000177}
178
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000179void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
Zachary Turner0683be22017-05-14 01:13:40 +0000180 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Thunks))
181 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +0000182 if (Printer.IsSymbolExcluded(Symbol.getName()))
183 return;
184
Zachary Turner2d11c202015-02-27 09:15:59 +0000185 Printer.NewLine();
186 Printer << "thunk ";
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000187 codeview::ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
Zachary Turnere5cb2692015-05-01 20:24:26 +0000188 uint64_t VA = Symbol.getVirtualAddress();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000189 if (Ordinal == codeview::ThunkOrdinal::TrampIncremental) {
Zachary Turnere5cb2692015-05-01 20:24:26 +0000190 uint64_t Target = Symbol.getTargetVirtualAddress();
191 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
Zachary Turner2d11c202015-02-27 09:15:59 +0000192 Printer << " -> ";
193 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000194 } else {
Zachary Turner2d11c202015-02-27 09:15:59 +0000195 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000196 << "[" << format_hex(VA, 10) << " - "
197 << format_hex(VA + Symbol.getLength(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000198 }
Zachary Turner7797c722015-03-02 04:39:56 +0000199 Printer << " (";
200 WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
201 Printer << ") ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000202 std::string Name = Symbol.getName();
203 if (!Name.empty())
Zachary Turner2d11c202015-02-27 09:15:59 +0000204 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000205}
206
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000207void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +0000208
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000209void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000210 Printer.NewLine();
211 Printer << "unknown (" << Symbol.getSymTag() << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000212}