[IC] Turn non-null MD on pointer loads to range MD on integer loads.
[oota-llvm.git] / tools / llvm-pdbdump / CompilandDumper.cpp
1 //===- 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
35 using namespace llvm;
36
37 CompilandDumper::CompilandDumper() : PDBSymDumper(true) {}
38
39 void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol,
40                            raw_ostream &OS, int Indent) {}
41
42 void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol, raw_ostream &OS,
43                            int Indent) {}
44
45 void 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
57 void 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
76 void CompilandDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS,
77                            int Indent) {
78   if (Symbol.getLength() == 0)
79     return;
80
81   FunctionDumper Dumper;
82   Dumper.start(Symbol, FunctionDumper::PointerType::None, OS, Indent);
83 }
84
85 void CompilandDumper::dump(const PDBSymbolLabel &Symbol, raw_ostream &OS,
86                            int Indent) {
87   OS << newline(Indent);
88   OS << "label [" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "] "
89      << Symbol.getName();
90 }
91
92 void CompilandDumper::dump(const PDBSymbolThunk &Symbol, raw_ostream &OS,
93                            int Indent) {
94   OS << newline(Indent) << "thunk ";
95   PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
96   uint32_t RVA = Symbol.getRelativeVirtualAddress();
97   if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) {
98     OS << format_hex(RVA, 10);
99     OS << " -> " << format_hex(Symbol.getTargetRelativeVirtualAddress(), 10);
100   } else {
101     OS << "[" << format_hex(RVA, 10);
102     OS << " - " << format_hex(RVA + Symbol.getLength(), 10) << "]";
103   }
104   OS << " (" << Ordinal << ") ";
105   std::string Name = Symbol.getName();
106   if (!Name.empty())
107     OS << Name;
108 }
109
110 void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
111                            int Indent) {}
112
113 void CompilandDumper::dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS,
114                            int Indent) {
115   OS << newline(Indent);
116   OS << "unknown (" << Symbol.getSymTag() << ")";
117 }