2017-06-09 22:46:17 +02:00
|
|
|
//===- PrettyCompilandDumper.cpp - llvm-pdbutil compiland dumper -*- C++ *-===//
|
2015-02-22 23:03:38 +01:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-02-22 23:03:38 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-01-11 01:35:43 +01:00
|
|
|
#include "PrettyCompilandDumper.h"
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
#include "LinePrinter.h"
|
2017-01-11 01:35:43 +01:00
|
|
|
#include "PrettyFunctionDumper.h"
|
2017-06-09 22:46:17 +02:00
|
|
|
#include "llvm-pdbutil.h"
|
2015-02-22 23:03:38 +01:00
|
|
|
|
|
|
|
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
|
2016-03-08 22:42:24 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
|
2015-02-22 23:03:38 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSession.h"
|
2016-03-08 22:42:24 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
|
2015-02-22 23:03:38 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBExtras.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbol.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
|
2018-10-11 23:37:18 +02:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h"
|
2015-02-22 23:03:38 +01:00
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
using namespace llvm;
|
2016-05-04 22:32:13 +02:00
|
|
|
using namespace llvm::pdb;
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
CompilandDumper::CompilandDumper(LinePrinter &P)
|
2015-02-27 10:53:55 +01:00
|
|
|
: PDBSymDumper(true), Printer(P) {}
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol) {}
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol) {}
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2016-03-08 22:42:24 +01:00
|
|
|
void CompilandDumper::start(const PDBSymbolCompiland &Symbol,
|
|
|
|
CompilandDumpFlags opts) {
|
2015-02-22 23:03:38 +01:00
|
|
|
std::string FullName = Symbol.getName();
|
2015-03-01 07:49:49 +01:00
|
|
|
if (Printer.IsCompilandExcluded(FullName))
|
|
|
|
return;
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::Path).get() << FullName;
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2016-03-08 22:42:24 +01:00
|
|
|
if (opts & Flags::Lines) {
|
|
|
|
const IPDBSession &Session = Symbol.getSession();
|
2018-03-07 03:23:08 +01:00
|
|
|
if (auto Files = Session.getSourceFilesForCompiland(Symbol)) {
|
2016-03-08 22:42:24 +01:00
|
|
|
Printer.Indent();
|
2018-03-07 03:23:08 +01:00
|
|
|
while (auto File = Files->getNext()) {
|
2016-03-08 22:42:24 +01:00
|
|
|
Printer.NewLine();
|
2018-03-07 03:23:08 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Path).get() << File->getFileName();
|
2018-04-10 16:47:12 +02:00
|
|
|
if (File->getChecksumType() != PDB_Checksum::None) {
|
|
|
|
auto ChecksumType = File->getChecksumType();
|
|
|
|
auto ChecksumHexString = toHex(File->getChecksum());
|
|
|
|
WithColor(Printer, PDB_ColorItem::Comment).get()
|
|
|
|
<< " (" << ChecksumType << ": " << ChecksumHexString << ")";
|
|
|
|
}
|
2018-03-07 03:23:08 +01:00
|
|
|
|
|
|
|
auto Lines = Session.findLineNumbers(Symbol, *File);
|
|
|
|
if (!Lines)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Printer.Indent();
|
|
|
|
while (auto Line = Lines->getNext()) {
|
|
|
|
Printer.NewLine();
|
|
|
|
uint32_t LineStart = Line->getLineNumber();
|
|
|
|
uint32_t LineEnd = Line->getLineNumberEnd();
|
|
|
|
|
|
|
|
Printer << "Line ";
|
|
|
|
PDB_ColorItem StatementColor = Line->isStatement()
|
|
|
|
? PDB_ColorItem::Keyword
|
|
|
|
: PDB_ColorItem::LiteralValue;
|
|
|
|
WithColor(Printer, StatementColor).get() << LineStart;
|
|
|
|
if (LineStart != LineEnd)
|
|
|
|
WithColor(Printer, StatementColor).get() << " - " << LineEnd;
|
|
|
|
|
|
|
|
uint32_t ColumnStart = Line->getColumnNumber();
|
|
|
|
uint32_t ColumnEnd = Line->getColumnNumberEnd();
|
|
|
|
if (ColumnStart != 0 || ColumnEnd != 0) {
|
|
|
|
Printer << ", Column: ";
|
|
|
|
WithColor(Printer, StatementColor).get() << ColumnStart;
|
|
|
|
if (ColumnEnd != ColumnStart)
|
|
|
|
WithColor(Printer, StatementColor).get() << " - " << ColumnEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
Printer << ", Address: ";
|
|
|
|
if (Line->getLength() > 0) {
|
|
|
|
uint64_t AddrStart = Line->getVirtualAddress();
|
|
|
|
uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
|
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get()
|
2016-03-08 22:42:24 +01:00
|
|
|
<< "[" << format_hex(AddrStart, 10) << " - "
|
|
|
|
<< format_hex(AddrEnd, 10) << "]";
|
2018-03-07 03:23:08 +01:00
|
|
|
Printer << " (" << Line->getLength() << " bytes)";
|
|
|
|
} else {
|
|
|
|
uint64_t AddrStart = Line->getVirtualAddress();
|
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get()
|
2016-03-08 22:42:24 +01:00
|
|
|
<< "[" << format_hex(AddrStart, 10) << "] ";
|
2018-03-07 03:23:08 +01:00
|
|
|
Printer << "(0 bytes)";
|
|
|
|
}
|
2016-03-08 22:42:24 +01:00
|
|
|
}
|
2018-03-07 03:23:08 +01:00
|
|
|
Printer.Unindent();
|
2016-03-08 22:42:24 +01:00
|
|
|
}
|
|
|
|
Printer.Unindent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts & Flags::Children) {
|
2018-03-07 03:23:08 +01:00
|
|
|
if (auto ChildrenEnum = Symbol.findAllChildren()) {
|
|
|
|
Printer.Indent();
|
|
|
|
while (auto Child = ChildrenEnum->getNext())
|
|
|
|
Child->dump(*this);
|
|
|
|
Printer.Unindent();
|
|
|
|
}
|
2016-03-08 22:42:24 +01:00
|
|
|
}
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void CompilandDumper::dump(const PDBSymbolData &Symbol) {
|
2017-05-14 03:13:40 +02:00
|
|
|
if (!shouldDumpSymLevel(opts::pretty::SymLevel::Data))
|
|
|
|
return;
|
2015-03-01 07:49:49 +01:00
|
|
|
if (Printer.IsSymbolExcluded(Symbol.getName()))
|
|
|
|
return;
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
|
2015-02-22 23:03:38 +01:00
|
|
|
switch (auto LocType = Symbol.getLocationType()) {
|
|
|
|
case PDB_LocType::Static:
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "data: ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get()
|
2015-05-01 22:24:26 +02:00
|
|
|
<< "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
|
2017-05-14 03:13:40 +02:00
|
|
|
|
|
|
|
WithColor(Printer, PDB_ColorItem::Comment).get()
|
|
|
|
<< " [sizeof = " << getTypeLength(Symbol) << "]";
|
|
|
|
|
2015-02-22 23:03:38 +01:00
|
|
|
break;
|
|
|
|
case PDB_LocType::Constant:
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "constant: ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::LiteralValue).get()
|
|
|
|
<< "[" << Symbol.getValue() << "]";
|
2017-05-14 03:13:40 +02:00
|
|
|
WithColor(Printer, PDB_ColorItem::Comment).get()
|
|
|
|
<< " [sizeof = " << getTypeLength(Symbol) << "]";
|
2015-02-22 23:03:38 +01:00
|
|
|
break;
|
|
|
|
default:
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "data(unexpected type=" << LocType << ")";
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << " ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
|
2017-05-14 03:13:40 +02:00
|
|
|
if (!shouldDumpSymLevel(opts::pretty::SymLevel::Functions))
|
|
|
|
return;
|
2015-02-23 06:58:34 +01:00
|
|
|
if (Symbol.getLength() == 0)
|
|
|
|
return;
|
2015-03-01 07:49:49 +01:00
|
|
|
if (Printer.IsSymbolExcluded(Symbol.getName()))
|
|
|
|
return;
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
FunctionDumper Dumper(Printer);
|
2015-03-01 07:51:29 +01:00
|
|
|
Dumper.start(Symbol, FunctionDumper::PointerType::None);
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
|
2015-03-01 07:49:49 +01:00
|
|
|
if (Printer.IsSymbolExcluded(Symbol.getName()))
|
|
|
|
return;
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "label ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get()
|
2015-05-01 22:24:26 +02:00
|
|
|
<< "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
|
2017-05-14 03:13:40 +02:00
|
|
|
if (!shouldDumpSymLevel(opts::pretty::SymLevel::Thunks))
|
|
|
|
return;
|
2015-03-01 07:49:49 +01:00
|
|
|
if (Printer.IsSymbolExcluded(Symbol.getName()))
|
|
|
|
return;
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "thunk ";
|
2016-05-25 00:58:46 +02:00
|
|
|
codeview::ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
|
2015-05-01 22:24:26 +02:00
|
|
|
uint64_t VA = Symbol.getVirtualAddress();
|
2016-05-25 00:58:46 +02:00
|
|
|
if (Ordinal == codeview::ThunkOrdinal::TrampIncremental) {
|
2015-05-01 22:24:26 +02:00
|
|
|
uint64_t Target = Symbol.getTargetVirtualAddress();
|
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << " -> ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
|
2015-02-22 23:03:38 +01:00
|
|
|
} else {
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get()
|
2015-05-01 22:24:26 +02:00
|
|
|
<< "[" << format_hex(VA, 10) << " - "
|
|
|
|
<< format_hex(VA + Symbol.getLength(), 10) << "]";
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
2015-03-02 05:39:56 +01:00
|
|
|
Printer << " (";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
|
|
|
|
Printer << ") ";
|
2015-02-22 23:03:38 +01:00
|
|
|
std::string Name = Symbol.getName();
|
|
|
|
if (!Name.empty())
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "unknown (" << Symbol.getSymTag() << ")";
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
2018-10-11 23:37:18 +02:00
|
|
|
|
|
|
|
void CompilandDumper::dump(const PDBSymbolUsingNamespace &Symbol) {
|
|
|
|
if (Printer.IsSymbolExcluded(Symbol.getName()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "using namespace ";
|
|
|
|
std::string Name = Symbol.getName();
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
|
|
|
|
}
|