blob: ee55228309d94be80db102bd1a922b1d40695eb7 [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"
11#include "llvm-pdbdump.h"
12
13#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
14#include "llvm/DebugInfo/PDB/IPDBSession.h"
15#include "llvm/DebugInfo/PDB/PDBExtras.h"
16#include "llvm/DebugInfo/PDB/PDBSymbol.h"
17#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
18#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
19#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
20#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
21#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
22#include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
23#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
24#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
25#include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
26#include "llvm/Support/Format.h"
27#include "llvm/Support/Path.h"
28#include "llvm/Support/raw_ostream.h"
29
30#include "FunctionDumper.h"
31
32#include <utility>
33#include <vector>
34
35using namespace llvm;
36
37CompilandDumper::CompilandDumper() : PDBSymDumper(true) {}
38
39void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol,
40 raw_ostream &OS, int Indent) {}
41
42void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol, raw_ostream &OS,
43 int Indent) {}
44
45void CompilandDumper::start(const PDBSymbolCompiland &Symbol, raw_ostream &OS,
46 int Indent, bool Children) {
47 std::string FullName = Symbol.getName();
48 OS << newline(Indent) << FullName;
49 if (!Children)
50 return;
51
52 auto ChildrenEnum = Symbol.findAllChildren();
53 while (auto Child = ChildrenEnum->getNext())
54 Child->dump(OS, Indent + 2, *this);
55}
56
57void CompilandDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS,
58 int Indent) {
59 OS << newline(Indent);
60 switch (auto LocType = Symbol.getLocationType()) {
61 case PDB_LocType::Static:
62 OS << "data: [";
63 OS << format_hex(Symbol.getRelativeVirtualAddress(), 10);
64 OS << "]";
65 break;
66 case PDB_LocType::Constant:
67 OS << "constant: [" << Symbol.getValue() << "]";
68 break;
69 default:
70 OS << "data(unexpected type=" << LocType << ")";
71 }
72
73 OS << " " << Symbol.getName();
74}
75
76void CompilandDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS,
77 int Indent) {
78 uint32_t FuncStart = Symbol.getRelativeVirtualAddress();
79 uint32_t FuncEnd = FuncStart + Symbol.getLength();
80 OS << newline(Indent) << "func [" << format_hex(FuncStart, 8);
81 if (auto DebugStart = Symbol.findOneChild<PDBSymbolFuncDebugStart>())
82 OS << "+" << DebugStart->getRelativeVirtualAddress() - FuncStart;
83 OS << " - " << format_hex(FuncEnd, 8);
84 if (auto DebugEnd = Symbol.findOneChild<PDBSymbolFuncDebugEnd>())
85 OS << "-" << FuncEnd - DebugEnd->getRelativeVirtualAddress();
86 OS << "] ";
87
88 if (Symbol.hasFramePointer())
89 OS << "(" << Symbol.getLocalBasePointerRegisterId() << ")";
90 else
91 OS << "(FPO)";
92
93 OS << " ";
94
95 FunctionDumper Dumper;
96 Dumper.start(Symbol, OS);
97 OS.flush();
98}
99
100void CompilandDumper::dump(const PDBSymbolLabel &Symbol, raw_ostream &OS,
101 int Indent) {
102 OS << newline(Indent);
103 OS << "label [" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "] "
104 << Symbol.getName();
105}
106
107void CompilandDumper::dump(const PDBSymbolThunk &Symbol, raw_ostream &OS,
108 int Indent) {
109 OS << newline(Indent) << "thunk ";
110 PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
111 uint32_t RVA = Symbol.getRelativeVirtualAddress();
112 if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) {
113 OS << format_hex(RVA, 10);
114 OS << " -> " << format_hex(Symbol.getTargetRelativeVirtualAddress(), 10);
115 } else {
116 OS << "[" << format_hex(RVA, 10);
117 OS << " - " << format_hex(RVA + Symbol.getLength(), 10) << "]";
118 }
119 OS << " (" << Ordinal << ") ";
120 std::string Name = Symbol.getName();
121 if (!Name.empty())
122 OS << Name;
123}
124
125void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
126 int Indent) {}
127
128void CompilandDumper::dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS,
129 int Indent) {
130 OS << newline(Indent);
131 OS << "unknown (" << Symbol.getSymTag() << ")";
132}