blob: 5ec37cbbb5a065526cbf3716cb152a8cdeb240fe [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
79 Printer << ", Address: ";
80 if (Line->getLength() > 0) {
81 uint64_t AddrStart = Line->getVirtualAddress();
82 uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
83 WithColor(Printer, PDB_ColorItem::Address).get()
84 << "[" << format_hex(AddrStart, 10) << " - "
85 << format_hex(AddrEnd, 10) << "]";
86 Printer << " (" << Line->getLength() << " bytes)";
87 } else {
88 uint64_t AddrStart = Line->getVirtualAddress();
89 WithColor(Printer, PDB_ColorItem::Address).get()
90 << "[" << format_hex(AddrStart, 10) << "] ";
91 Printer << "(0 bytes)";
92 }
93 }
94 Printer.Unindent();
95 }
96 Printer.Unindent();
97 }
98
99 if (opts & Flags::Children) {
100 auto ChildrenEnum = Symbol.findAllChildren();
101 Printer.Indent();
102 while (auto Child = ChildrenEnum->getNext())
103 Child->dump(*this);
104 Printer.Unindent();
105 }
Zachary Turner9a818ad2015-02-22 22:03:38 +0000106}
107
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000108void CompilandDumper::dump(const PDBSymbolData &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000109 if (Printer.IsSymbolExcluded(Symbol.getName()))
110 return;
111
Zachary Turner2d11c202015-02-27 09:15:59 +0000112 Printer.NewLine();
113
Zachary Turner9a818ad2015-02-22 22:03:38 +0000114 switch (auto LocType = Symbol.getLocationType()) {
115 case PDB_LocType::Static:
Zachary Turner2d11c202015-02-27 09:15:59 +0000116 Printer << "data: ";
117 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000118 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000119 break;
120 case PDB_LocType::Constant:
Zachary Turner2d11c202015-02-27 09:15:59 +0000121 Printer << "constant: ";
122 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
123 << "[" << Symbol.getValue() << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000124 break;
125 default:
Zachary Turner2d11c202015-02-27 09:15:59 +0000126 Printer << "data(unexpected type=" << LocType << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000127 }
128
Zachary Turner2d11c202015-02-27 09:15:59 +0000129 Printer << " ";
130 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000131}
132
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000133void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
Zachary Turner29c69102015-02-23 05:58:34 +0000134 if (Symbol.getLength() == 0)
135 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +0000136 if (Printer.IsSymbolExcluded(Symbol.getName()))
137 return;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000138
Zachary Turner2d11c202015-02-27 09:15:59 +0000139 Printer.NewLine();
140 FunctionDumper Dumper(Printer);
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000141 Dumper.start(Symbol, FunctionDumper::PointerType::None);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000142}
143
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000144void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000145 if (Printer.IsSymbolExcluded(Symbol.getName()))
146 return;
147
Zachary Turner2d11c202015-02-27 09:15:59 +0000148 Printer.NewLine();
149 Printer << "label ";
150 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000151 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
Zachary Turner2d11c202015-02-27 09:15:59 +0000152 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 PDBSymbolThunk &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000156 if (Printer.IsSymbolExcluded(Symbol.getName()))
157 return;
158
Zachary Turner2d11c202015-02-27 09:15:59 +0000159 Printer.NewLine();
160 Printer << "thunk ";
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000161 codeview::ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
Zachary Turnere5cb2692015-05-01 20:24:26 +0000162 uint64_t VA = Symbol.getVirtualAddress();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000163 if (Ordinal == codeview::ThunkOrdinal::TrampIncremental) {
Zachary Turnere5cb2692015-05-01 20:24:26 +0000164 uint64_t Target = Symbol.getTargetVirtualAddress();
165 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
Zachary Turner2d11c202015-02-27 09:15:59 +0000166 Printer << " -> ";
167 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000168 } else {
Zachary Turner2d11c202015-02-27 09:15:59 +0000169 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000170 << "[" << format_hex(VA, 10) << " - "
171 << format_hex(VA + Symbol.getLength(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000172 }
Zachary Turner7797c722015-03-02 04:39:56 +0000173 Printer << " (";
174 WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
175 Printer << ") ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000176 std::string Name = Symbol.getName();
177 if (!Name.empty())
Zachary Turner2d11c202015-02-27 09:15:59 +0000178 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000179}
180
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000181void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +0000182
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000183void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000184 Printer.NewLine();
185 Printer << "unknown (" << Symbol.getSymTag() << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000186}