diff options
| author | Zachary Turner <zturner@google.com> | 2016-04-26 18:42:34 +0000 |
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2016-04-26 18:42:34 +0000 |
| commit | 53a65ba5c98ca29c568ff18fe14e11ce6ff53b43 (patch) | |
| tree | d49e2aae51f3aab0f7882005430c701e0504705c /llvm/lib/DebugInfo/PDB/Raw | |
| parent | 35c913dd4cd51ca0cb816e1ec60d16bc205b74fb (diff) | |
| download | bcm5719-llvm-53a65ba5c98ca29c568ff18fe14e11ce6ff53b43.tar.gz bcm5719-llvm-53a65ba5c98ca29c568ff18fe14e11ce6ff53b43.zip | |
Parse and dump PDB DBI Stream Header Information
The DBI stream contains a lot of bookkeeping information for other
streams. In particular it contains information about section contributions
and linked modules. This patch is a first attempt at parsing some of the
information out of the DBI stream. It currently only parses and dumps the
headers of the DBI stream, so none of the module data or section
contribution data is pulled out.
This is just a proof of concept that we understand the basic properties of
the DBI stream's metadata, and followup patches will try to extract more
detailed information out.
Differential Revision: http://reviews.llvm.org/D19500
Reviewed By: majnemer, ruiu
llvm-svn: 267585
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw')
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/PDBDbiStream.cpp | 143 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp | 18 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/PDBInfoStream.cpp | 2 |
3 files changed, 162 insertions, 1 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBDbiStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBDbiStream.cpp new file mode 100644 index 00000000000..15adae666e3 --- /dev/null +++ b/llvm/lib/DebugInfo/PDB/Raw/PDBDbiStream.cpp @@ -0,0 +1,143 @@ +//===- PDBDbiStream.cpp - PDB Dbi Stream (Stream 3) Access ----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/Raw/PDBDbiStream.h" +#include "llvm/DebugInfo/PDB/Raw/PDBFile.h" +#include "llvm/DebugInfo/PDB/Raw/PDBInfoStream.h" +#include "llvm/DebugInfo/PDB/Raw/PDBRawConstants.h" + +using namespace llvm; +using namespace llvm::support; + +namespace { +// Some of the values are stored in bitfields. Since this needs to be portable +// across compilers and architectures (big / little endian in particular) we +// can't use the actual structures below, but must instead do the shifting +// and masking ourselves. The struct definitions are provided for reference. + +// struct DbiFlags { +// uint16_t IncrementalLinking : 1; // True if linked incrementally +// uint16_t IsStripped : 1; // True if private symbols were stripped. +// uint16_t HasCTypes : 1; // True if linked with /debug:ctypes. +// uint16_t Reserved : 13; +//}; +const uint16_t FlagIncrementalMask = 0x0001; +const uint16_t FlagStrippedMask = 0x0002; +const uint16_t FlagHasCTypesMask = 0x0004; + +// struct DbiBuildNo { +// uint16_t MinorVersion : 8; +// uint16_t MajorVersion : 7; +// uint16_t NewVersionFormat : 1; +//}; +const uint16_t BuildMinorMask = 0x00FF; +const uint16_t BuildMinorShift = 0; + +const uint16_t BuildMajorMask = 0x7F00; +const uint16_t BuildMajorShift = 8; + +const uint16_t BuildNewFormatMask = 0x8000; +const uint16_t BuildNewFormatShift = 15; +} + +struct PDBDbiStream::HeaderInfo { + ulittle32_t VersionSignature; + ulittle32_t VersionHeader; + ulittle32_t Age; // Should match PDBInfoStream. + ulittle16_t GSSyms; + ulittle16_t BuildNumber; // See DbiBuildNo structure. + ulittle16_t PSSyms; + ulittle16_t PdbDllVersion; // version of mspdbNNN.dll + ulittle16_t SymRecords; // Number of symbols + ulittle16_t PdbDllRbld; // rbld number of mspdbNNN.dll + little32_t ModiSubstreamSize; // Size of module info stream + little32_t SecContrSubstreamSize; // Size of sec. contribution stream + little32_t SectionMapSize; + little32_t FileInfoSize; + little32_t TypeServerSize; // Size of type server map + ulittle32_t MFCTypeServerIndex; // Index of MFC Type Server + little32_t OptionalDbgHdrSize; // Size of DbgHeader info + little32_t ECSubstreamSize; // Size of EC stream (what is EC?) + ulittle16_t Flags; // See DbiFlags enum. + ulittle16_t MachineType; // See PDB_MachineType enum. + + ulittle32_t Reserved; // Pad to 64 bytes +}; + +PDBDbiStream::PDBDbiStream(PDBFile &File) : Pdb(File), Stream(3, File) { + static_assert(sizeof(HeaderInfo) == 64, "Invalid HeaderInfo size!"); +} + +PDBDbiStream::~PDBDbiStream() {} + +std::error_code PDBDbiStream::reload() { + Stream.setOffset(0); + Header.reset(new HeaderInfo()); + + if (Stream.getLength() < sizeof(HeaderInfo)) + return std::make_error_code(std::errc::illegal_byte_sequence); + Stream.readObject(Header.get()); + + if (Header->VersionSignature != -1) + return std::make_error_code(std::errc::illegal_byte_sequence); + + // Prior to VC50 an old style header was used. We don't support this. + if (Header->VersionHeader < PdbDbiV50) + return std::make_error_code(std::errc::not_supported); + + if (Header->Age != Pdb.getPDBInfoStream().getAge()) + return std::make_error_code(std::errc::illegal_byte_sequence); + + if (Stream.getLength() != + sizeof(HeaderInfo) + Header->ModiSubstreamSize + + Header->SecContrSubstreamSize + Header->SectionMapSize + + Header->FileInfoSize + Header->TypeServerSize + + Header->OptionalDbgHdrSize + Header->ECSubstreamSize) + return std::make_error_code(std::errc::illegal_byte_sequence); + + return std::error_code(); +} + +PdbRaw_DbiVer PDBDbiStream::getDbiVersion() const { + uint32_t Value = Header->VersionHeader; + return static_cast<PdbRaw_DbiVer>(Value); +} + +uint32_t PDBDbiStream::getAge() const { return Header->Age; } + +bool PDBDbiStream::isIncrementallyLinked() const { + return (Header->Flags & FlagIncrementalMask) != 0; +} + +bool PDBDbiStream::hasCTypes() const { + return (Header->Flags & FlagHasCTypesMask) != 0; +} + +bool PDBDbiStream::isStripped() const { + return (Header->Flags & FlagStrippedMask) != 0; +} + +uint16_t PDBDbiStream::getBuildMajorVersion() const { + return (Header->BuildNumber & BuildMajorMask) >> BuildMajorShift; +} + +uint16_t PDBDbiStream::getBuildMinorVersion() const { + return (Header->BuildNumber & BuildMinorMask) >> BuildMinorShift; +} + +uint32_t PDBDbiStream::getPdbDllVersion() const { + return Header->PdbDllVersion; +} + +uint32_t PDBDbiStream::getNumberOfSymbols() const { return Header->SymRecords; } + +PDB_Machine PDBDbiStream::getMachineType() const { + uint16_t Machine = Header->MachineType; + return static_cast<PDB_Machine>(Machine); +} diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp index 01d7554a183..6fefafe597c 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp @@ -9,6 +9,8 @@ #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/DebugInfo/PDB/Raw/PDBDbiStream.h" +#include "llvm/DebugInfo/PDB/Raw/PDBInfoStream.h" #include "llvm/Support/Endian.h" #include "llvm/Support/MemoryBuffer.h" @@ -236,3 +238,19 @@ llvm::ArrayRef<support::ulittle32_t> PDBFile::getDirectoryBlockArray() { Context->Buffer->getBufferStart() + getBlockMapOffset()), getNumDirectoryBlocks()); } + +PDBInfoStream &PDBFile::getPDBInfoStream() { + if (!InfoStream) { + InfoStream.reset(new PDBInfoStream(*this)); + InfoStream->reload(); + } + return *InfoStream; +} + +PDBDbiStream &PDBFile::getPDBDbiStream() { + if (!DbiStream) { + DbiStream.reset(new PDBDbiStream(*this)); + DbiStream->reload(); + } + return *DbiStream; +} diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBInfoStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBInfoStream.cpp index 76fa1952d7f..8b12eeaf8dd 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/PDBInfoStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/PDBInfoStream.cpp @@ -20,7 +20,7 @@ std::error_code PDBInfoStream::reload() { support::ulittle32_t Value; Stream1.readObject(&Version); - if (Version < PdbRaw_ImplVer::VC70) + if (Version < PdbRaw_ImplVer::PdbImplVC70) return std::make_error_code(std::errc::not_supported); Stream1.readObject(&Value); |

