blob: 14197a8b48e151b97efead6678c85e8d81cfa5ba [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
41void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol,
42 raw_ostream &OS, int Indent) {}
43
44void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol, raw_ostream &OS,
45 int Indent) {}
46
47void CompilandDumper::start(const PDBSymbolCompiland &Symbol, raw_ostream &OS,
48 int Indent, bool Children) {
49 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 if (!Children)
56 return;
57
58 auto ChildrenEnum = Symbol.findAllChildren();
Zachary Turner2d11c202015-02-27 09:15:59 +000059 Printer.Indent();
Zachary Turner9a818ad2015-02-22 22:03:38 +000060 while (auto Child = ChildrenEnum->getNext())
61 Child->dump(OS, Indent + 2, *this);
Zachary Turner2d11c202015-02-27 09:15:59 +000062 Printer.Unindent();
Zachary Turner9a818ad2015-02-22 22:03:38 +000063}
64
65void CompilandDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS,
66 int Indent) {
Zachary Turnerf5abda22015-03-01 06:49:49 +000067 if (Printer.IsSymbolExcluded(Symbol.getName()))
68 return;
69
Zachary Turner2d11c202015-02-27 09:15:59 +000070 Printer.NewLine();
71
Zachary Turner9a818ad2015-02-22 22:03:38 +000072 switch (auto LocType = Symbol.getLocationType()) {
73 case PDB_LocType::Static:
Zachary Turner2d11c202015-02-27 09:15:59 +000074 Printer << "data: ";
75 WithColor(Printer, PDB_ColorItem::Address).get()
76 << "[" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +000077 break;
78 case PDB_LocType::Constant:
Zachary Turner2d11c202015-02-27 09:15:59 +000079 Printer << "constant: ";
80 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
81 << "[" << Symbol.getValue() << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +000082 break;
83 default:
Zachary Turner2d11c202015-02-27 09:15:59 +000084 Printer << "data(unexpected type=" << LocType << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +000085 }
86
Zachary Turner2d11c202015-02-27 09:15:59 +000087 Printer << " ";
88 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +000089}
90
91void CompilandDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS,
92 int Indent) {
Zachary Turner29c69102015-02-23 05:58:34 +000093 if (Symbol.getLength() == 0)
94 return;
Zachary Turnerf5abda22015-03-01 06:49:49 +000095 if (Printer.IsSymbolExcluded(Symbol.getName()))
96 return;
Zachary Turner9a818ad2015-02-22 22:03:38 +000097
Zachary Turner2d11c202015-02-27 09:15:59 +000098 Printer.NewLine();
99 FunctionDumper Dumper(Printer);
Zachary Turner29c69102015-02-23 05:58:34 +0000100 Dumper.start(Symbol, FunctionDumper::PointerType::None, OS, Indent);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000101}
102
103void CompilandDumper::dump(const PDBSymbolLabel &Symbol, raw_ostream &OS,
104 int Indent) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000105 if (Printer.IsSymbolExcluded(Symbol.getName()))
106 return;
107
Zachary Turner2d11c202015-02-27 09:15:59 +0000108 Printer.NewLine();
109 Printer << "label ";
110 WithColor(Printer, PDB_ColorItem::Address).get()
111 << "[" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "] ";
112 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000113}
114
115void CompilandDumper::dump(const PDBSymbolThunk &Symbol, raw_ostream &OS,
116 int Indent) {
Zachary Turnerf5abda22015-03-01 06:49:49 +0000117 if (Printer.IsSymbolExcluded(Symbol.getName()))
118 return;
119
Zachary Turner2d11c202015-02-27 09:15:59 +0000120 Printer.NewLine();
121 Printer << "thunk ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000122 PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
123 uint32_t RVA = Symbol.getRelativeVirtualAddress();
124 if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000125 uint32_t Target = Symbol.getTargetRelativeVirtualAddress();
126 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(RVA, 10);
127 Printer << " -> ";
128 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000129 } else {
Zachary Turner2d11c202015-02-27 09:15:59 +0000130 WithColor(Printer, PDB_ColorItem::Address).get()
131 << "[" << format_hex(RVA, 10) << " - "
132 << format_hex(RVA + Symbol.getLength(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000133 }
Zachary Turner2d11c202015-02-27 09:15:59 +0000134 Printer << " (" << Ordinal << ") ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000135 std::string Name = Symbol.getName();
136 if (!Name.empty())
Zachary Turner2d11c202015-02-27 09:15:59 +0000137 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000138}
139
140void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
141 int Indent) {}
142
143void CompilandDumper::dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS,
144 int Indent) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000145 Printer.NewLine();
146 Printer << "unknown (" << Symbol.getSymTag() << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000147}