]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbdump/PrettyCompilandDumper.cpp
Merge llvm, clang, lld and lldb release_40 branch r292009. Also update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbdump / PrettyCompilandDumper.cpp
1 //===- PrettyCompilandDumper.cpp - llvm-pdbdump compiland 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 "PrettyCompilandDumper.h"
11
12 #include "LinePrinter.h"
13 #include "PrettyFunctionDumper.h"
14 #include "llvm-pdbdump.h"
15
16 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
17 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
18 #include "llvm/DebugInfo/PDB/IPDBSession.h"
19 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
20 #include "llvm/DebugInfo/PDB/PDBExtras.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
26 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
27 #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
28 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
29 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
30 #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
31 #include "llvm/Support/Format.h"
32 #include "llvm/Support/Path.h"
33 #include "llvm/Support/raw_ostream.h"
34
35 #include <utility>
36
37 using namespace llvm;
38 using namespace llvm::pdb;
39
40 CompilandDumper::CompilandDumper(LinePrinter &P)
41     : PDBSymDumper(true), Printer(P) {}
42
43 void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol) {}
44
45 void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol) {}
46
47 void CompilandDumper::start(const PDBSymbolCompiland &Symbol,
48                             CompilandDumpFlags opts) {
49   std::string FullName = Symbol.getName();
50   if (Printer.IsCompilandExcluded(FullName))
51     return;
52
53   Printer.NewLine();
54   WithColor(Printer, PDB_ColorItem::Path).get() << FullName;
55
56   if (opts & Flags::Lines) {
57     const IPDBSession &Session = Symbol.getSession();
58     auto Files = Session.getSourceFilesForCompiland(Symbol);
59     Printer.Indent();
60     while (auto File = Files->getNext()) {
61       Printer.NewLine();
62       WithColor(Printer, PDB_ColorItem::Path).get() << File->getFileName();
63
64       auto Lines = Session.findLineNumbers(Symbol, *File);
65       Printer.Indent();
66       while (auto Line = Lines->getNext()) {
67         Printer.NewLine();
68         uint32_t LineStart = Line->getLineNumber();
69         uint32_t LineEnd = Line->getLineNumberEnd();
70
71         Printer << "Line ";
72         PDB_ColorItem StatementColor = Line->isStatement()
73                                            ? PDB_ColorItem::Keyword
74                                            : PDB_ColorItem::LiteralValue;
75         WithColor(Printer, StatementColor).get() << LineStart;
76         if (LineStart != LineEnd)
77           WithColor(Printer, StatementColor).get() << " - " << LineEnd;
78
79         uint32_t ColumnStart = Line->getColumnNumber();
80         uint32_t ColumnEnd = Line->getColumnNumberEnd();
81         if (ColumnStart != 0 || ColumnEnd != 0) {
82           Printer << ", Column: ";
83           WithColor(Printer, StatementColor).get() << ColumnStart;
84           if (ColumnEnd != ColumnStart)
85             WithColor(Printer, StatementColor).get() << " - " << ColumnEnd;
86         }
87
88         Printer << ", Address: ";
89         if (Line->getLength() > 0) {
90           uint64_t AddrStart = Line->getVirtualAddress();
91           uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
92           WithColor(Printer, PDB_ColorItem::Address).get()
93               << "[" << format_hex(AddrStart, 10) << " - "
94               << format_hex(AddrEnd, 10) << "]";
95           Printer << " (" << Line->getLength() << " bytes)";
96         } else {
97           uint64_t AddrStart = Line->getVirtualAddress();
98           WithColor(Printer, PDB_ColorItem::Address).get()
99               << "[" << format_hex(AddrStart, 10) << "] ";
100           Printer << "(0 bytes)";
101         }
102       }
103       Printer.Unindent();
104     }
105     Printer.Unindent();
106   }
107
108   if (opts & Flags::Children) {
109     auto ChildrenEnum = Symbol.findAllChildren();
110     Printer.Indent();
111     while (auto Child = ChildrenEnum->getNext())
112       Child->dump(*this);
113     Printer.Unindent();
114   }
115 }
116
117 void CompilandDumper::dump(const PDBSymbolData &Symbol) {
118   if (Printer.IsSymbolExcluded(Symbol.getName()))
119     return;
120
121   Printer.NewLine();
122
123   switch (auto LocType = Symbol.getLocationType()) {
124   case PDB_LocType::Static:
125     Printer << "data: ";
126     WithColor(Printer, PDB_ColorItem::Address).get()
127         << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
128     break;
129   case PDB_LocType::Constant:
130     Printer << "constant: ";
131     WithColor(Printer, PDB_ColorItem::LiteralValue).get()
132         << "[" << Symbol.getValue() << "]";
133     break;
134   default:
135     Printer << "data(unexpected type=" << LocType << ")";
136   }
137
138   Printer << " ";
139   WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
140 }
141
142 void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
143   if (Symbol.getLength() == 0)
144     return;
145   if (Printer.IsSymbolExcluded(Symbol.getName()))
146     return;
147
148   Printer.NewLine();
149   FunctionDumper Dumper(Printer);
150   Dumper.start(Symbol, FunctionDumper::PointerType::None);
151 }
152
153 void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
154   if (Printer.IsSymbolExcluded(Symbol.getName()))
155     return;
156
157   Printer.NewLine();
158   Printer << "label ";
159   WithColor(Printer, PDB_ColorItem::Address).get()
160       << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
161   WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
162 }
163
164 void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
165   if (Printer.IsSymbolExcluded(Symbol.getName()))
166     return;
167
168   Printer.NewLine();
169   Printer << "thunk ";
170   codeview::ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
171   uint64_t VA = Symbol.getVirtualAddress();
172   if (Ordinal == codeview::ThunkOrdinal::TrampIncremental) {
173     uint64_t Target = Symbol.getTargetVirtualAddress();
174     WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
175     Printer << " -> ";
176     WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
177   } else {
178     WithColor(Printer, PDB_ColorItem::Address).get()
179         << "[" << format_hex(VA, 10) << " - "
180         << format_hex(VA + Symbol.getLength(), 10) << "]";
181   }
182   Printer << " (";
183   WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
184   Printer << ") ";
185   std::string Name = Symbol.getName();
186   if (!Name.empty())
187     WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
188 }
189
190 void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
191
192 void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
193   Printer.NewLine();
194   Printer << "unknown (" << Symbol.getSymTag() << ")";
195 }