Generates conditional branch instead of fake ones for Select instruction in some...
[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 "LinePrinter.h"
12 #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
36 using namespace llvm;
37
38 CompilandDumper::CompilandDumper(LinePrinter &P)
39     : PDBSymDumper(true), Printer(P) {}
40
41 void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol) {}
42
43 void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol) {}
44
45 void CompilandDumper::start(const PDBSymbolCompiland &Symbol, bool Children) {
46   std::string FullName = Symbol.getName();
47   if (Printer.IsCompilandExcluded(FullName))
48     return;
49
50   Printer.NewLine();
51   WithColor(Printer, PDB_ColorItem::Path).get() << FullName;
52   if (!Children)
53     return;
54
55   auto ChildrenEnum = Symbol.findAllChildren();
56   Printer.Indent();
57   while (auto Child = ChildrenEnum->getNext())
58     Child->dump(*this);
59   Printer.Unindent();
60 }
61
62 void CompilandDumper::dump(const PDBSymbolData &Symbol) {
63   if (Printer.IsSymbolExcluded(Symbol.getName()))
64     return;
65
66   Printer.NewLine();
67
68   switch (auto LocType = Symbol.getLocationType()) {
69   case PDB_LocType::Static:
70     Printer << "data: ";
71     WithColor(Printer, PDB_ColorItem::Address).get()
72         << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
73     break;
74   case PDB_LocType::Constant:
75     Printer << "constant: ";
76     WithColor(Printer, PDB_ColorItem::LiteralValue).get()
77         << "[" << Symbol.getValue() << "]";
78     break;
79   default:
80     Printer << "data(unexpected type=" << LocType << ")";
81   }
82
83   Printer << " ";
84   WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
85 }
86
87 void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
88   if (Symbol.getLength() == 0)
89     return;
90   if (Printer.IsSymbolExcluded(Symbol.getName()))
91     return;
92
93   Printer.NewLine();
94   FunctionDumper Dumper(Printer);
95   Dumper.start(Symbol, FunctionDumper::PointerType::None);
96 }
97
98 void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
99   if (Printer.IsSymbolExcluded(Symbol.getName()))
100     return;
101
102   Printer.NewLine();
103   Printer << "label ";
104   WithColor(Printer, PDB_ColorItem::Address).get()
105       << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
106   WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
107 }
108
109 void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
110   if (Printer.IsSymbolExcluded(Symbol.getName()))
111     return;
112
113   Printer.NewLine();
114   Printer << "thunk ";
115   PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
116   uint64_t VA = Symbol.getVirtualAddress();
117   if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) {
118     uint64_t Target = Symbol.getTargetVirtualAddress();
119     WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
120     Printer << " -> ";
121     WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
122   } else {
123     WithColor(Printer, PDB_ColorItem::Address).get()
124         << "[" << format_hex(VA, 10) << " - "
125         << format_hex(VA + Symbol.getLength(), 10) << "]";
126   }
127   Printer << " (";
128   WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
129   Printer << ") ";
130   std::string Name = Symbol.getName();
131   if (!Name.empty())
132     WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
133 }
134
135 void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
136
137 void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
138   Printer.NewLine();
139   Printer << "unknown (" << Symbol.getSymTag() << ")";
140 }