2015-02-23 05:58:34 +00:00
|
|
|
//===- VariableDumper.cpp - -------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "VariableDumper.h"
|
|
|
|
|
2015-02-26 23:49:23 +00:00
|
|
|
#include "BuiltinDumper.h"
|
2015-02-27 09:15:59 +00:00
|
|
|
#include "LinePrinter.h"
|
2015-02-23 05:58:34 +00:00
|
|
|
#include "llvm-pdbdump.h"
|
|
|
|
#include "FunctionDumper.h"
|
|
|
|
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
|
2015-03-04 06:09:53 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
|
2015-02-26 23:49:23 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
|
2015-02-23 05:58:34 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
|
|
|
|
|
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2015-02-27 09:15:59 +00:00
|
|
|
VariableDumper::VariableDumper(LinePrinter &P)
|
|
|
|
: PDBSymDumper(true), Printer(P) {}
|
2015-02-23 05:58:34 +00:00
|
|
|
|
2015-03-01 06:51:29 +00:00
|
|
|
void VariableDumper::start(const PDBSymbolData &Var) {
|
2015-03-02 04:39:56 +00:00
|
|
|
if (Var.isCompilerGenerated() && opts::ExcludeCompilerGenerated)
|
|
|
|
return;
|
2015-03-01 06:49:49 +00:00
|
|
|
if (Printer.IsSymbolExcluded(Var.getName()))
|
|
|
|
return;
|
|
|
|
|
2015-02-23 05:58:34 +00:00
|
|
|
auto VarType = Var.getType();
|
|
|
|
|
|
|
|
switch (auto LocType = Var.getLocationType()) {
|
|
|
|
case PDB_LocType::Static:
|
2015-03-04 06:09:53 +00:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "data [";
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get()
|
2015-05-01 20:24:26 +00:00
|
|
|
<< format_hex(Var.getVirtualAddress(), 10);
|
2015-03-02 04:39:56 +00:00
|
|
|
Printer << "] ";
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "static ";
|
2015-03-01 06:51:29 +00:00
|
|
|
dumpSymbolTypeAndName(*VarType, Var.getName());
|
2015-02-23 05:58:34 +00:00
|
|
|
break;
|
|
|
|
case PDB_LocType::Constant:
|
2015-03-04 06:09:53 +00:00
|
|
|
if (isa<PDBSymbolTypeEnum>(*VarType))
|
|
|
|
break;
|
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "data ";
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
|
2015-03-01 06:51:29 +00:00
|
|
|
dumpSymbolTypeAndName(*VarType, Var.getName());
|
2015-03-02 04:39:56 +00:00
|
|
|
Printer << " = ";
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Var.getValue();
|
2015-02-23 05:58:34 +00:00
|
|
|
break;
|
2015-02-23 11:33:54 +00:00
|
|
|
case PDB_LocType::ThisRel:
|
2015-03-04 06:09:53 +00:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "data ";
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
|
|
|
<< "+" << format_hex(Var.getOffset(), 4) << " ";
|
2015-03-01 06:51:29 +00:00
|
|
|
dumpSymbolTypeAndName(*VarType, Var.getName());
|
2015-02-23 05:58:34 +00:00
|
|
|
break;
|
2015-03-02 04:39:56 +00:00
|
|
|
case PDB_LocType::BitField:
|
2015-03-04 06:09:53 +00:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "data ";
|
2015-03-02 04:39:56 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
|
|
|
<< "+" << format_hex(Var.getOffset(), 4) << " ";
|
|
|
|
dumpSymbolTypeAndName(*VarType, Var.getName());
|
|
|
|
Printer << " : ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Var.getLength();
|
|
|
|
break;
|
2015-02-23 05:58:34 +00:00
|
|
|
default:
|
2015-03-04 06:09:53 +00:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "data ";
|
2015-03-01 06:51:29 +00:00
|
|
|
Printer << "unknown(" << LocType << ") ";
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Var.getName();
|
2015-02-23 05:58:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-01 06:51:29 +00:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeBuiltin &Symbol) {
|
2015-02-27 09:15:59 +00:00
|
|
|
BuiltinDumper Dumper(Printer);
|
2015-03-01 06:51:29 +00:00
|
|
|
Dumper.start(Symbol);
|
2015-02-23 05:58:34 +00:00
|
|
|
}
|
|
|
|
|
2015-03-01 06:51:29 +00:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeEnum &Symbol) {
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-23 05:58:34 +00:00
|
|
|
}
|
|
|
|
|
2015-03-01 06:51:29 +00:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeFunctionSig &Symbol) {}
|
2015-02-23 05:58:34 +00:00
|
|
|
|
2015-03-01 06:51:29 +00:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypePointer &Symbol) {
|
2015-02-23 05:58:34 +00:00
|
|
|
auto PointeeType = Symbol.getPointeeType();
|
|
|
|
if (!PointeeType)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (auto Func = dyn_cast<PDBSymbolFunc>(PointeeType.get())) {
|
2015-02-27 09:15:59 +00:00
|
|
|
FunctionDumper NestedDumper(Printer);
|
2015-02-23 05:58:34 +00:00
|
|
|
FunctionDumper::PointerType Pointer =
|
|
|
|
Symbol.isReference() ? FunctionDumper::PointerType::Reference
|
|
|
|
: FunctionDumper::PointerType::Pointer;
|
2015-03-01 06:51:29 +00:00
|
|
|
NestedDumper.start(*Func, Pointer);
|
2015-02-23 05:58:34 +00:00
|
|
|
} else {
|
|
|
|
if (Symbol.isConstType())
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
|
2015-02-23 05:58:34 +00:00
|
|
|
if (Symbol.isVolatileType())
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
|
2015-03-01 06:51:29 +00:00
|
|
|
PointeeType->dump(*this);
|
2015-02-27 09:15:59 +00:00
|
|
|
Printer << (Symbol.isReference() ? "&" : "*");
|
2015-02-23 05:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-01 06:51:29 +00:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "typedef ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-23 05:58:34 +00:00
|
|
|
}
|
|
|
|
|
2015-03-01 06:51:29 +00:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeUDT &Symbol) {
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-23 05:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VariableDumper::dumpSymbolTypeAndName(const PDBSymbol &Type,
|
2015-03-01 06:51:29 +00:00
|
|
|
StringRef Name) {
|
2015-02-23 05:58:34 +00:00
|
|
|
if (auto *ArrayType = dyn_cast<PDBSymbolTypeArray>(&Type)) {
|
|
|
|
std::string IndexSpec;
|
|
|
|
raw_string_ostream IndexStream(IndexSpec);
|
|
|
|
std::unique_ptr<PDBSymbol> ElementType = ArrayType->getElementType();
|
|
|
|
while (auto NestedArray = dyn_cast<PDBSymbolTypeArray>(ElementType.get())) {
|
2015-02-27 09:15:59 +00:00
|
|
|
IndexStream << "[";
|
|
|
|
IndexStream << NestedArray->getCount();
|
|
|
|
IndexStream << "]";
|
2015-02-23 05:58:34 +00:00
|
|
|
ElementType = NestedArray->getElementType();
|
|
|
|
}
|
|
|
|
IndexStream << "[" << ArrayType->getCount() << "]";
|
2015-03-01 06:51:29 +00:00
|
|
|
ElementType->dump(*this);
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << " " << Name;
|
|
|
|
Printer << IndexStream.str();
|
2015-02-23 05:58:34 +00:00
|
|
|
} else {
|
2015-03-01 06:51:29 +00:00
|
|
|
if (!tryDumpFunctionPointer(Type, Name)) {
|
|
|
|
Type.dump(*this);
|
2015-02-27 09:15:59 +00:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << " " << Name;
|
2015-02-26 23:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VariableDumper::tryDumpFunctionPointer(const PDBSymbol &Type,
|
2015-03-01 06:51:29 +00:00
|
|
|
StringRef Name) {
|
2015-02-26 23:49:23 +00:00
|
|
|
// Function pointers come across as pointers to function signatures. But the
|
|
|
|
// signature carries no name, so we have to handle this case separately.
|
|
|
|
if (auto *PointerType = dyn_cast<PDBSymbolTypePointer>(&Type)) {
|
|
|
|
auto PointeeType = PointerType->getPointeeType();
|
|
|
|
if (auto *FunctionSig =
|
|
|
|
dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType.get())) {
|
2015-02-27 09:15:59 +00:00
|
|
|
FunctionDumper Dumper(Printer);
|
2015-02-26 23:49:23 +00:00
|
|
|
FunctionDumper::PointerType PT = FunctionDumper::PointerType::Pointer;
|
|
|
|
if (PointerType->isReference())
|
|
|
|
PT = FunctionDumper::PointerType::Reference;
|
|
|
|
std::string NameStr(Name.begin(), Name.end());
|
2015-03-01 06:51:29 +00:00
|
|
|
Dumper.start(*FunctionSig, NameStr.c_str(), PT);
|
2015-02-26 23:49:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-02-23 05:58:34 +00:00
|
|
|
}
|
2015-02-26 23:49:23 +00:00
|
|
|
return false;
|
2015-02-23 05:58:34 +00:00
|
|
|
}
|