blob: accb2debd27b3c4f9f2ac66897df6f089be1834f [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"
15#include "llvm/DebugInfo/PDB/IPDBSession.h"
16#include "llvm/DebugInfo/PDB/PDBExtras.h"
17#include "llvm/DebugInfo/PDB/PDBSymbol.h"
18#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
19#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
20#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
21#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
22#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
23#include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
24#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
25#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
26#include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
27#include "llvm/Support/Format.h"
28#include "llvm/Support/Path.h"
29#include "llvm/Support/raw_ostream.h"
30
31#include "FunctionDumper.h"
32
33#include <utility>
34#include <vector>
35
36using namespace llvm;
37
Zachary Turner2d11c202015-02-27 09:15:59 +000038CompilandDumper::CompilandDumper(LinePrinter &P)
Zachary Turner94118282015-02-27 09:53:55 +000039 : PDBSymDumper(true), Printer(P) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +000040
Zachary Turnerb52d08d2015-03-01 06:51:29 +000041void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +000042
Zachary Turnerb52d08d2015-03-01 06:51:29 +000043void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +000044
Zachary Turnerb52d08d2015-03-01 06:51:29 +000045void CompilandDumper::start(const PDBSymbolCompiland &Symbol, bool Children) {
Zachary Turner9a818ad2015-02-22 22:03:38 +000046 std::string FullName = Symbol.getName();
Zachary Turnerf5abda22015-03-01 06:49:49 +000047 if (Printer.IsCompilandExcluded(FullName))
48 return;
49
Zachary Turner2d11c202015-02-27 09:15:59 +000050 Printer.NewLine();
51 WithColor(Printer, PDB_ColorItem::Path).get() << FullName;
Zachary Turner9a818ad2015-02-22 22:03:38 +000052 if (!Children)
53 return;
54
55 auto ChildrenEnum = Symbol.findAllChildren();
Zachary Turner2d11c202015-02-27 09:15:59 +000056 Printer.Indent();
Zachary Turner9a818ad2015-02-22 22:03:38 +000057 while (auto Child = ChildrenEnum->getNext())
Zachary Turnerb52d08d2015-03-01 06:51:29 +000058 Child->dump(*this);
Zachary Turner2d11c202015-02-27 09:15:59 +000059 Printer.Unindent();
Zachary Turner9a818ad2015-02-22 22:03:38 +000060}
61
Zachary Turnerb52d08d2015-03-01 06:51:29 +000062void CompilandDumper::dump(const PDBSymbolData &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +000063 if (Printer.IsSymbolExcluded(Symbol.getName()))
64 return;
65
Zachary Turner2d11c202015-02-27 09:15:59 +000066 Printer.NewLine();
67
Zachary Turner9a818ad2015-02-22 22:03:38 +000068 switch (auto LocType = Symbol.getLocationType()) {
69 case PDB_LocType::Static:
Zachary Turner2d11c202015-02-27 09:15:59 +000070 Printer << "data: ";
71 WithColor(Printer, PDB_ColorItem::Address).get()
72 << "[" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +000073 break;
74 case PDB_LocType::Constant:
Zachary Turner2d11c202015-02-27 09:15:59 +000075 Printer << "constant: ";
76 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
77 << "[" << Symbol.getValue() << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +000078 break;
79 default:
Zachary Turner2d11c202015-02-27 09:15:59 +000080 Printer << "data(unexpected type=" << LocType << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +000081 }
82
Zachary Turner2d11c202015-02-27 09:15:59 +000083 Printer << " ";
84 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +000085}
86
Zachary Turnerb52d08d2015-03-01 06:51:29 +000087void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
Zachary Turner29c69102015-02-23 05:58:34 +000088 if (Symbol.getLength() == 0)
89 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +000090 if (Printer.IsSymbolExcluded(Symbol.getName()))
91 return;
Zachary Turner9a818ad2015-02-22 22:03:38 +000092
Zachary Turner2d11c202015-02-27 09:15:59 +000093 Printer.NewLine();
94 FunctionDumper Dumper(Printer);
Zachary Turnerb52d08d2015-03-01 06:51:29 +000095 Dumper.start(Symbol, FunctionDumper::PointerType::None);
Zachary Turner9a818ad2015-02-22 22:03:38 +000096}
97
Zachary Turnerb52d08d2015-03-01 06:51:29 +000098void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +000099 if (Printer.IsSymbolExcluded(Symbol.getName()))
100 return;
101
Zachary Turner2d11c202015-02-27 09:15:59 +0000102 Printer.NewLine();
103 Printer << "label ";
104 WithColor(Printer, PDB_ColorItem::Address).get()
105 << "[" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "] ";
106 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000107}
108
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000109void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000110 if (Printer.IsSymbolExcluded(Symbol.getName()))
111 return;
112
Zachary Turner2d11c202015-02-27 09:15:59 +0000113 Printer.NewLine();
114 Printer << "thunk ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000115 PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
116 uint32_t RVA = Symbol.getRelativeVirtualAddress();
117 if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000118 uint32_t Target = Symbol.getTargetRelativeVirtualAddress();
119 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(RVA, 10);
120 Printer << " -> ";
121 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000122 } else {
Zachary Turner2d11c202015-02-27 09:15:59 +0000123 WithColor(Printer, PDB_ColorItem::Address).get()
124 << "[" << format_hex(RVA, 10) << " - "
125 << format_hex(RVA + Symbol.getLength(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000126 }
Zachary Turner2d11c202015-02-27 09:15:59 +0000127 Printer << " (" << Ordinal << ") ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000128 std::string Name = Symbol.getName();
129 if (!Name.empty())
Zachary Turner2d11c202015-02-27 09:15:59 +0000130 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000131}
132
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000133void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
Zachary Turner9a818ad2015-02-22 22:03:38 +0000134
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000135void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000136 Printer.NewLine();
137 Printer << "unknown (" << Symbol.getSymTag() << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000138}