[llvm-pdbutil] Move InputFile/FormatUtil/LinePrinter to PDB library.

At Sony we are developing llvm-dva

https://lists.llvm.org/pipermail/llvm-dev/2020-August/144174.html

For its PDB support, it requires functionality already present in
llvm-pdbutil.

We intend to move that functionaly into the PDB library to be
shared by both tools. That change will be done in 2 steps, that
will be submitted as 2 patches:

(1) Replace 'ExitOnError' with explicit error handling.
(2) Move the intended shared code to the PDB library.

Patch for step (1): https://reviews.llvm.org/D121801

This patch is for step (2).

Move InputFile.cpp[h], FormatUtil.cpp[h] and LinePrinter.cpp[h]
files to the debug PDB library.

It exposes the following functionality that can be used by tools:

- Open a PDB file.
- Get module debug stream.
- Traverse module sections.
- Traverse module subsections.

Most of the needed functionality is in InputFile, but there are
dependencies from LinePrinter and FormatUtil.

Some other functionality is in the following functions in
DumpOutputStyle.cpp file:

- iterateModuleSubsections
- getModuleDebugStream
- iterateOneModule
- iterateSymbolGroups
- iterateModuleSubsections

Only these specific functions from DumpOutputStyle are moved to
the PDB library.

Reviewed By: aganea, dblaikie, rnk

Differential Revision: https://reviews.llvm.org/D122226
This commit is contained in:
Carlos Alberto Enciso 2022-03-24 16:33:08 +00:00
parent 50354558a7
commit 75112133b8
31 changed files with 290 additions and 202 deletions

View File

@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVMPDBUTIL_FORMAT_UTIL_H
#define LLVM_TOOLS_LLVMPDBUTIL_FORMAT_UTIL_H
#ifndef LLVM_DEBUGINFO_PDB_NATIVE_FORMATUTIL_H
#define LLVM_DEBUGINFO_PDB_NATIVE_FORMATUTIL_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
@ -136,6 +136,6 @@ fmtle(support::detail::packed_endian_specific_integral<T, support::little,
Value) {
return detail::EndianAdapter<T>(std::move(Value));
}
}
} // namespace pdb
} // namespace llvm
#endif

View File

@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVMPDBDUMP_INPUTFILE_H
#define LLVM_TOOLS_LLVMPDBDUMP_INPUTFILE_H
#ifndef LLVM_DEBUGINFO_PDB_NATIVE_INPUTFILE_H
#define LLVM_DEBUGINFO_PDB_NATIVE_INPUTFILE_H
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/PointerUnion.h"
@ -15,6 +15,7 @@
#include "llvm/ADT/iterator.h"
#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/ObjectFile.h"
@ -54,6 +55,9 @@ class InputFile {
getOrCreateTypeCollection(TypeCollectionKind Kind);
public:
InputFile(PDBFile *Pdb) { PdbOrObj = Pdb; }
InputFile(object::COFFObjectFile *Obj) { PdbOrObj = Obj; }
InputFile(MemoryBuffer *Buffer) { PdbOrObj = Buffer; }
~InputFile();
InputFile(InputFile &&Other) = default;
@ -91,6 +95,7 @@ public:
explicit SymbolGroup(InputFile *File, uint32_t GroupIndex = 0);
Expected<StringRef> getNameFromStringTable(uint32_t Offset) const;
Expected<StringRef> getNameFromChecksums(uint32_t Offset) const;
void formatFromFileName(LinePrinter &Printer, StringRef File,
bool Append = false) const;
@ -148,6 +153,80 @@ private:
SymbolGroup Value;
};
Expected<ModuleDebugStreamRef>
getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index);
Expected<ModuleDebugStreamRef> getModuleDebugStream(PDBFile &File,
uint32_t Index);
bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group);
// TODO: Change these callbacks to be function_refs (de-templatify them).
template <typename CallbackT>
Error iterateOneModule(InputFile &File, const Optional<PrintScope> &HeaderScope,
const SymbolGroup &SG, uint32_t Modi,
CallbackT Callback) {
if (HeaderScope) {
HeaderScope->P.formatLine(
"Mod {0:4} | `{1}`: ",
fmt_align(Modi, AlignStyle::Right, HeaderScope->LabelWidth), SG.name());
}
AutoIndent Indent(HeaderScope);
return Callback(Modi, SG);
}
template <typename CallbackT>
Error iterateSymbolGroups(InputFile &Input,
const Optional<PrintScope> &HeaderScope,
CallbackT Callback) {
AutoIndent Indent(HeaderScope);
if (llvm::pdb::Filters.DumpModi > 0) {
assert(llvm::pdb::Filters.DumpModi == 1);
uint32_t Modi = llvm::pdb::Filters.DumpModi;
SymbolGroup SG(&Input, Modi);
return iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)),
SG, Modi, Callback);
}
uint32_t I = 0;
for (const auto &SG : Input.symbol_groups()) {
if (shouldDumpSymbolGroup(I, SG))
if (auto Err =
iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(I)),
SG, I, Callback))
return Err;
++I;
}
return Error::success();
}
template <typename SubsectionT>
Error iterateModuleSubsections(
InputFile &File, const Optional<PrintScope> &HeaderScope,
llvm::function_ref<Error(uint32_t, const SymbolGroup &, SubsectionT &)>
Callback) {
return iterateSymbolGroups(
File, HeaderScope, [&](uint32_t Modi, const SymbolGroup &SG) -> Error {
for (const auto &SS : SG.getDebugSubsections()) {
SubsectionT Subsection;
if (SS.kind() != Subsection.kind())
continue;
BinaryStreamReader Reader(SS.getRecordData());
if (auto Err = Subsection.initialize(Reader))
continue;
if (auto Err = Callback(Modi, SG, Subsection))
return Err;
}
return Error::success();
});
}
} // namespace pdb
} // namespace llvm

