blob: e15384ce71c4fc5c2aaa1619a09ca9f039340d2b [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 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())
58 Child->dump(OS, Indent + 2, *this);
Zachary Turner2d11c202015-02-27 09:15:59 +000059 Printer.Unindent();
Zachary Turner9a818ad2015-02-22 22:03:38 +000060}
61
62void CompilandDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS,
63 int Indent) {
Zachary Turner2d11c202015-02-27 09:15:59 +000064 Printer.NewLine();
65
Zachary Turner9a818ad2015-02-22 22:03:38 +000066 switch (auto LocType = Symbol.getLocationType()) {
67 case PDB_LocType::Static:
Zachary Turner2d11c202015-02-27 09:15:59 +000068 Printer << "data: ";
69 WithColor(Printer, PDB_ColorItem::Address).get()
70 << "[" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +000071 break;
72 case PDB_LocType::Constant:
Zachary Turner2d11c202015-02-27 09:15:59 +000073 Printer << "constant: ";
74 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
75 << "[" << Symbol.getValue() << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +000076 break;
77 default:
Zachary Turner2d11c202015-02-27 09:15:59 +000078 Printer << "data(unexpected type=" << LocType << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +000079 }
80
Zachary Turner2d11c202015-02-27 09:15:59 +000081 Printer << " ";
82 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +000083}
84
85void CompilandDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS,
86 int Indent) {
Zachary Turner29c69102015-02-23 05:58:34 +000087 if (Symbol.getLength() == 0)
88 return;
Zachary Turner9a818ad2015-02-22 22:03:38 +000089
Zachary Turner2d11c202015-02-27 09:15:59 +000090 Printer.NewLine();
91 FunctionDumper Dumper(Printer);
Zachary Turner29c69102015-02-23 05:58:34 +000092 Dumper.start(Symbol, FunctionDumper::PointerType::None, OS, Indent);
Zachary Turner9a818ad2015-02-22 22:03:38 +000093}
94
95void CompilandDumper::dump(const PDBSymbolLabel &Symbol, raw_ostream &OS,
96 int Indent) {
Zachary Turner2d11c202015-02-27 09:15:59 +000097 Printer.NewLine();
98 Printer << "label ";
99 WithColor(Printer, PDB_ColorItem::Address).get()
100 << "[" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "] ";
101 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000102}
103
104void CompilandDumper::dump(const PDBSymbolThunk &Symbol, raw_ostream &OS,
105 int Indent) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000106 Printer.NewLine();
107 Printer << "thunk ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000108 PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
109 uint32_t RVA = Symbol.getRelativeVirtualAddress();
110 if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000111 uint32_t Target = Symbol.getTargetRelativeVirtualAddress();
112 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(RVA, 10);
113 Printer << " -> ";
114 WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
Zachary Turner9a818ad2015-02-22 22:03:38 +0000115 } else {
Zachary Turner2d11c202015-02-27 09:15:59 +0000116 WithColor(Printer, PDB_ColorItem::Address).get()
117 << "[" << format_hex(RVA, 10) << " - "
118 << format_hex(RVA + Symbol.getLength(), 10) << "]";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000119 }
Zachary Turner2d11c202015-02-27 09:15:59 +0000120 Printer << " (" << Ordinal << ") ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000121 std::string Name = Symbol.getName();
122 if (!Name.empty())
Zachary Turner2d11c202015-02-27 09:15:59 +0000123 WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000124}
125
126void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
127 int Indent) {}
128
129void CompilandDumper::dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS,
130 int Indent) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000131 Printer.NewLine();
132 Printer << "unknown (" << Symbol.getSymTag() << ")";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000133}