]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbutil/PrettyCompilandDumper.cpp
MFV r323789: 8473 scrub does not detect errors on active spares
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbutil / PrettyCompilandDumper.cpp
1 //===- PrettyCompilandDumper.cpp - llvm-pdbutil 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-pdbutil.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 (!shouldDumpSymLevel(opts::pretty::SymLevel::Data))
119     return;
120   if (Printer.IsSymbolExcluded(Symbol.getName()))
121     return;
122
123   Printer.NewLine();
124
125   switch (auto LocType = Symbol.getLocationType()) {
126   case PDB_LocType::Static:
127     Printer << "data: ";
128     WithColor(Printer, PDB_ColorItem::Address).get()
129         << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
130
131     WithColor(Printer, PDB_ColorItem::Comment).get()
132         << " [sizeof = " << getTypeLength(Symbol) << "]";
133
134     break;
135   case PDB_LocType::Constant:
136     Printer << "constant: ";
137     WithColor(Printer, PDB_ColorItem::LiteralValue).get()
138         << "[" << Symbol.getValue() << "]";
139     WithColor(Printer, PDB_ColorItem::Comment).get()
140         << " [sizeof = " << getTypeLength(Symbol) << "]";
141     break;
142   default:
143     Printer << "data(unexpected type=" << LocType << ")";
144   }
145
146   Printer << " ";
147   WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
148 }
149
150 void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
151   if (!shouldDumpSymLevel(opts::pretty::SymLevel::Functions))
152     return;
153   if (Symbol.getLength() == 0)
154     return;
155   if (Printer.IsSymbolExcluded(Symbol.getName()))
156     return;
157
158   Printer.NewLine();
159   FunctionDumper Dumper(Printer);
160   Dumper.start(Symbol, FunctionDumper::PointerType::None);
161 }
162
163 void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
164   if (Printer.IsSymbolExcluded(Symbol.getName()))
165     return;
166
167   Printer.NewLine();
168   Printer << "label ";
169   WithColor(Printer, PDB_ColorItem::Address).get()
170       << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
171   WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
172 }
173
174 void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
175   if (!shouldDumpSymLevel(opts::pretty::SymLevel::Thunks))
176     return;
177   if (Printer.IsSymbolExcluded(Symbol.getName()))
178     return;
179
180   Printer.NewLine();
181   Printer << "thunk ";
182   codeview::ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
183   uint64_t VA = Symbol.getVirtualAddress();
184   if (Ordinal == codeview::ThunkOrdinal::TrampIncremental) {
185     uint64_t Target = Symbol.getTargetVirtualAddress();
186     WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
187     Printer << " -> ";
188     WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
189   } else {
190     WithColor(Printer, PDB_ColorItem::Address).get()
191         << "[" << format_hex(VA, 10) << " - "
192         << format_hex(VA + Symbol.getLength(), 10) << "]";
193   }
194   Printer << " (";
195   WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
196   Printer << ") ";
197   std::string Name = Symbol.getName();
198   if (!Name.empty())
199     WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
200 }
201
202 void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
203
204 void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
205   Printer.NewLine();
206   Printer << "unknown (" << Symbol.getSymTag() << ")";
207 }