blob: 05141818660e56002c83f00c67ff3492abe78e01 [file] [log] [blame]
Zachary Turner9a818ad2015-02-22 22:03:38 +00001//===- CompilandDumper.cpp - llvm-pdbdump compiland symbol dumper *- C++ *-===//
2//
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
10#include "CompilandDumper.h"
Zachary Turner2d11c202015-02-27 09:15:59 +000011#include "LinePrinter.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000012#include "llvm-pdbdump.h"
13
14#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
Zachary Turnera99000d2016-03-08 21:42:24 +000015#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000016#include "llvm/DebugInfo/PDB/IPDBSession.h"
Zachary Turnera99000d2016-03-08 21:42:24 +000017#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000018#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"
32
33#include "FunctionDumper.h"
34
35#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 Turnerf5abda22015-03-01 06:49:49 +0000118 if (Printer.IsSymbolExcluded(Symbol.getName()))
119 return;
120
Zachary Turner2d11c202015-02-27 09:15:59 +0000121 Printer.NewLine();
122
Zachary Turner9a818ad2015-02-22 22:03:38 +0000123 switch (auto LocType = Symbol.getLocationType()) {
124 case PDB_LocType::Static:
Zachary Turner2d11c202015-02-27 09:15:59 +0000125 Printer << "data: ";
126 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000127 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000128 break;
129 case PDB_LocType::Constant:
Zachary Turner2d11c202015-02-27 09:15:59 +0000130 Printer << "constant: ";
131 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
132 << "[" << Symbol.getValue() << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000133 break;
134 default:
Zachary Turner2d11c202015-02-27 09:15:59 +0000135 Printer << "data(unexpected type=" << LocType << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000136 }
137
Zachary Turner2d11c202015-02-27 09:15:59 +0000138 Printer << " ";
139 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000140}
141
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000142void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
Zachary Turner29c69102015-02-23 05:58:34 +0000143 if (Symbol.getLength() == 0)
144 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +0000145 if (Printer.IsSymbolExcluded(Symbol.getName()))
146 return;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000147
Zachary Turner2d11c202015-02-27 09:15:59 +0000148 Printer.NewLine();
149 FunctionDumper Dumper(Printer);
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000150 Dumper.start(Symbol, FunctionDumper::PointerType::None);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000151}
152
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000153void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000154 if (Printer.IsSymbolExcluded(Symbol.getName()))
155 return;
156
Zachary Turner2d11c202015-02-27 09:15:59 +0000157 Printer.NewLine();
158 Printer << "label ";
159 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000160 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
Zachary Turner2d11c202015-02-27 09:15:59 +0000161 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000162}
163
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000164void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000165 if (Printer.IsSymbolExcluded(Symbol.getName()))
166 return;
167
Zachary Turner2d11c202015-02-27 09:15:59 +0000168 Printer.NewLine();
169 Printer << "thunk ";
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000170 codeview::ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
Zachary Turnere5cb2692015-05-01 20:24:26 +0000171 uint64_t VA = Symbol.getVirtualAddress();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000172 if (Ordinal == codeview::ThunkOrdinal::TrampIncremental) {
Zachary Turnere5cb2692015-05-01 20:24:26 +0000173 uint64_t Target = Symbol.getTargetVirtualAddress();
174 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
Zachary Turner2d11c202015-02-27 09:15:59 +0000175 Printer << " -> ";
176 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000177 } else {
Zachary Turner2d11c202015-02-27 09:15:59 +0000178 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000179 << "[" << format_hex(VA, 10) << " - "
180 << format_hex(VA + Symbol.getLength(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000181 }
Zachary Turner7797c722015-03-02 04:39:56 +0000182 Printer << " (";
183 WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
184 Printer << ") ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000185 std::string Name = Symbol.getName();
186 if (!Name.empty())
Zachary Turner2d11c202015-02-27 09:15:59 +0000187 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000188}
189
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000190void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +0000191
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000192void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000193 Printer.NewLine();
194 Printer << "unknown (" << Symbol.getSymTag() << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000195}