From 90db78816b9cc285254b8a4d8fcf5c0499dc2dad Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 2 Jun 2016 18:20:20 +0000 Subject: pdbdump: print out COFF section headers. Unlike other sections that can grow to any size, the COFF section header stream has maximum length because each record is fixed size and the COFF file format limits the maximum number of sections. So I decided to not create a specific stream class for it. Instead, I added a member function to DbiStream class which returns a vector of COFF headers. Differential Revision: http://reviews.llvm.org/D20717 llvm-svn: 271557 --- llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'llvm/lib/DebugInfo') diff --git a/llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp index 96a68b6caa6..8c46957706e 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp @@ -6,6 +6,7 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// + #include "llvm/DebugInfo/PDB/Raw/DbiStream.h" #include "llvm/DebugInfo/CodeView/StreamArray.h" @@ -18,6 +19,7 @@ #include "llvm/DebugInfo/PDB/Raw/RawConstants.h" #include "llvm/DebugInfo/PDB/Raw/RawError.h" #include "llvm/DebugInfo/PDB/Raw/RawTypes.h" +#include "llvm/Object/COFF.h" using namespace llvm; using namespace llvm::codeview; @@ -180,7 +182,8 @@ Error DbiStream::reload() { if (auto EC = initializeSectionContributionData()) return EC; - + if (auto EC = initializeSectionHeadersData()) + return EC; if (auto EC = initializeSectionMapData()) return EC; @@ -244,6 +247,11 @@ PDB_Machine DbiStream::getMachineType() const { return static_cast(Machine); } +codeview::FixedStreamArray +DbiStream::getSectionHeaders() { + return SectionHeaders; +} + ArrayRef DbiStream::modules() const { return ModuleInfos; } codeview::FixedStreamArray DbiStream::getSectionMap() const { return SectionMap; @@ -274,6 +282,24 @@ Error DbiStream::initializeSectionContributionData() { "Unsupported DBI Section Contribution version"); } +// Initializes this->SectionHeaders. +Error DbiStream::initializeSectionHeadersData() { + uint32_t StreamNum = getDebugStreamIndex(DbgHeaderType::SectionHdr); + SectionHeaderStream.reset(new MappedBlockStream(StreamNum, Pdb)); + + size_t StreamLen = SectionHeaderStream->getLength(); + if (StreamLen % sizeof(object::coff_section)) + return make_error(raw_error_code::corrupt_file, + "Corrupted section header stream."); + + size_t NumSections = StreamLen / sizeof(object::coff_section); + codeview::StreamReader Reader(*SectionHeaderStream); + if (auto EC = Reader.readArray(SectionHeaders, NumSections)) + return make_error(raw_error_code::corrupt_file, + "Could not read a bitmap."); + return Error::success(); +} + Error DbiStream::initializeSectionMapData() { StreamReader SMReader(SecMapSubstream); const SecMapHeader *Header; -- cgit v1.2.3