View File

@ -6,12 +6,13 @@
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
#define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
#ifndef LLVM_DEBUGINFO_PDB_NATIVE_LINEPRINTER_H
#define LLVM_DEBUGINFO_PDB_NATIVE_LINEPRINTER_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
#include "llvm/Support/BinaryStreamRef.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Regex.h"
@ -19,12 +20,28 @@
#include <list>
// Container for filter options to control which elements will be printed.
struct FilterOptions {
std::list<std::string> ExcludeTypes;
std::list<std::string> ExcludeSymbols;
std::list<std::string> ExcludeCompilands;
std::list<std::string> IncludeTypes;
std::list<std::string> IncludeSymbols;
std::list<std::string> IncludeCompilands;
uint32_t PaddingThreshold;
uint32_t SizeThreshold;
uint32_t DumpModi;
bool JustMyCode;
};
namespace llvm {
namespace msf {
class MSFStreamLayout;
} // namespace msf
namespace pdb {
extern FilterOptions Filters;
class ClassLayout;
class PDBFile;
@ -32,7 +49,8 @@ class LinePrinter {
friend class WithColor;
public:
LinePrinter(int Indent, bool UseColor, raw_ostream &Stream);
LinePrinter(int Indent, bool UseColor, raw_ostream &Stream,
FilterOptions &Filters);
void Indent(uint32_t Amount = 0);
void Unindent(uint32_t Amount = 0);
@ -40,10 +58,10 @@ public:
void printLine(const Twine &T);
void print(const Twine &T);
template <typename... Ts> void formatLine(const char *Fmt, Ts &&... Items) {
template <typename... Ts> void formatLine(const char *Fmt, Ts &&...Items) {
printLine(formatv(Fmt, std::forward<Ts>(Items)...));
}
template <typename... Ts> void format(const char *Fmt, Ts &&... Items) {
template <typename... Ts> void format(const char *Fmt, Ts &&...Items) {
print(formatv(Fmt, std::forward<Ts>(Items)...));
}
@ -161,7 +179,7 @@ private:
raw_ostream &OS;
bool UseColor;
};
}
}
} // namespace pdb
} // namespace llvm
#endif

View File

