Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
Show First 20 Lines • Show All 282 Lines • ▼ Show 20 Lines | static StatCollection getSymbolStats(const SymbolGroup &SG, | ||||
for (const auto &SS : SG.getDebugSubsections()) { | for (const auto &SS : SG.getDebugSubsections()) { | ||||
// For object files, all symbols are spread across multiple Symbol | // For object files, all symbols are spread across multiple Symbol | ||||
// subsections of a given .debug$S section. | // subsections of a given .debug$S section. | ||||
if (SS.kind() != DebugSubsectionKind::Symbols) | if (SS.kind() != DebugSubsectionKind::Symbols) | ||||
continue; | continue; | ||||
DebugSymbolsSubsectionRef Symbols; | DebugSymbolsSubsectionRef Symbols; | ||||
BinaryStreamReader Reader(SS.getRecordData()); | BinaryStreamReader Reader(SS.getRecordData()); | ||||
cantFail(Symbols.initialize(Reader)); | llvm_cantFail(Symbols.initialize(Reader)); | ||||
for (const auto &S : Symbols) { | for (const auto &S : Symbols) { | ||||
Stats.update(S.kind(), S.length()); | Stats.update(S.kind(), S.length()); | ||||
CumulativeStats.update(S.kind(), S.length()); | CumulativeStats.update(S.kind(), S.length()); | ||||
} | } | ||||
} | } | ||||
return Stats; | return Stats; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | |||||
static Expected<std::pair<std::unique_ptr<MappedBlockStream>, | static Expected<std::pair<std::unique_ptr<MappedBlockStream>, | ||||
ArrayRef<llvm::object::coff_section>>> | ArrayRef<llvm::object::coff_section>>> | ||||
loadSectionHeaders(PDBFile &File, DbgHeaderType Type) { | loadSectionHeaders(PDBFile &File, DbgHeaderType Type) { | ||||
if (!File.hasPDBDbiStream()) | if (!File.hasPDBDbiStream()) | ||||
return make_error<StringError>( | return make_error<StringError>( | ||||
"Section headers require a DBI Stream, which could not be loaded", | "Section headers require a DBI Stream, which could not be loaded", | ||||
inconvertibleErrorCode()); | inconvertibleErrorCode()); | ||||
auto &Dbi = cantFail(File.getPDBDbiStream()); | auto &Dbi = llvm_cantFail(File.getPDBDbiStream()); | ||||
uint32_t SI = Dbi.getDebugStreamIndex(Type); | uint32_t SI = Dbi.getDebugStreamIndex(Type); | ||||
if (SI == kInvalidStreamIndex) | if (SI == kInvalidStreamIndex) | ||||
return make_error<StringError>( | return make_error<StringError>( | ||||
"PDB does not contain the requested image section header type", | "PDB does not contain the requested image section header type", | ||||
inconvertibleErrorCode()); | inconvertibleErrorCode()); | ||||
auto Stream = File.createIndexedStream(SI); | auto Stream = File.createIndexedStream(SI); | ||||
if (!Stream) | if (!Stream) | ||||
return make_error<StringError>("Could not load the required stream data", | return make_error<StringError>("Could not load the required stream data", | ||||
inconvertibleErrorCode()); | inconvertibleErrorCode()); | ||||
ArrayRef<object::coff_section> Headers; | ArrayRef<object::coff_section> Headers; | ||||
if (Stream->getLength() % sizeof(object::coff_section) != 0) | if (Stream->getLength() % sizeof(object::coff_section) != 0) | ||||
return make_error<StringError>( | return make_error<StringError>( | ||||
"Section header array size is not a multiple of section header size", | "Section header array size is not a multiple of section header size", | ||||
inconvertibleErrorCode()); | inconvertibleErrorCode()); | ||||
uint32_t NumHeaders = Stream->getLength() / sizeof(object::coff_section); | uint32_t NumHeaders = Stream->getLength() / sizeof(object::coff_section); | ||||
BinaryStreamReader Reader(*Stream); | BinaryStreamReader Reader(*Stream); | ||||
cantFail(Reader.readArray(Headers, NumHeaders)); | llvm_cantFail(Reader.readArray(Headers, NumHeaders)); | ||||
return std::make_pair(std::move(Stream), Headers); | return std::make_pair(std::move(Stream), Headers); | ||||
} | } | ||||
static std::vector<std::string> getSectionNames(PDBFile &File) { | static std::vector<std::string> getSectionNames(PDBFile &File) { | ||||
auto ExpectedHeaders = loadSectionHeaders(File, DbgHeaderType::SectionHdr); | auto ExpectedHeaders = loadSectionHeaders(File, DbgHeaderType::SectionHdr); | ||||
if (!ExpectedHeaders) | if (!ExpectedHeaders) | ||||
return {}; | return {}; | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | if (File.isPdb()) | ||||
Scope.emplace(P, 2); | Scope.emplace(P, 2); | ||||
iterateSymbolGroups(File, Scope, [&](uint32_t Modi, const SymbolGroup &SG) { | iterateSymbolGroups(File, Scope, [&](uint32_t Modi, const SymbolGroup &SG) { | ||||
StatCollection SS = getSymbolStats(SG, SymStats); | StatCollection SS = getSymbolStats(SG, SymStats); | ||||
StatCollection CS = getChunkStats(SG, ChunkStats); | StatCollection CS = getChunkStats(SG, ChunkStats); | ||||
if (SG.getFile().isPdb()) { | if (SG.getFile().isPdb()) { | ||||
AutoIndent Indent(P); | AutoIndent Indent(P); | ||||
auto Modules = cantFail(File.pdb().getPDBDbiStream()).modules(); | auto Modules = llvm_cantFail(File.pdb().getPDBDbiStream()).modules(); | ||||
uint32_t ModCount = Modules.getModuleCount(); | uint32_t ModCount = Modules.getModuleCount(); | ||||
DbiModuleDescriptor Desc = Modules.getModuleDescriptor(Modi); | DbiModuleDescriptor Desc = Modules.getModuleDescriptor(Modi); | ||||
uint32_t StreamIdx = Desc.getModuleStreamIndex(); | uint32_t StreamIdx = Desc.getModuleStreamIndex(); | ||||
if (StreamIdx == kInvalidStreamIndex) { | if (StreamIdx == kInvalidStreamIndex) { | ||||
P.formatLine("Mod {0} (debug info not present): [{1}]", | P.formatLine("Mod {0} (debug info not present): [{1}]", | ||||
fmt_align(Modi, AlignStyle::Right, NumDigits(ModCount)), | fmt_align(Modi, AlignStyle::Right, NumDigits(ModCount)), | ||||
Desc.getModuleName()); | Desc.getModuleName()); | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | Error DumpOutputStyle::dumpUdtStats() { | ||||
StringMap<StatCollection::Stat> NamespacedStats; | StringMap<StatCollection::Stat> NamespacedStats; | ||||
size_t LongestNamespace = 0; | size_t LongestNamespace = 0; | ||||
auto HandleOneSymbol = [&](const CVSymbol &Sym) { | auto HandleOneSymbol = [&](const CVSymbol &Sym) { | ||||
if (Sym.kind() != SymbolKind::S_UDT) | if (Sym.kind() != SymbolKind::S_UDT) | ||||
return; | return; | ||||
UdtStats.update(SymbolKind::S_UDT, Sym.length()); | UdtStats.update(SymbolKind::S_UDT, Sym.length()); | ||||
UDTSym UDT = cantFail(SymbolDeserializer::deserializeAs<UDTSym>(Sym)); | UDTSym UDT = llvm_cantFail(SymbolDeserializer::deserializeAs<UDTSym>(Sym)); | ||||
uint32_t Kind = 0; | uint32_t Kind = 0; | ||||
uint32_t RecordSize = 0; | uint32_t RecordSize = 0; | ||||
if (UDT.Type.isNoneType()) | if (UDT.Type.isNoneType()) | ||||
Kind = kNoneUdtKind; | Kind = kNoneUdtKind; | ||||
else if (UDT.Type.isSimple()) | else if (UDT.Type.isSimple()) | ||||
Kind = kSimpleUdtKind; | Kind = kSimpleUdtKind; | ||||
Show All 15 Lines | auto HandleOneSymbol = [&](const CVSymbol &Sym) { | ||||
LongestNamespace = std::max(LongestNamespace, Scope.size()); | LongestNamespace = std::max(LongestNamespace, Scope.size()); | ||||
NamespacedStats[Scope].update(RecordSize); | NamespacedStats[Scope].update(RecordSize); | ||||
}; | }; | ||||
P.NewLine(); | P.NewLine(); | ||||
if (File.isPdb()) { | if (File.isPdb()) { | ||||
auto &SymbolRecords = cantFail(getPdb().getPDBSymbolStream()); | auto &SymbolRecords = llvm_cantFail(getPdb().getPDBSymbolStream()); | ||||
auto ExpGlobals = getPdb().getPDBGlobalsStream(); | auto ExpGlobals = getPdb().getPDBGlobalsStream(); | ||||
if (!ExpGlobals) | if (!ExpGlobals) | ||||
return ExpGlobals.takeError(); | return ExpGlobals.takeError(); | ||||
for (uint32_t PubSymOff : ExpGlobals->getGlobalsTable()) { | for (uint32_t PubSymOff : ExpGlobals->getGlobalsTable()) { | ||||
CVSymbol Sym = SymbolRecords.readRecord(PubSymOff); | CVSymbol Sym = SymbolRecords.readRecord(PubSymOff); | ||||
HandleOneSymbol(Sym); | HandleOneSymbol(Sym); | ||||
} | } | ||||
} else { | } else { | ||||
for (const auto &Sec : File.symbol_groups()) { | for (const auto &Sec : File.symbol_groups()) { | ||||
for (const auto &SS : Sec.getDebugSubsections()) { | for (const auto &SS : Sec.getDebugSubsections()) { | ||||
if (SS.kind() != DebugSubsectionKind::Symbols) | if (SS.kind() != DebugSubsectionKind::Symbols) | ||||
continue; | continue; | ||||
DebugSymbolsSubsectionRef Symbols; | DebugSymbolsSubsectionRef Symbols; | ||||
BinaryStreamReader Reader(SS.getRecordData()); | BinaryStreamReader Reader(SS.getRecordData()); | ||||
cantFail(Symbols.initialize(Reader)); | llvm_cantFail(Symbols.initialize(Reader)); | ||||
for (const auto &S : Symbols) | for (const auto &S : Symbols) | ||||
HandleOneSymbol(S); | HandleOneSymbol(S); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
LongestNamespace += StringRef(" namespace ''").size(); | LongestNamespace += StringRef(" namespace ''").size(); | ||||
size_t LongestTypeLeafKind = getLongestTypeLeafName(UdtTargetStats); | size_t LongestTypeLeafKind = getLongestTypeLeafName(UdtTargetStats); | ||||
▲ Show 20 Lines • Show All 365 Lines • ▼ Show 20 Lines | P.NewLine(); | ||||
P.formatLine("Signature: {0}", IS->getSignature()); | P.formatLine("Signature: {0}", IS->getSignature()); | ||||
P.formatLine("Hash Version: {0}", IS->getHashVersion()); | P.formatLine("Hash Version: {0}", IS->getHashVersion()); | ||||
P.formatLine("Name Buffer Size: {0}", IS->getByteSize()); | P.formatLine("Name Buffer Size: {0}", IS->getByteSize()); | ||||
P.NewLine(); | P.NewLine(); | ||||
} | } | ||||
BinaryStreamRef NameBuffer = IS->getStringTable().getBuffer(); | BinaryStreamRef NameBuffer = IS->getStringTable().getBuffer(); | ||||
ArrayRef<uint8_t> Contents; | ArrayRef<uint8_t> Contents; | ||||
cantFail(NameBuffer.readBytes(0, NameBuffer.getLength(), Contents)); | llvm_cantFail(NameBuffer.readBytes(0, NameBuffer.getLength(), Contents)); | ||||
P.formatBinary("Name Buffer", Contents, 0); | P.formatBinary("Name Buffer", Contents, 0); | ||||
P.NewLine(); | P.NewLine(); | ||||
{ | { | ||||
P.printLine("Hash Table:"); | P.printLine("Hash Table:"); | ||||
AutoIndent Indent(P); | AutoIndent Indent(P); | ||||
P.formatLine("Bucket Count: {0}", IS->name_ids().size()); | P.formatLine("Bucket Count: {0}", IS->name_ids().size()); | ||||
for (const auto &Entry : enumerate(IS->name_ids())) | for (const auto &Entry : enumerate(IS->name_ids())) | ||||
P.formatLine("Bucket[{0}] : {1}", Entry.index(), | P.formatLine("Bucket[{0}] : {1}", Entry.index(), | ||||
Show All 9 Lines | iterateModuleSubsections<DebugStringTableSubsectionRef>( | ||||
File, PrintScope{P, 4}, | File, PrintScope{P, 4}, | ||||
[&](uint32_t Modi, const SymbolGroup &Strings, | [&](uint32_t Modi, const SymbolGroup &Strings, | ||||
DebugStringTableSubsectionRef &Strings2) { | DebugStringTableSubsectionRef &Strings2) { | ||||
BinaryStreamRef StringTableBuffer = Strings2.getBuffer(); | BinaryStreamRef StringTableBuffer = Strings2.getBuffer(); | ||||
BinaryStreamReader Reader(StringTableBuffer); | BinaryStreamReader Reader(StringTableBuffer); | ||||
while (Reader.bytesRemaining() > 0) { | while (Reader.bytesRemaining() > 0) { | ||||
StringRef Str; | StringRef Str; | ||||
uint32_t Offset = Reader.getOffset(); | uint32_t Offset = Reader.getOffset(); | ||||
cantFail(Reader.readCString(Str)); | llvm_cantFail(Reader.readCString(Str)); | ||||
if (Str.empty()) | if (Str.empty()) | ||||
continue; | continue; | ||||
P.formatLine("{0} | {1}", fmt_align(Offset, AlignStyle::Right, 4), | P.formatLine("{0} | {1}", fmt_align(Offset, AlignStyle::Right, 4), | ||||
Str); | Str); | ||||
} | } | ||||
}); | }); | ||||
return Error::success(); | return Error::success(); | ||||
▲ Show 20 Lines • Show All 388 Lines • ▼ Show 20 Lines | Error DumpOutputStyle::dumpGSIRecords() { | ||||
if (!getPdb().hasPDBSymbolStream()) { | if (!getPdb().hasPDBSymbolStream()) { | ||||
printStreamNotPresent("GSI Common Symbol"); | printStreamNotPresent("GSI Common Symbol"); | ||||
return Error::success(); | return Error::success(); | ||||
} | } | ||||
AutoIndent Indent(P); | AutoIndent Indent(P); | ||||
auto &Records = cantFail(getPdb().getPDBSymbolStream()); | auto &Records = llvm_cantFail(getPdb().getPDBSymbolStream()); | ||||
auto &Types = File.types(); | auto &Types = File.types(); | ||||
auto &Ids = File.ids(); | auto &Ids = File.ids(); | ||||
P.printLine("Records"); | P.printLine("Records"); | ||||
SymbolVisitorCallbackPipeline Pipeline; | SymbolVisitorCallbackPipeline Pipeline; | ||||
SymbolDeserializer Deserializer(nullptr, CodeViewContainer::Pdb); | SymbolDeserializer Deserializer(nullptr, CodeViewContainer::Pdb); | ||||
MinimalSymbolDumper Dumper(P, opts::dump::DumpSymRecordBytes, Ids, Types); | MinimalSymbolDumper Dumper(P, opts::dump::DumpSymRecordBytes, Ids, Types); | ||||
Show All 23 Lines | Error DumpOutputStyle::dumpGlobals() { | ||||
AutoIndent Indent(P); | AutoIndent Indent(P); | ||||
ExitOnError Err("Error dumping globals stream: "); | ExitOnError Err("Error dumping globals stream: "); | ||||
auto &Globals = Err(getPdb().getPDBGlobalsStream()); | auto &Globals = Err(getPdb().getPDBGlobalsStream()); | ||||
if (opts::dump::DumpGlobalNames.empty()) { | if (opts::dump::DumpGlobalNames.empty()) { | ||||
const GSIHashTable &Table = Globals.getGlobalsTable(); | const GSIHashTable &Table = Globals.getGlobalsTable(); | ||||
Err(dumpSymbolsFromGSI(Table, opts::dump::DumpGlobalExtras)); | Err(dumpSymbolsFromGSI(Table, opts::dump::DumpGlobalExtras)); | ||||
} else { | } else { | ||||
SymbolStream &SymRecords = cantFail(getPdb().getPDBSymbolStream()); | SymbolStream &SymRecords = llvm_cantFail(getPdb().getPDBSymbolStream()); | ||||
auto &Types = File.types(); | auto &Types = File.types(); | ||||
auto &Ids = File.ids(); | auto &Ids = File.ids(); | ||||
SymbolVisitorCallbackPipeline Pipeline; | SymbolVisitorCallbackPipeline Pipeline; | ||||
SymbolDeserializer Deserializer(nullptr, CodeViewContainer::Pdb); | SymbolDeserializer Deserializer(nullptr, CodeViewContainer::Pdb); | ||||
MinimalSymbolDumper Dumper(P, opts::dump::DumpSymRecordBytes, Ids, Types); | MinimalSymbolDumper Dumper(P, opts::dump::DumpSymRecordBytes, Ids, Types); | ||||
Pipeline.addCallbackToPipeline(Deserializer); | Pipeline.addCallbackToPipeline(Deserializer); | ||||
▲ Show 20 Lines • Show All 293 Lines • Show Last 20 Lines |