blob: 86b54589c24b681c016ab6372031f86f70004a36 [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;
38
Zachary Turner2d11c202015-02-27 09:15:59 +000039CompilandDumper::CompilandDumper(LinePrinter &P)
Zachary Turner94118282015-02-27 09:53:55 +000040 : PDBSymDumper(true), Printer(P) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +000041
Zachary Turnerb52d08d2015-03-01 06:51:29 +000042void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +000043
Zachary Turnerb52d08d2015-03-01 06:51:29 +000044void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +000045
Zachary Turnera99000d2016-03-08 21:42:24 +000046void CompilandDumper::start(const PDBSymbolCompiland &Symbol,
47 CompilandDumpFlags opts) {
Zachary Turner9a818ad2015-02-22 22:03:38 +000048 std::string FullName = Symbol.getName();
Zachary Turnerf5abda22015-03-01 06:49:49 +000049 if (Printer.IsCompilandExcluded(FullName))
50 return;
51
Zachary Turner2d11c202015-02-27 09:15:59 +000052 Printer.NewLine();
53 WithColor(Printer, PDB_ColorItem::Path).get() << FullName;
Zachary Turner9a818ad2015-02-22 22:03:38 +000054
Zachary Turnera99000d2016-03-08 21:42:24 +000055 if (opts & Flags::Lines) {
56 const IPDBSession &Session = Symbol.getSession();
57 auto Files = Session.getSourceFilesForCompiland(Symbol);
58 Printer.Indent();
59 while (auto File = Files->getNext()) {
60 Printer.NewLine();
61 WithColor(Printer, PDB_ColorItem::Path).get() << File->getFileName();
62
63 auto Lines = Session.findLineNumbers(Symbol, *File);
64 Printer.Indent();
65 while (auto Line = Lines->getNext()) {
66 Printer.NewLine();
67 uint32_t LineStart = Line->getLineNumber();
68 uint32_t LineEnd = Line->getLineNumberEnd();
69
70 Printer << "Line ";
71 PDB_ColorItem StatementColor = Line->isStatement()
72 ? PDB_ColorItem::Keyword
73 : PDB_ColorItem::LiteralValue;
74 WithColor(Printer, StatementColor).get() << LineStart;
75 if (LineStart != LineEnd)
76 WithColor(Printer, StatementColor).get() << " - " << LineEnd;
77
78 Printer << ", Address: ";
79 if (Line->getLength() > 0) {
80 uint64_t AddrStart = Line->getVirtualAddress();
81 uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
82 WithColor(Printer, PDB_ColorItem::Address).get()
83 << "[" << format_hex(AddrStart, 10) << " - "
84 << format_hex(AddrEnd, 10) << "]";
85 Printer << " (" << Line->getLength() << " bytes)";
86 } else {
87 uint64_t AddrStart = Line->getVirtualAddress();
88 WithColor(Printer, PDB_ColorItem::Address).get()
89 << "[" << format_hex(AddrStart, 10) << "] ";
90 Printer << "(0 bytes)";
91 }
92 }
93 Printer.Unindent();
94 }
95 Printer.Unindent();
96 }
97
98 if (opts & Flags::Children) {
99 auto ChildrenEnum = Symbol.findAllChildren();
100 Printer.Indent();
101 while (auto Child = ChildrenEnum->getNext())
102 Child->dump(*this);
103 Printer.Unindent();
104 }
Zachary Turner9a818ad2015-02-22 22:03:38 +0000105}
106
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000107void CompilandDumper::dump(const PDBSymbolData &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000108 if (Printer.IsSymbolExcluded(Symbol.getName()))
109 return;
110
Zachary Turner2d11c202015-02-27 09:15:59 +0000111 Printer.NewLine();
112
Zachary Turner9a818ad2015-02-22 22:03:38 +0000113 switch (auto LocType = Symbol.getLocationType()) {
114 case PDB_LocType::Static:
Zachary Turner2d11c202015-02-27 09:15:59 +0000115 Printer << "data: ";
116 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000117 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000118 break;
119 case PDB_LocType::Constant:
Zachary Turner2d11c202015-02-27 09:15:59 +0000120 Printer << "constant: ";
121 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
122 << "[" << Symbol.getValue() << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000123 break;
124 default:
Zachary Turner2d11c202015-02-27 09:15:59 +0000125 Printer << "data(unexpected type=" << LocType << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000126 }
127
Zachary Turner2d11c202015-02-27 09:15:59 +0000128 Printer << " ";
129 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000130}
131
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000132void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
Zachary Turner29c69102015-02-23 05:58:34 +0000133 if (Symbol.getLength() == 0)
134 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +0000135 if (Printer.IsSymbolExcluded(Symbol.getName()))
136 return;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000137
Zachary Turner2d11c202015-02-27 09:15:59 +0000138 Printer.NewLine();
139 FunctionDumper Dumper(Printer);
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000140 Dumper.start(Symbol, FunctionDumper::PointerType::None);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000141}
142
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000143void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000144 if (Printer.IsSymbolExcluded(Symbol.getName()))
145 return;
146
Zachary Turner2d11c202015-02-27 09:15:59 +0000147 Printer.NewLine();
148 Printer << "label ";
149 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000150 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
Zachary Turner2d11c202015-02-27 09:15:59 +0000151 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000152}
153
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000154void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000155 if (Printer.IsSymbolExcluded(Symbol.getName()))
156 return;
157
Zachary Turner2d11c202015-02-27 09:15:59 +0000158 Printer.NewLine();
159 Printer << "thunk ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000160 PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
Zachary Turnere5cb2692015-05-01 20:24:26 +0000161 uint64_t VA = Symbol.getVirtualAddress();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000162 if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) {
Zachary Turnere5cb2692015-05-01 20:24:26 +0000163 uint64_t Target = Symbol.getTargetVirtualAddress();
164 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
Zachary Turner2d11c202015-02-27 09:15:59 +0000165 Printer << " -> ";
166 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000167 } else {
Zachary Turner2d11c202015-02-27 09:15:59 +0000168 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000169 << "[" << format_hex(VA, 10) << " - "
170 << format_hex(VA + Symbol.getLength(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000171 }
Zachary Turner7797c722015-03-02 04:39:56 +0000172 Printer << " (";
173 WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
174 Printer << ") ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000175 std::string Name = Symbol.getName();
176 if (!Name.empty())
Zachary Turner2d11c202015-02-27 09:15:59 +0000177 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000178}
179
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000180void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +0000181
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000182void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000183 Printer.NewLine();
184 Printer << "unknown (" << Symbol.getSymTag() << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000185}