@ -47,12 +47,15 @@ add_pdb_impl_folder(Native
Native/DbiStream.cpp
Native/DbiStreamBuilder.cpp
Native/EnumTables.cpp
Native/FormatUtil.cpp
Native/GlobalsStream.cpp
Native/Hash.cpp
Native/HashTable.cpp
Native/InfoStream.cpp
Native/InfoStreamBuilder.cpp
Native/InjectedSourceStream.cpp
Native/InputFile.cpp
Native/LinePrinter.cpp
Native/ModuleDebugStream.cpp
Native/NativeCompilandSymbol.cpp
Native/NativeEnumGlobals.cpp

View File

@ -6,7 +6,8 @@
//
//===----------------------------------------------------------------------===//
#include "FormatUtil.h"
#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/BinaryFormat/COFF.h"

View File

@ -6,10 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "InputFile.h"
#include "FormatUtil.h"
#include "LinePrinter.h"
#include "llvm/DebugInfo/PDB/Native/InputFile.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/DebugInfo/CodeView/CodeView.h"
@ -17,6 +14,8 @@
#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
@ -35,8 +34,9 @@ using namespace llvm::pdb;
InputFile::InputFile() {}
InputFile::~InputFile() {}
static Expected<ModuleDebugStreamRef>
getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index) {
Expected<ModuleDebugStreamRef>
llvm::pdb::getModuleDebugStream(PDBFile &File, StringRef &ModuleName,
uint32_t Index) {
Expected<DbiStream &> DbiOrErr = File.getPDBDbiStream();
if (!DbiOrErr)
return DbiOrErr.takeError();
@ -65,6 +65,30 @@ getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index) {
return std::move(ModS);
}
Expected<ModuleDebugStreamRef> llvm::pdb::getModuleDebugStream(PDBFile &File,
uint32_t Index) {
Expected<DbiStream &> DbiOrErr = File.getPDBDbiStream();
if (!DbiOrErr)
return DbiOrErr.takeError();
DbiStream &Dbi = *DbiOrErr;
const auto &Modules = Dbi.modules();
auto Modi = Modules.getModuleDescriptor(Index);
uint16_t ModiStream = Modi.getModuleStreamIndex();
if (ModiStream == kInvalidStreamIndex)
return make_error<RawError>(raw_error_code::no_stream,
"Module stream not present");
auto ModStreamData = File.createIndexedStream(ModiStream);
ModuleDebugStreamRef ModS(Modi, std::move(ModStreamData));
if (Error Err = ModS.reload())
return make_error<RawError>(raw_error_code::corrupt_file,
"Invalid module stream");
return std::move(ModS);
}
static inline bool isCodeViewDebugSubsection(object::SectionRef Section,
StringRef Name,
BinaryStreamReader &Reader) {
@ -122,7 +146,7 @@ static std::string formatChecksumKind(FileChecksumKind Kind) {
}
template <typename... Args>
static void formatInternal(LinePrinter &Printer, bool Append, Args &&... args) {
static void formatInternal(LinePrinter &Printer, bool Append, Args &&...args) {
if (Append)
Printer.format(std::forward<Args>(args)...);
else
@ -211,6 +235,26 @@ Expected<StringRef> SymbolGroup::getNameFromStringTable(uint32_t Offset) const {
return SC.strings().getString(Offset);
}
Expected<StringRef> SymbolGroup::getNameFromChecksums(uint32_t Offset) const {
StringRef Name;
if (!SC.hasChecksums()) {
return std::move(Name);
}
auto Iter = SC.checksums().getArray().at(Offset);
if (Iter == SC.checksums().getArray().end()) {
return std::move(Name);
}
uint32_t FO = Iter->FileNameOffset;
auto ExpectedFile = getNameFromStringTable(FO);
if (!ExpectedFile) {
return std::move(Name);
}
return *ExpectedFile;
}
void SymbolGroup::formatFromFileName(LinePrinter &Printer, StringRef File,
bool Append) const {
auto FC = ChecksumsByFile.find(File);
@ -510,3 +554,33 @@ bool SymbolGroupIterator::isEnd() const {
assert(SectionIter.hasValue());
return *SectionIter == Value.File->obj().section_end();
}
static bool isMyCode(const SymbolGroup &Group) {
if (Group.getFile().isObj())
return true;
StringRef Name = Group.name();
if (Name.startswith("Import:"))
return false;
if (Name.endswith_insensitive(".dll"))
return false;
if (Name.equals_insensitive("* linker *"))
return false;
if (Name.startswith_insensitive("f:\\binaries\\Intermediate\\vctools"))
return false;
if (Name.startswith_insensitive("f:\\dd\\vctools\\crt"))
return false;
return true;
}
bool llvm::pdb::shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group) {
if (llvm::pdb::Filters.JustMyCode && !isMyCode(Group))
return false;
// If the arg was not specified on the command line, always dump all modules.
if (llvm::pdb::Filters.DumpModi == 0)
return true;
// Otherwise, only dump if this is the same module specified.
return (llvm::pdb::Filters.DumpModi == Idx);
}

View File

@ -6,16 +6,18 @@
//
//===----------------------------------------------------------------------===//
#include "LinePrinter.h"
#include "llvm-pdbutil.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
#include "llvm/DebugInfo/MSF/MSFCommon.h"
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
#include "llvm/DebugInfo/PDB/Native/InputFile.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/UDTLayout.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/FormatAdapters.h"
@ -28,6 +30,10 @@ using namespace llvm;
using namespace llvm::msf;
using namespace llvm::pdb;
// TODO: Move this Filters state inside the LinePrinter class and pass it by
// reference to the iterate* functions.
FilterOptions llvm::pdb::Filters;
namespace {
bool IsItemExcluded(llvm::StringRef Item,
std::list<llvm::Regex> &IncludeFilters,
@ -47,25 +53,27 @@ bool IsItemExcluded(llvm::StringRef Item,
return false;
}
}
} // namespace
using namespace llvm;
LinePrinter::LinePrinter(int Indent, bool UseColor, llvm::raw_ostream &Stream)
LinePrinter::LinePrinter(int Indent, bool UseColor, llvm::raw_ostream &Stream,
FilterOptions &Filters)
: OS(Stream), IndentSpaces(Indent), CurrentIndent(0), UseColor(UseColor) {
SetFilters(ExcludeTypeFilters, opts::pretty::ExcludeTypes.begin(),
opts::pretty::ExcludeTypes.end());
SetFilters(ExcludeSymbolFilters, opts::pretty::ExcludeSymbols.begin(),
opts::pretty::ExcludeSymbols.end());
SetFilters(ExcludeCompilandFilters, opts::pretty::ExcludeCompilands.begin(),
opts::pretty::ExcludeCompilands.end());
llvm::pdb::Filters = Filters;
SetFilters(ExcludeTypeFilters, Filters.ExcludeTypes.begin(),
Filters.ExcludeTypes.end());
SetFilters(ExcludeSymbolFilters, Filters.ExcludeSymbols.begin(),
Filters.ExcludeSymbols.end());
SetFilters(ExcludeCompilandFilters, Filters.ExcludeCompilands.begin(),
Filters.ExcludeCompilands.end());
SetFilters(IncludeTypeFilters, opts::pretty::IncludeTypes.begin(),
opts::pretty::IncludeTypes.end());
SetFilters(IncludeSymbolFilters, opts::pretty::IncludeSymbols.begin(),
opts::pretty::IncludeSymbols.end());
SetFilters(IncludeCompilandFilters, opts::pretty::IncludeCompilands.begin(),
opts::pretty::IncludeCompilands.end());
SetFilters(IncludeTypeFilters, Filters.IncludeTypes.begin(),
Filters.IncludeTypes.end());
SetFilters(IncludeSymbolFilters, Filters.IncludeSymbols.begin(),
Filters.IncludeSymbols.end());
SetFilters(IncludeCompilandFilters, Filters.IncludeCompilands.begin(),
Filters.IncludeCompilands.end());
}
void LinePrinter::Indent(uint32_t Amount) {
@ -95,7 +103,7 @@ void LinePrinter::printLine(const Twine &T) {
bool LinePrinter::IsClassExcluded(const ClassLayout &Class) {
if (IsTypeExcluded(Class.getName(), Class.getSize()))
return true;
if (Class.deepPaddingSize() < opts::pretty::PaddingThreshold)
if (Class.deepPaddingSize() < Filters.PaddingThreshold)
return true;
return false;
}
@ -273,7 +281,7 @@ void LinePrinter::formatMsfStreamBlocks(
bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName, uint64_t Size) {
if (IsItemExcluded(TypeName, IncludeTypeFilters, ExcludeTypeFilters))
return true;
if (Size < opts::pretty::SizeThreshold)
if (Size < Filters.SizeThreshold)
return true;
return false;
}

View File

@ -8,7 +8,6 @@
#include "BytesOutputStyle.h"
#include "FormatUtil.h"
#include "StreamUtil.h"
#include "llvm-pdbutil.h"
@ -17,6 +16,7 @@
#include "llvm/DebugInfo/MSF/MSFCommon.h"
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
@ -83,7 +83,7 @@ static void printHeader(LinePrinter &P, const Twine &S) {
}
BytesOutputStyle::BytesOutputStyle(PDBFile &File)
: File(File), P(2, false, outs()) {}
: File(File), P(2, false, outs(), opts::Filters) {}
Error BytesOutputStyle::dump() {

View File

@ -9,10 +9,10 @@
#ifndef LLVM_TOOLS_LLVMPDBDUMP_BYTESOUTPUTSTYLE_H
#define LLVM_TOOLS_LLVMPDBDUMP_BYTESOUTPUTSTYLE_H
#include "LinePrinter.h"
#include "OutputStyle.h"
#include "StreamUtil.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include "llvm/Support/Error.h"
namespace llvm {

View File

@ -12,10 +12,7 @@ add_llvm_tool(llvm-pdbutil
BytesOutputStyle.cpp
DumpOutputStyle.cpp
ExplainOutputStyle.cpp
InputFile.cpp
llvm-pdbutil.cpp
FormatUtil.cpp
LinePrinter.cpp
MinimalSymbolDumper.cpp
MinimalTypeDumper.cpp
PdbYaml.cpp

View File

@ -8,8 +8,6 @@
#include "DumpOutputStyle.h"
#include "FormatUtil.h"
#include "InputFile.h"
#include "MinimalSymbolDumper.h"
#include "MinimalTypeDumper.h"
#include "StreamUtil.h"
@ -38,10 +36,13 @@
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
#include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h"
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
#include "llvm/DebugInfo/PDB/Native/InputFile.h"
#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
#include "llvm/DebugInfo/PDB/Native/RawError.h"
@ -61,7 +62,7 @@ using namespace llvm::msf;
using namespace llvm::pdb;
DumpOutputStyle::DumpOutputStyle(InputFile &File)
: File(File), P(2, false, outs()) {
: File(File), P(2, false, outs(), opts::Filters) {
if (opts::dump::DumpTypeRefStats)
RefTracker.reset(new TypeReferenceTracker(File));
}
@ -342,36 +343,6 @@ static void printModuleDetailStats(LinePrinter &P, StringRef Label,
}
}
static bool isMyCode(const SymbolGroup &Group) {
if (Group.getFile().isObj())
return true;
StringRef Name = Group.name();
if (Name.startswith("Import:"))
return false;
if (Name.endswith_insensitive(".dll"))
return false;
if (Name.equals_insensitive("* linker *"))
return false;
if (Name.startswith_insensitive("f:\\binaries\\Intermediate\\vctools"))
return false;
if (Name.startswith_insensitive("f:\\dd\\vctools\\crt"))
return false;
return true;
}
static bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group) {
if (opts::dump::JustMyCode && !isMyCode(Group))
return false;
// If the arg was not specified on the command line, always dump all modules.
if (opts::dump::DumpModi.getNumOccurrences() == 0)
return true;
// Otherwise, only dump if this is the same module specified.
return (opts::dump::DumpModi == Idx);
}
Error DumpOutputStyle::dumpStreamSummary() {
printHeader(P, "Streams");
@ -408,96 +379,6 @@ Error DumpOutputStyle::dumpStreamSummary() {
return Error::success();
}
static Expected<ModuleDebugStreamRef> getModuleDebugStream(PDBFile &File,
uint32_t Index) {
Expected<DbiStream &> DbiOrErr = File.getPDBDbiStream();
if (!DbiOrErr)
return DbiOrErr.takeError();
DbiStream &Dbi = *DbiOrErr;
const auto &Modules = Dbi.modules();
auto Modi = Modules.getModuleDescriptor(Index);
uint16_t ModiStream = Modi.getModuleStreamIndex();
if (ModiStream == kInvalidStreamIndex)
return make_error<RawError>(raw_error_code::no_stream,
"Module stream not present");
auto ModStreamData = File.createIndexedStream(ModiStream);
ModuleDebugStreamRef ModS(Modi, std::move(ModStreamData));
if (auto EC = ModS.reload())
return make_error<RawError>(raw_error_code::corrupt_file,
"Invalid module stream");
return std::move(ModS);
}
template <typename CallbackT>
static Error
iterateOneModule(InputFile &File, const Optional<PrintScope> &HeaderScope,
const SymbolGroup &SG, uint32_t Modi, CallbackT Callback) {
if (HeaderScope) {
HeaderScope->P.formatLine(
"Mod {0:4} | `{1}`: ",
fmt_align(Modi, AlignStyle::Right, HeaderScope->LabelWidth), SG.name());
}
AutoIndent Indent(HeaderScope);
return Callback(Modi, SG);
}
template <typename CallbackT>
static Error iterateSymbolGroups(InputFile &Input,
const Optional<PrintScope> &HeaderScope,
CallbackT Callback) {
AutoIndent Indent(HeaderScope);
if (opts::dump::DumpModi.getNumOccurrences() > 0) {
assert(opts::dump::DumpModi.getNumOccurrences() == 1);
uint32_t Modi = opts::dump::DumpModi;
SymbolGroup SG(&Input, Modi);
return iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)),
SG, Modi, Callback);
}
uint32_t I = 0;
for (const auto &SG : Input.symbol_groups()) {
if (shouldDumpSymbolGroup(I, SG))
if (auto Err =
iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(I)),
SG, I, Callback))
return Err;
++I;
}
return Error::success();
}
template <typename SubsectionT>
static Error iterateModuleSubsections(
InputFile &File, const Optional<PrintScope> &HeaderScope,
llvm::function_ref<Error(uint32_t, const SymbolGroup &, SubsectionT &)>
Callback) {
return iterateSymbolGroups(
File, HeaderScope, [&](uint32_t Modi, const SymbolGroup &SG) -> Error {
for (const auto &SS : SG.getDebugSubsections()) {
SubsectionT Subsection;
if (SS.kind() != Subsection.kind())
continue;
BinaryStreamReader Reader(SS.getRecordData());
if (auto Err = Subsection.initialize(Reader))
continue;
if (auto Err = Callback(Modi, SG, Subsection))
return Err;
}
return Error::success();
});
}
static Expected<std::pair<std::unique_ptr<MappedBlockStream>,
ArrayRef<llvm::object::coff_section>>>
loadSectionHeaders(PDBFile &File, DbgHeaderType Type) {

View File

@ -9,13 +9,13 @@
#ifndef LLVM_TOOLS_LLVMPDBDUMP_DUMPOUTPUTSTYLE_H
#define LLVM_TOOLS_LLVMPDBDUMP_DUMPOUTPUTSTYLE_H
#include "LinePrinter.h"
#include "OutputStyle.h"
#include "StreamUtil.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
#include <string>

View File

@ -8,17 +8,20 @@
#include "ExplainOutputStyle.h"
#include "FormatUtil.h"
#include "InputFile.h"
#include "StreamUtil.h"
#include "llvm-pdbutil.h"
#include "llvm/DebugInfo/CodeView/Formatters.h"
#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
#include "llvm/DebugInfo/PDB/Native/InputFile.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/BinaryByteStream.h"
#include "llvm/Support/BinaryStreamArray.h"
#include "llvm/Support/Error.h"
@ -29,7 +32,7 @@ using namespace llvm::msf;
using namespace llvm::pdb;
ExplainOutputStyle::ExplainOutputStyle(InputFile &File, uint64_t FileOffset)
: File(File), FileOffset(FileOffset), P(2, false, outs()) {}
: File(File), FileOffset(FileOffset), P(2, false, outs(), opts::Filters) {}
Error ExplainOutputStyle::dump() {
P.formatLine("Explaining file offset {0} of file '{1}'.", FileOffset,

View File

@ -9,9 +9,10 @@
#ifndef LLVM_TOOLS_LLVMPDBDUMP_EXPLAINOUTPUTSTYLE_H
#define LLVM_TOOLS_LLVMPDBDUMP_EXPLAINOUTPUTSTYLE_H
#include "LinePrinter.h"
#include "OutputStyle.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include <string>
namespace llvm {

View File

@ -8,17 +8,19 @@
#include "MinimalSymbolDumper.h"
#include "FormatUtil.h"
#include "InputFile.h"
#include "LinePrinter.h"
#include "llvm/DebugInfo/CodeView/CVRecord.h"
#include "llvm/DebugInfo/CodeView/CodeView.h"
#include "llvm/DebugInfo/CodeView/Formatters.h"
#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
#include "llvm/DebugInfo/PDB/Native/InputFile.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/FormatVariadic.h"
using namespace llvm;

View File

@ -8,8 +8,6 @@
#include "MinimalTypeDumper.h"
#include "FormatUtil.h"
#include "LinePrinter.h"
#include "TypeReferenceTracker.h"
#include "llvm-pdbutil.h"
@ -19,8 +17,13 @@
#include "llvm/DebugInfo/CodeView/Formatters.h"
#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/TpiHashing.h"
#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MathExtras.h"

View File

@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "PrettyBuiltinDumper.h"
#include "LinePrinter.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
using namespace llvm;

View File

@ -8,7 +8,6 @@
#include "PrettyClassDefinitionDumper.h"
#include "LinePrinter.h"
#include "PrettyClassLayoutGraphicalDumper.h"
#include "llvm-pdbutil.h"

View File

@ -8,7 +8,6 @@
#include "PrettyClassLayoutGraphicalDumper.h"
#include "LinePrinter.h"
#include "PrettyClassDefinitionDumper.h"
#include "PrettyEnumDumper.h"
#include "PrettyFunctionDumper.h"

View File

@ -8,7 +8,6 @@
#include "PrettyCompilandDumper.h"
#include "LinePrinter.h"
#include "PrettyFunctionDumper.h"
#include "llvm-pdbutil.h"

View File

@ -8,7 +8,6 @@
#include "PrettyEnumDumper.h"
#include "LinePrinter.h"
#include "PrettyBuiltinDumper.h"
#include "llvm-pdbutil.h"

View File

@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#include "PrettyExternalSymbolDumper.h"
#include "LinePrinter.h"
#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
#include "llvm/Support/Format.h"

View File

@ -7,12 +7,12 @@
//===----------------------------------------------------------------------===//
#include "PrettyFunctionDumper.h"
#include "LinePrinter.h"
#include "PrettyBuiltinDumper.h"
#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include "llvm/DebugInfo/PDB/PDBExtras.h"
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"

View File

@ -8,7 +8,6 @@
#include "PrettyTypeDumper.h"
#include "LinePrinter.h"
#include "PrettyBuiltinDumper.h"
#include "PrettyClassDefinitionDumper.h"
#include "PrettyEnumDumper.h"

View File

@ -8,13 +8,13 @@
#include "PrettyTypedefDumper.h"
#include "LinePrinter.h"
#include "PrettyBuiltinDumper.h"
#include "PrettyFunctionDumper.h"
#include "PrettyTypeDumper.h"
#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include "llvm/DebugInfo/PDB/PDBExtras.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"

View File

@ -8,7 +8,6 @@
#include "PrettyVariableDumper.h"
#include "LinePrinter.h"
#include "PrettyBuiltinDumper.h"
#include "PrettyFunctionDumper.h"
#include "llvm-pdbutil.h"

View File

@ -7,13 +7,13 @@
//===----------------------------------------------------------------------===//
#include "StreamUtil.h"
#include "FormatUtil.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
#include "llvm/DebugInfo/PDB/Native/DbiModuleList.h"
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/TpiStream.h"

View File

@ -9,10 +9,12 @@
#include "TypeReferenceTracker.h"
#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
#include "llvm/Object/COFF.h"
using namespace llvm;
using namespace llvm::pdb;

View File

@ -9,14 +9,13 @@
#ifndef LLVM_TOOLS_LLVMPDBDUMP_TYPEREFERENCETRACKER_H
#define LLVM_TOOLS_LLVMPDBDUMP_TYPEREFERENCETRACKER_H
#include "InputFile.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/CodeView/CVRecord.h"
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
#include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
#include "llvm/DebugInfo/PDB/Native/InputFile.h"
#include "llvm/Support/Error.h"
namespace llvm {

View File

@ -15,8 +15,6 @@
#include "BytesOutputStyle.h"
#include "DumpOutputStyle.h"
#include "ExplainOutputStyle.h"
#include "InputFile.h"
#include "LinePrinter.h"
#include "OutputStyle.h"
#include "PrettyClassDefinitionDumper.h"
#include "PrettyCompilandDumper.h"
@ -55,6 +53,7 @@
#include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h"
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
#include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
#include "llvm/DebugInfo/PDB/Native/InputFile.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
@ -199,6 +198,8 @@ static cl::opt<bool> Typedefs("typedefs", cl::desc("Dump typedefs"),
cl::sub(DiaDumpSubcommand));
} // namespace diadump
FilterOptions Filters;
namespace pretty {
cl::list<std::string> InputFilenames(cl::Positional,
cl::desc("<input PDB files>"),
@ -1072,7 +1073,7 @@ static void dumpPretty(StringRef Path) {
const bool UseColor = opts::pretty::ColorOutput == cl::BOU_UNSET
? Stream.has_colors()
: opts::pretty::ColorOutput == cl::BOU_TRUE;
LinePrinter Printer(2, UseColor, Stream);
LinePrinter Printer(2, UseColor, Stream, opts::Filters);
auto GlobalScope(Session->getGlobalScope());
if (!GlobalScope)
@ -1510,6 +1511,25 @@ int main(int Argc, const char **Argv) {
llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
// Initialize the filters for LinePrinter.
auto propagate = [&](auto &Target, auto &Reference) {
for (std::string &Option : Reference)
Target.push_back(Option);
};
propagate(opts::Filters.ExcludeTypes, opts::pretty::ExcludeTypes);
propagate(opts::Filters.ExcludeTypes, opts::pretty::ExcludeTypes);
propagate(opts::Filters.ExcludeSymbols, opts::pretty::ExcludeSymbols);
propagate(opts::Filters.ExcludeCompilands, opts::pretty::ExcludeCompilands);
propagate(opts::Filters.IncludeTypes, opts::pretty::IncludeTypes);
propagate(opts::Filters.IncludeSymbols, opts::pretty::IncludeSymbols);
propagate(opts::Filters.IncludeCompilands, opts::pretty::IncludeCompilands);
opts::Filters.PaddingThreshold = opts::pretty::PaddingThreshold;
opts::Filters.SizeThreshold = opts::pretty::SizeThreshold;
opts::Filters.JustMyCode = opts::dump::JustMyCode;
if (opts::dump::DumpModi.getNumOccurrences())
opts::Filters.DumpModi = opts::dump::DumpModi;
if (opts::PdbToYamlSubcommand) {
pdb2Yaml(opts::pdb2yaml::InputFilename.front());
} else if (opts::YamlToPdbSubcommand) {
@ -1548,14 +1568,14 @@ int main(int Argc, const char **Argv) {
// it needs to be escaped again in the C++. So matching a single \ in the
// input requires 4 \es in the C++.
if (opts::pretty::ExcludeCompilerGenerated) {
opts::pretty::ExcludeTypes.push_back("__vc_attributes");
opts::pretty::ExcludeCompilands.push_back("\\* Linker \\*");
opts::Filters.ExcludeTypes.push_back("__vc_attributes");
opts::Filters.ExcludeCompilands.push_back("\\* Linker \\*");
}
if (opts::pretty::ExcludeSystemLibraries) {
opts::pretty::ExcludeCompilands.push_back(
opts::Filters.ExcludeCompilands.push_back(
"f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
opts::pretty::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
opts::pretty::ExcludeCompilands.push_back(
opts::Filters.ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
opts::Filters.ExcludeCompilands.push_back(
"d:\\\\th.obj.x86fre\\\\minkernel");
}
llvm::for_each(opts::pretty::InputFilenames, dumpPretty);

View File

@ -12,6 +12,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
@ -50,6 +51,8 @@ enum class ModuleSubsection {
All
};
extern FilterOptions Filters;
namespace pretty {
enum class ClassDefinitionFormat { None, Layout, All };