blob: 0d99c9b1245c38c859c19070df1bfaa7b8bb4e05 [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();
Aaron Smith13cb6be2018-04-10 14:47:12 +000063 if (File->getChecksumType() != PDB_Checksum::None) {
64 auto ChecksumType = File->getChecksumType();
65 auto ChecksumHexString = toHex(File->getChecksum());
66 WithColor(Printer, PDB_ColorItem::Comment).get()
67 << " (" << ChecksumType << ": " << ChecksumHexString << ")";
68 }
Zachary Turnera99000d2016-03-08 21:42:24 +000069
Aaron Smitha27b5e92018-03-07 02:23:08 +000070 auto Lines = Session.findLineNumbers(Symbol, *File);
71 if (!Lines)
72 continue;
Zachary Turnera99000d2016-03-08 21:42:24 +000073
Aaron Smitha27b5e92018-03-07 02:23:08 +000074 Printer.Indent();
75 while (auto Line = Lines->getNext()) {
76 Printer.NewLine();
77 uint32_t LineStart = Line->getLineNumber();
78 uint32_t LineEnd = Line->getLineNumberEnd();
Adrian McCarthyd5ca7202016-08-17 23:01:03 +000079
Aaron Smitha27b5e92018-03-07 02:23:08 +000080 Printer << "Line ";
81 PDB_ColorItem StatementColor = Line->isStatement()
82 ? PDB_ColorItem::Keyword
83 : PDB_ColorItem::LiteralValue;
84 WithColor(Printer, StatementColor).get() << LineStart;
85 if (LineStart != LineEnd)
86 WithColor(Printer, StatementColor).get() << " - " << LineEnd;
87
88 uint32_t ColumnStart = Line->getColumnNumber();
89 uint32_t ColumnEnd = Line->getColumnNumberEnd();
90 if (ColumnStart != 0 || ColumnEnd != 0) {
91 Printer << ", Column: ";
92 WithColor(Printer, StatementColor).get() << ColumnStart;
93 if (ColumnEnd != ColumnStart)
94 WithColor(Printer, StatementColor).get() << " - " << ColumnEnd;
95 }
96
97 Printer << ", Address: ";
98 if (Line->getLength() > 0) {
99 uint64_t AddrStart = Line->getVirtualAddress();
100 uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
101 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnera99000d2016-03-08 21:42:24 +0000102 << "[" << format_hex(AddrStart, 10) << " - "
103 << format_hex(AddrEnd, 10) << "]";
Aaron Smitha27b5e92018-03-07 02:23:08 +0000104 Printer << " (" << Line->getLength() << " bytes)";
105 } else {
106 uint64_t AddrStart = Line->getVirtualAddress();
107 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnera99000d2016-03-08 21:42:24 +0000108 << "[" << format_hex(AddrStart, 10) << "] ";
Aaron Smitha27b5e92018-03-07 02:23:08 +0000109 Printer << "(0 bytes)";
110 }
Zachary Turnera99000d2016-03-08 21:42:24 +0000111 }
Aaron Smitha27b5e92018-03-07 02:23:08 +0000112 Printer.Unindent();
Zachary Turnera99000d2016-03-08 21:42:24 +0000113 }
114 Printer.Unindent();
115 }
Zachary Turnera99000d2016-03-08 21:42:24 +0000116 }
117
118 if (opts & Flags::Children) {
Aaron Smitha27b5e92018-03-07 02:23:08 +0000119 if (auto ChildrenEnum = Symbol.findAllChildren()) {
120 Printer.Indent();
121 while (auto Child = ChildrenEnum->getNext())
122 Child->dump(*this);
123 Printer.Unindent();
124 }
Zachary Turnera99000d2016-03-08 21:42:24 +0000125 }
Zachary Turner9a818ad2015-02-22 22:03:38 +0000126}
127
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000128void CompilandDumper::dump(const PDBSymbolData &Symbol) {
Zachary Turner0683be22017-05-14 01:13:40 +0000129 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Data))
130 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +0000131 if (Printer.IsSymbolExcluded(Symbol.getName()))
132 return;
133
Zachary Turner2d11c202015-02-27 09:15:59 +0000134 Printer.NewLine();
135
Zachary Turner9a818ad2015-02-22 22:03:38 +0000136 switch (auto LocType = Symbol.getLocationType()) {
137 case PDB_LocType::Static:
Zachary Turner2d11c202015-02-27 09:15:59 +0000138 Printer << "data: ";
139 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000140 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
Zachary Turner0683be22017-05-14 01:13:40 +0000141
142 WithColor(Printer, PDB_ColorItem::Comment).get()
143 << " [sizeof = " << getTypeLength(Symbol) << "]";
144
Zachary Turner9a818ad2015-02-22 22:03:38 +0000145 break;
146 case PDB_LocType::Constant:
Zachary Turner2d11c202015-02-27 09:15:59 +0000147 Printer << "constant: ";
148 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
149 << "[" << Symbol.getValue() << "]";
Zachary Turner0683be22017-05-14 01:13:40 +0000150 WithColor(Printer, PDB_ColorItem::Comment).get()
151 << " [sizeof = " << getTypeLength(Symbol) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000152 break;
153 default:
Zachary Turner2d11c202015-02-27 09:15:59 +0000154 Printer << "data(unexpected type=" << LocType << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000155 }
156
Zachary Turner2d11c202015-02-27 09:15:59 +0000157 Printer << " ";
158 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000159}
160
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000161void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
Zachary Turner0683be22017-05-14 01:13:40 +0000162 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Functions))
163 return;
Zachary Turner29c69102015-02-23 05:58:34 +0000164 if (Symbol.getLength() == 0)
165 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +0000166 if (Printer.IsSymbolExcluded(Symbol.getName()))
167 return;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000168
Zachary Turner2d11c202015-02-27 09:15:59 +0000169 Printer.NewLine();
170 FunctionDumper Dumper(Printer);
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000171 Dumper.start(Symbol, FunctionDumper::PointerType::None);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000172}
173
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000174void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000175 if (Printer.IsSymbolExcluded(Symbol.getName()))
176 return;
177
Zachary Turner2d11c202015-02-27 09:15:59 +0000178 Printer.NewLine();
179 Printer << "label ";
180 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000181 << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
Zachary Turner2d11c202015-02-27 09:15:59 +0000182 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000183}
184
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000185void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
Zachary Turner0683be22017-05-14 01:13:40 +0000186 if (!shouldDumpSymLevel(opts::pretty::SymLevel::Thunks))
187 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +0000188 if (Printer.IsSymbolExcluded(Symbol.getName()))
189 return;
190
Zachary Turner2d11c202015-02-27 09:15:59 +0000191 Printer.NewLine();
192 Printer << "thunk ";
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000193 codeview::ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
Zachary Turnere5cb2692015-05-01 20:24:26 +0000194 uint64_t VA = Symbol.getVirtualAddress();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000195 if (Ordinal == codeview::ThunkOrdinal::TrampIncremental) {
Zachary Turnere5cb2692015-05-01 20:24:26 +0000196 uint64_t Target = Symbol.getTargetVirtualAddress();
197 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
Zachary Turner2d11c202015-02-27 09:15:59 +0000198 Printer << " -> ";
199 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000200 } else {
Zachary Turner2d11c202015-02-27 09:15:59 +0000201 WithColor(Printer, PDB_ColorItem::Address).get()
Zachary Turnere5cb2692015-05-01 20:24:26 +0000202 << "[" << format_hex(VA, 10) << " - "
203 << format_hex(VA + Symbol.getLength(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000204 }
Zachary Turner7797c722015-03-02 04:39:56 +0000205 Printer << " (";
206 WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
207 Printer << ") ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000208 std::string Name = Symbol.getName();
209 if (!Name.empty())
Zachary Turner2d11c202015-02-27 09:15:59 +0000210 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000211}
212
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000213void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +0000214
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000215void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000216 Printer.NewLine();
217 Printer << "unknown (" << Symbol.getSymTag() << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000218}