mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-24 23:22:10 +00:00
Revert r267049, r26706[16789], r267071 - Refactor raw pdb dumper into library
r267049 broke multiple buildbots (e.g. clang-cmake-mips, and clang-x86_64-linux-selfhost-modules) which the follow-ups have not yet resolved and this is preventing subsequent committers from being notified about additional failures on the affected buildbots. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267148 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c42b2f3bd2
commit
cd2984fe3c
@ -11,7 +11,6 @@
|
||||
#define LLVM_DEBUGINFO_PDB_IPDBSESSION_H
|
||||
|
||||
#include "PDBTypes.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include <memory>
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "llvm/Config/llvm-config.h"
|
||||
#include "llvm/DebugInfo/CodeView/CodeView.h"
|
||||
#include "llvm/Support/Endian.h"
|
||||
#include <functional>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
@ -69,7 +70,6 @@ class PDBSymbolUnknown;
|
||||
/// of PDB_ReaderType::DIA is supported.
|
||||
enum class PDB_ReaderType {
|
||||
DIA = 0,
|
||||
Raw = 1,
|
||||
};
|
||||
|
||||
/// Defines a 128-bit unique identifier. This maps to a GUID on Windows, but
|
||||
@ -429,6 +429,35 @@ struct Variant {
|
||||
}
|
||||
};
|
||||
|
||||
namespace PDB {
|
||||
static const char Magic[] = {'M', 'i', 'c', 'r', 'o', 's', 'o', 'f',
|
||||
't', ' ', 'C', '/', 'C', '+', '+', ' ',
|
||||
'M', 'S', 'F', ' ', '7', '.', '0', '0',
|
||||
'\r', '\n', '\x1a', 'D', 'S', '\0', '\0', '\0'};
|
||||
|
||||
// The superblock is overlaid at the beginning of the file (offset 0).
|
||||
// It starts with a magic header and is followed by information which describes
|
||||
// the layout of the file system.
|
||||
struct SuperBlock {
|
||||
char MagicBytes[sizeof(Magic)];
|
||||
// The file system is split into a variable number of fixed size elements.
|
||||
// These elements are referred to as blocks. The size of a block may vary
|
||||
// from system to system.
|
||||
support::ulittle32_t BlockSize;
|
||||
// This field's purpose is not yet known.
|
||||
support::ulittle32_t Unknown0;
|
||||
// This contains the number of blocks resident in the file system. In
|
||||
// practice, NumBlocks * BlockSize is equivalent to the size of the PDB file.
|
||||
support::ulittle32_t NumBlocks;
|
||||
// This contains the number of bytes which make up the directory.
|
||||
support::ulittle32_t NumDirectoryBytes;
|
||||
// This field's purpose is not yet known.
|
||||
support::ulittle32_t Unknown1;
|
||||
// This contains the block # of the block map.
|
||||
support::ulittle32_t BlockMapAddr;
|
||||
};
|
||||
} // end namespace PDB
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
namespace std {
|
||||
|
@ -1,62 +0,0 @@
|
||||
//===- PDBFile.h - Low level interface to a PDB file ------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBFILE_H
|
||||
#define LLVM_DEBUGINFO_PDB_RAW_PDBFILE_H
|
||||
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/Support/Endian.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace llvm {
|
||||
class MemoryBuffer;
|
||||
|
||||
struct PDBContext;
|
||||
|
||||
class PDBFile {
|
||||
public:
|
||||
explicit PDBFile(std::unique_ptr<MemoryBuffer> MemBuffer);
|
||||
~PDBFile();
|
||||
|
||||
uint32_t getBlockSize() const;
|
||||
uint32_t getUnknown0() const;
|
||||
uint32_t getBlockCount() const;
|
||||
uint32_t getNumDirectoryBytes() const;
|
||||
uint32_t getBlockMapIndex() const;
|
||||
uint32_t getUnknown1() const;
|
||||
uint32_t getNumDirectoryBlocks() const;
|
||||
uint64_t getBlockMapOffset() const;
|
||||
|
||||
uint32_t getNumStreams() const;
|
||||
uint32_t getStreamByteSize(uint32_t StreamIndex) const;
|
||||
llvm::ArrayRef<uint32_t> getStreamBlockList(uint32_t StreamIndex) const;
|
||||
|
||||
StringRef getBlockData(uint32_t BlockIndex, uint32_t NumBytes) const;
|
||||
|
||||
llvm::ArrayRef<uint32_t> getDirectoryBlockArray();
|
||||
|
||||
std::error_code parseFileHeaders();
|
||||
std::error_code parseStreamData();
|
||||
|
||||
static uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize) {
|
||||
return alignTo(NumBytes, BlockSize) / BlockSize;
|
||||
}
|
||||
|
||||
static uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize) {
|
||||
return BlockNumber * BlockSize;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<PDBContext> Context;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,46 +0,0 @@
|
||||
//===- PDBStream.h - Low level interface to a PDB stream --------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBSTREAM_H
|
||||
#define LLVM_DEBUGINFO_PDB_RAW_PDBSTREAM_H
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class MemoryBufferRef;
|
||||
class PDBFile;
|
||||
|
||||
class PDBStream {
|
||||
public:
|
||||
PDBStream(uint32_t StreamIdx, const PDBFile &File);
|
||||
|
||||
std::error_code readInteger(uint32_t &Dest);
|
||||
std::error_code readZeroString(std::string &Dest);
|
||||
std::error_code readBytes(void *Dest, uint32_t Length);
|
||||
|
||||
void setOffset(uint32_t Off);
|
||||
uint32_t getOffset() const;
|
||||
uint32_t getLength() const;
|
||||
|
||||
template <typename T> std::error_code readObject(T *Dest) {
|
||||
return readBytes(reinterpret_cast<void *>(Dest), sizeof(T));
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t Offset;
|
||||
|
||||
uint32_t StreamLength;
|
||||
std::vector<uint32_t> BlockList;
|
||||
const PDBFile &Pdb;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,72 +0,0 @@
|
||||
//===- RawSession.h - Native implementation of IPDBSession ------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGINFO_PDB_RAW_RAWSESSION_H
|
||||
#define LLVM_DEBUGINFO_PDB_RAW_RAWSESSION_H
|
||||
|
||||
#include "llvm/DebugInfo/PDB/IPDBSession.h"
|
||||
|
||||
namespace llvm {
|
||||
class PDBFile;
|
||||
class StringRef;
|
||||
|
||||
class RawSession : public IPDBSession {
|
||||
public:
|
||||
explicit RawSession(std::unique_ptr<PDBFile> PdbFile);
|
||||
~RawSession() override;
|
||||
|
||||
static PDB_ErrorCode createFromPdb(StringRef Path,
|
||||
std::unique_ptr<IPDBSession> &Session);
|
||||
static PDB_ErrorCode createFromExe(StringRef Path,
|
||||
std::unique_ptr<IPDBSession> &Session);
|
||||
|
||||
uint64_t getLoadAddress() const override;
|
||||
void setLoadAddress(uint64_t Address) override;
|
||||
std::unique_ptr<PDBSymbolExe> getGlobalScope() const override;
|
||||
std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const override;
|
||||
|
||||
std::unique_ptr<PDBSymbol>
|
||||
findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override;
|
||||
|
||||
std::unique_ptr<IPDBEnumLineNumbers>
|
||||
findLineNumbers(const PDBSymbolCompiland &Compiland,
|
||||
const IPDBSourceFile &File) const override;
|
||||
std::unique_ptr<IPDBEnumLineNumbers>
|
||||
findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override;
|
||||
|
||||
std::unique_ptr<IPDBEnumSourceFiles>
|
||||
findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern,
|
||||
PDB_NameSearchFlags Flags) const override;
|
||||
std::unique_ptr<IPDBSourceFile>
|
||||
findOneSourceFile(const PDBSymbolCompiland *Compiland,
|
||||
llvm::StringRef Pattern,
|
||||
PDB_NameSearchFlags Flags) const override;
|
||||
std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
|
||||
findCompilandsForSourceFile(llvm::StringRef Pattern,
|
||||
PDB_NameSearchFlags Flags) const override;
|
||||
std::unique_ptr<PDBSymbolCompiland>
|
||||
findOneCompilandForSourceFile(llvm::StringRef Pattern,
|
||||
PDB_NameSearchFlags Flags) const override;
|
||||
std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override;
|
||||
std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland(
|
||||
const PDBSymbolCompiland &Compiland) const override;
|
||||
std::unique_ptr<IPDBSourceFile>
|
||||
getSourceFileById(uint32_t FileId) const override;
|
||||
|
||||
std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override;
|
||||
|
||||
PDBFile &getPDBFile() { return *Pdb; }
|
||||
const PDBFile &getPDBFile() const { return *Pdb; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<PDBFile> Pdb;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -24,12 +24,8 @@ if(HAVE_DIA_SDK)
|
||||
)
|
||||
|
||||
set(LIBPDB_ADDITIONAL_HEADER_DIRS "${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/PDB/DIA")
|
||||
endif()
|
||||
|
||||
add_pdb_impl_folder(Raw
|
||||
Raw/PDBFile.cpp
|
||||
Raw/PDBStream.cpp
|
||||
Raw/RawSession.cpp)
|
||||
endif()
|
||||
|
||||
list(APPEND LIBPDB_ADDITIONAL_HEADER_DIRS "${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/PDB")
|
||||
|
||||
|
@ -17,30 +17,23 @@
|
||||
#if HAVE_DIA_SDK
|
||||
#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
|
||||
#endif
|
||||
#include "llvm/DebugInfo/PDB/Raw/RawSession.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
PDB_ErrorCode llvm::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
|
||||
std::unique_ptr<IPDBSession> &Session) {
|
||||
// Create the correct concrete instance type based on the value of Type.
|
||||
if (Type == PDB_ReaderType::Raw)
|
||||
return RawSession::createFromPdb(Path, Session);
|
||||
|
||||
#if HAVE_DIA_SDK
|
||||
return DIASession::createFromPdb(Path, Session);
|
||||
#endif
|
||||
return PDB_ErrorCode::NoDiaSupport;
|
||||
return PDB_ErrorCode::NoDiaSupport;
|
||||
}
|
||||
|
||||
PDB_ErrorCode llvm::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
|
||||
std::unique_ptr<IPDBSession> &Session) {
|
||||
// Create the correct concrete instance type based on the value of Type.
|
||||
if (Type == PDB_ReaderType::Raw)
|
||||
return RawSession::createFromExe(Path, Session);
|
||||
|
||||
#if HAVE_DIA_SDK
|
||||
return DIASession::createFromExe(Path, Session);
|
||||
#endif
|
||||
return PDB_ErrorCode::NoDiaSupport;
|
||||
return PDB_ErrorCode::NoDiaSupport;
|
||||
}
|
||||
|
@ -1,238 +0,0 @@
|
||||
//===- PDBFile.cpp - Low level interface to a PDB file ----------*- C++ -*-===//
|
||||
//
|
||||
// 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/PDBFile.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/Support/Endian.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
static const char Magic[] = {'M', 'i', 'c', 'r', 'o', 's', 'o', 'f',
|
||||
't', ' ', 'C', '/', 'C', '+', '+', ' ',
|
||||
'M', 'S', 'F', ' ', '7', '.', '0', '0',
|
||||
'\r', '\n', '\x1a', 'D', 'S', '\0', '\0', '\0'};
|
||||
|
||||
// The superblock is overlaid at the beginning of the file (offset 0).
|
||||
// It starts with a magic header and is followed by information which describes
|
||||
// the layout of the file system.
|
||||
struct SuperBlock {
|
||||
char MagicBytes[sizeof(Magic)];
|
||||
// The file system is split into a variable number of fixed size elements.
|
||||
// These elements are referred to as blocks. The size of a block may vary
|
||||
// from system to system.
|
||||
support::ulittle32_t BlockSize;
|
||||
// This field's purpose is not yet known.
|
||||
support::ulittle32_t Unknown0;
|
||||
// This contains the number of blocks resident in the file system. In
|
||||
// practice, NumBlocks * BlockSize is equivalent to the size of the PDB file.
|
||||
support::ulittle32_t NumBlocks;
|
||||
// This contains the number of bytes which make up the directory.
|
||||
support::ulittle32_t NumDirectoryBytes;
|
||||
// This field's purpose is not yet known.
|
||||
support::ulittle32_t Unknown1;
|
||||
// This contains the block # of the block map.
|
||||
support::ulittle32_t BlockMapAddr;
|
||||
};
|
||||
}
|
||||
|
||||
struct llvm::PDBContext {
|
||||
std::unique_ptr<MemoryBuffer> Buffer;
|
||||
const SuperBlock *SB;
|
||||
std::vector<uint32_t> StreamSizes;
|
||||
DenseMap<uint32_t, std::vector<uint32_t>> StreamMap;
|
||||
};
|
||||
|
||||
static std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr,
|
||||
const uint64_t Size) {
|
||||
if (Addr + Size < Addr || Addr + Size < Size ||
|
||||
Addr + Size > uintptr_t(M.getBufferEnd()) ||
|
||||
Addr < uintptr_t(M.getBufferStart())) {
|
||||
return std::make_error_code(std::errc::bad_address);
|
||||
}
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static std::error_code checkOffset(MemoryBufferRef M, ArrayRef<T> AR) {
|
||||
return checkOffset(M, uintptr_t(AR.data()), (uint64_t)AR.size() * sizeof(T));
|
||||
}
|
||||
|
||||
PDBFile::PDBFile(std::unique_ptr<MemoryBuffer> MemBuffer) {
|
||||
Context.reset(new PDBContext());
|
||||
Context->Buffer = std::move(MemBuffer);
|
||||
}
|
||||
|
||||
PDBFile::~PDBFile() {}
|
||||
|
||||
uint32_t PDBFile::getBlockSize() const { return Context->SB->BlockSize; }
|
||||
|
||||
uint32_t PDBFile::getUnknown0() const { return Context->SB->Unknown0; }
|
||||
|
||||
uint32_t PDBFile::getBlockCount() const { return Context->SB->NumBlocks; }
|
||||
|
||||
uint32_t PDBFile::getNumDirectoryBytes() const {
|
||||
return Context->SB->NumDirectoryBytes;
|
||||
}
|
||||
|
||||
uint32_t PDBFile::getBlockMapIndex() const { return Context->SB->BlockMapAddr; }
|
||||
|
||||
uint32_t PDBFile::getUnknown1() const { return Context->SB->Unknown1; }
|
||||
|
||||
uint32_t PDBFile::getNumDirectoryBlocks() const {
|
||||
return bytesToBlocks(Context->SB->NumDirectoryBytes, Context->SB->BlockSize);
|
||||
}
|
||||
|
||||
uint64_t PDBFile::getBlockMapOffset() const {
|
||||
return (uint64_t)Context->SB->BlockMapAddr * Context->SB->BlockSize;
|
||||
}
|
||||
|
||||
uint32_t PDBFile::getNumStreams() const { return Context->StreamSizes.size(); }
|
||||
|
||||
uint32_t PDBFile::getStreamByteSize(uint32_t StreamIndex) const {
|
||||
return Context->StreamSizes[StreamIndex];
|
||||
}
|
||||
|
||||
llvm::ArrayRef<uint32_t>
|
||||
PDBFile::getStreamBlockList(uint32_t StreamIndex) const {
|
||||
auto &Data = Context->StreamMap[StreamIndex];
|
||||
return llvm::ArrayRef<uint32_t>(Data);
|
||||
}
|
||||
|
||||
StringRef PDBFile::getBlockData(uint32_t BlockIndex, uint32_t NumBytes) const {
|
||||
uint64_t StreamBlockOffset = blockToOffset(BlockIndex, getBlockSize());
|
||||
|
||||
return StringRef(Context->Buffer->getBufferStart() + StreamBlockOffset,
|
||||
NumBytes);
|
||||
}
|
||||
|
||||
std::error_code PDBFile::parseFileHeaders() {
|
||||
std::error_code EC;
|
||||
MemoryBufferRef BufferRef = *Context->Buffer;
|
||||
|
||||
Context->SB =
|
||||
reinterpret_cast<const SuperBlock *>(BufferRef.getBufferStart());
|
||||
const SuperBlock *SB = Context->SB;
|
||||
// Check the magic bytes.
|
||||
if (memcmp(SB->MagicBytes, Magic, sizeof(Magic)) != 0)
|
||||
return std::make_error_code(std::errc::illegal_byte_sequence);
|
||||
|
||||
// We don't support blocksizes which aren't a multiple of four bytes.
|
||||
if (SB->BlockSize % sizeof(support::ulittle32_t) != 0)
|
||||
return std::make_error_code(std::errc::not_supported);
|
||||
|
||||
// We don't support directories whose sizes aren't a multiple of four bytes.
|
||||
if (SB->NumDirectoryBytes % sizeof(support::ulittle32_t) != 0)
|
||||
return std::make_error_code(std::errc::not_supported);
|
||||
|
||||
// The number of blocks which comprise the directory is a simple function of
|
||||
// the number of bytes it contains.
|
||||
uint64_t NumDirectoryBlocks = getNumDirectoryBlocks();
|
||||
|
||||
// The block map, as we understand it, is a block which consists of a list of
|
||||
// block numbers.
|
||||
// It is unclear what would happen if the number of blocks couldn't fit on a
|
||||
// single block.
|
||||
if (NumDirectoryBlocks > SB->BlockSize / sizeof(support::ulittle32_t))
|
||||
return std::make_error_code(std::errc::illegal_byte_sequence);
|
||||
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
std::error_code PDBFile::parseStreamData() {
|
||||
assert(Context && Context->SB);
|
||||
|
||||
bool SeenNumStreams = false;
|
||||
uint32_t NumStreams = 0;
|
||||
uint32_t StreamIdx = 0;
|
||||
uint64_t DirectoryBytesRead = 0;
|
||||
|
||||
MemoryBufferRef M = *Context->Buffer;
|
||||
const SuperBlock *SB = Context->SB;
|
||||
|
||||
auto DirectoryBlocks = getDirectoryBlockArray();
|
||||
|
||||
// The structure of the directory is as follows:
|
||||
// struct PDBDirectory {
|
||||
// uint32_t NumStreams;
|
||||
// uint32_t StreamSizes[NumStreams];
|
||||
// uint32_t StreamMap[NumStreams][];
|
||||
// };
|
||||
//
|
||||
// Empty streams don't consume entries in the StreamMap.
|
||||
for (uint32_t DirectoryBlockAddr : DirectoryBlocks) {
|
||||
uint64_t DirectoryBlockOffset =
|
||||
blockToOffset(DirectoryBlockAddr, SB->BlockSize);
|
||||
auto DirectoryBlock =
|
||||
makeArrayRef(reinterpret_cast<const uint32_t *>(M.getBufferStart() +
|
||||
DirectoryBlockOffset),
|
||||
SB->BlockSize / sizeof(support::ulittle32_t));
|
||||
if (auto EC = checkOffset(M, DirectoryBlock))
|
||||
return EC;
|
||||
|
||||
// We read data out of the directory four bytes at a time. Depending on
|
||||
// where we are in the directory, the contents may be: the number of streams
|
||||
// in the directory, a stream's size, or a block in the stream map.
|
||||
for (uint32_t Data : DirectoryBlock) {
|
||||
// Don't read beyond the end of the directory.
|
||||
if (DirectoryBytesRead == SB->NumDirectoryBytes)
|
||||
break;
|
||||
|
||||
DirectoryBytesRead += sizeof(Data);
|
||||
|
||||
// This data must be the number of streams if we haven't seen it yet.
|
||||
if (!SeenNumStreams) {
|
||||
NumStreams = Data;
|
||||
SeenNumStreams = true;
|
||||
continue;
|
||||
}
|
||||
// This data must be a stream size if we have not seen them all yet.
|
||||
if (Context->StreamSizes.size() < NumStreams) {
|
||||
// It seems like some streams have their set to -1 when their contents
|
||||
// are not present. Treat them like empty streams for now.
|
||||
if (Data == UINT32_MAX)
|
||||
Context->StreamSizes.push_back(0);
|
||||
else
|
||||
Context->StreamSizes.push_back(Data);
|
||||
continue;
|
||||
}
|
||||
|
||||
// This data must be a stream block number if we have seen all of the
|
||||
// stream sizes.
|
||||
std::vector<uint32_t> *StreamBlocks = nullptr;
|
||||
// Figure out which stream this block number belongs to.
|
||||
while (StreamIdx < NumStreams) {
|
||||
uint64_t NumExpectedStreamBlocks =
|
||||
bytesToBlocks(Context->StreamSizes[StreamIdx], SB->BlockSize);
|
||||
StreamBlocks = &Context->StreamMap[StreamIdx];
|
||||
if (NumExpectedStreamBlocks > StreamBlocks->size())
|
||||
break;
|
||||
++StreamIdx;
|
||||
}
|
||||
// It seems this block doesn't belong to any stream? The stream is either
|
||||
// corrupt or something more mysterious is going on.
|
||||
if (StreamIdx == NumStreams)
|
||||
return std::make_error_code(std::errc::illegal_byte_sequence);
|
||||
|
||||
StreamBlocks->push_back(Data);
|
||||
}
|
||||
}
|
||||
|
||||
// We should have read exactly SB->NumDirectoryBytes bytes.
|
||||
assert(DirectoryBytesRead == SB->NumDirectoryBytes);
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
llvm::ArrayRef<uint32_t> PDBFile::getDirectoryBlockArray() {
|
||||
return makeArrayRef(
|
||||
reinterpret_cast<const uint32_t *>(Context->Buffer->getBufferStart() +
|
||||
getBlockMapOffset()),
|
||||
getNumDirectoryBlocks());
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
//===- PDBStream.cpp - Low level interface to a PDB stream ------*- C++ -*-===//
|
||||
//
|
||||
// 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/PDBStream.h"
|
||||
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
PDBStream::PDBStream(uint32_t StreamIdx, const PDBFile &File) : Pdb(File) {
|
||||
this->StreamLength = Pdb.getStreamByteSize(StreamIdx);
|
||||
this->BlockList = Pdb.getStreamBlockList(StreamIdx);
|
||||
this->Offset = 0;
|
||||
}
|
||||
|
||||
std::error_code PDBStream::readInteger(uint32_t &Dest) {
|
||||
support::detail::packed_endian_specific_integral<uint32_t, support::little,
|
||||
support::unaligned>
|
||||
P;
|
||||
if (std::error_code EC = readObject(&P))
|
||||
return EC;
|
||||
Dest = P;
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
std::error_code PDBStream::readZeroString(std::string &Dest) {
|
||||
char C;
|
||||
do {
|
||||
readObject(&C);
|
||||
if (C != '\0')
|
||||
Dest.push_back(C);
|
||||
} while (C != '\0');
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
std::error_code PDBStream::readBytes(void *Dest, uint32_t Length) {
|
||||
uint32_t BlockNum = Offset / Pdb.getBlockSize();
|
||||
uint32_t OffsetInBlock = Offset % Pdb.getBlockSize();
|
||||
|
||||
// Make sure we aren't trying to read beyond the end of the stream.
|
||||
if (this->Offset + Length > this->StreamLength)
|
||||
return std::make_error_code(std::errc::bad_address);
|
||||
|
||||
// Modify the passed in offset to point to the data after the object.
|
||||
Offset += Length;
|
||||
|
||||
// Handle the contiguous case: the offset + size stays within a block.
|
||||
if (OffsetInBlock + Length <= Pdb.getBlockSize()) {
|
||||
uint32_t StreamBlockAddr = this->BlockList[BlockNum];
|
||||
|
||||
StringRef Data = Pdb.getBlockData(StreamBlockAddr, Pdb.getBlockSize());
|
||||
::memcpy(Dest, Data.data() + OffsetInBlock, Length);
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
// The non-contiguous case: we will stitch together non-contiguous chunks
|
||||
uint32_t BytesLeft = Length;
|
||||
uint32_t BytesWritten = 0;
|
||||
char *WriteBuffer = static_cast<char *>(Dest);
|
||||
while (BytesLeft > 0) {
|
||||
uint32_t StreamBlockAddr = this->BlockList[BlockNum];
|
||||
uint64_t StreamBlockOffset =
|
||||
PDBFile::blockToOffset(StreamBlockAddr, Pdb.getBlockSize()) +
|
||||
OffsetInBlock;
|
||||
|
||||
StringRef Data = Pdb.getBlockData(StreamBlockAddr, Pdb.getBlockSize());
|
||||
|
||||
const char *ChunkStart = Data.data() + StreamBlockOffset;
|
||||
uint32_t BytesInChunk =
|
||||
std::min(BytesLeft, Pdb.getBlockSize() - OffsetInBlock);
|
||||
::memcpy(WriteBuffer + BytesWritten, ChunkStart, BytesInChunk);
|
||||
|
||||
BytesWritten += BytesInChunk;
|
||||
BytesLeft -= BytesInChunk;
|
||||
++BlockNum;
|
||||
OffsetInBlock = 0;
|
||||
}
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
void PDBStream::setOffset(uint32_t O) { this->Offset = O; }
|
||||
|
||||
uint32_t PDBStream::getOffset() const { return this->Offset; }
|
||||
|
||||
uint32_t PDBStream::getLength() const { return this->StreamLength; }
|
@ -1,126 +0,0 @@
|
||||
//===- RawSession.cpp - Raw implementation of IPDBSession -------*- C++ -*-===//
|
||||
//
|
||||
// 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/RawSession.h"
|
||||
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
|
||||
#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
|
||||
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
|
||||
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
|
||||
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
|
||||
|
||||
#include "llvm/Support/ErrorOr.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
RawSession::RawSession(std::unique_ptr<PDBFile> PdbFile)
|
||||
: Pdb(std::move(PdbFile)) {}
|
||||
|
||||
RawSession::~RawSession() {}
|
||||
|
||||
PDB_ErrorCode RawSession::createFromPdb(StringRef Path,
|
||||
std::unique_ptr<IPDBSession> &Session) {
|
||||
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
|
||||
MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
|
||||
/*RequiresNullTerminator=*/false);
|
||||
|
||||
std::error_code EC;
|
||||
if ((EC = ErrorOrBuffer.getError()))
|
||||
return PDB_ErrorCode::CouldNotCreateImpl;
|
||||
|
||||
std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();
|
||||
|
||||
std::unique_ptr<PDBFile> File(new PDBFile(std::move(Buffer)));
|
||||
if ((EC = File->parseFileHeaders()))
|
||||
return PDB_ErrorCode::InvalidFileFormat;
|
||||
if ((EC = File->parseStreamData()))
|
||||
return PDB_ErrorCode::InvalidFileFormat;
|
||||
|
||||
Session.reset(new RawSession(std::move(File)));
|
||||
|
||||
return PDB_ErrorCode::Success;
|
||||
}
|
||||
|
||||
PDB_ErrorCode RawSession::createFromExe(StringRef Path,
|
||||
std::unique_ptr<IPDBSession> &Session) {
|
||||
return PDB_ErrorCode::CouldNotCreateImpl;
|
||||
}
|
||||
|
||||
uint64_t RawSession::getLoadAddress() const { return 0; }
|
||||
|
||||
void RawSession::setLoadAddress(uint64_t Address) {}
|
||||
|
||||
std::unique_ptr<PDBSymbolExe> RawSession::getGlobalScope() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<PDBSymbol> RawSession::getSymbolById(uint32_t SymbolId) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<PDBSymbol>
|
||||
RawSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumLineNumbers>
|
||||
RawSession::findLineNumbers(const PDBSymbolCompiland &Compiland,
|
||||
const IPDBSourceFile &File) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumLineNumbers>
|
||||
RawSession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumSourceFiles>
|
||||
RawSession::findSourceFiles(const PDBSymbolCompiland *Compiland,
|
||||
llvm::StringRef Pattern,
|
||||
PDB_NameSearchFlags Flags) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBSourceFile>
|
||||
RawSession::findOneSourceFile(const PDBSymbolCompiland *Compiland,
|
||||
llvm::StringRef Pattern,
|
||||
PDB_NameSearchFlags Flags) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
|
||||
RawSession::findCompilandsForSourceFile(llvm::StringRef Pattern,
|
||||
PDB_NameSearchFlags Flags) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<PDBSymbolCompiland>
|
||||
RawSession::findOneCompilandForSourceFile(llvm::StringRef Pattern,
|
||||
PDB_NameSearchFlags Flags) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumSourceFiles> RawSession::getAllSourceFiles() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumSourceFiles> RawSession::getSourceFilesForCompiland(
|
||||
const PDBSymbolCompiland &Compiland) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBSourceFile>
|
||||
RawSession::getSourceFileById(uint32_t FileId) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumDataStreams> RawSession::getDebugStreams() const {
|
||||
return nullptr;
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
; CHECK-NEXT: Version: 20000404
|
||||
; CHECK-NEXT: Signature: 54e507e2
|
||||
; CHECK-NEXT: Age: 1
|
||||
; CHECK-NEXT: Guid: {0B355641-86A0-A249-896F-9988FAE52FF0}
|
||||
; CHECK-NEXT: Guid: b 35 56 41 86 a0 a2 49 89 6f 99 88 fa e5 2f f0
|
||||
; CHECK-NEXT: NumberOfBytes: 34
|
||||
; CHECK-NEXT: HashSize: 3
|
||||
; CHECK-NEXT: MaxNumberOfStrings: 6
|
||||
|
@ -10,7 +10,6 @@
|
||||
#ifndef LLVM_TOOLS_LLVMPDBDUMP_BUILTINDUMPER_H
|
||||
#define LLVM_TOOLS_LLVMPDBDUMP_BUILTINDUMPER_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
|
||||
|
||||
namespace llvm {
|
||||
|
@ -35,9 +35,6 @@
|
||||
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
|
||||
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
|
||||
#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
|
||||
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
|
||||
#include "llvm/DebugInfo/PDB/Raw/PDBStream.h"
|
||||
#include "llvm/DebugInfo/PDB/Raw/RawSession.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/ConvertUTF.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
@ -46,8 +43,8 @@
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/PrettyStackTrace.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
#include "llvm/Support/Signals.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/Signals.h"
|
||||
|
||||
#if defined(HAVE_DIA_SDK)
|
||||
#ifndef NOMINMAX
|
||||
@ -155,32 +152,186 @@ static void reportError(StringRef Input, std::error_code EC) {
|
||||
reportError(Input, EC.message());
|
||||
}
|
||||
|
||||
static void dumpStructure(RawSession &RS) {
|
||||
PDBFile &File = RS.getPDBFile();
|
||||
static std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr,
|
||||
const uint64_t Size) {
|
||||
if (Addr + Size < Addr || Addr + Size < Size ||
|
||||
Addr + Size > uintptr_t(M.getBufferEnd()) ||
|
||||
Addr < uintptr_t(M.getBufferStart())) {
|
||||
return std::make_error_code(std::errc::bad_address);
|
||||
}
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
if (opts::DumpHeaders) {
|
||||
outs() << "BlockSize: " << File.getBlockSize() << '\n';
|
||||
outs() << "Unknown0: " << File.getUnknown0() << '\n';
|
||||
outs() << "NumBlocks: " << File.getBlockCount() << '\n';
|
||||
outs() << "NumDirectoryBytes: " << File.getNumDirectoryBytes() << '\n';
|
||||
outs() << "Unknown1: " << File.getUnknown1() << '\n';
|
||||
outs() << "BlockMapAddr: " << File.getBlockMapIndex() << '\n';
|
||||
template <typename T>
|
||||
static std::error_code checkOffset(MemoryBufferRef M, ArrayRef<T> AR) {
|
||||
return checkOffset(M, uintptr_t(AR.data()), (uint64_t)AR.size() * sizeof(T));
|
||||
}
|
||||
|
||||
static std::error_code checkOffset(MemoryBufferRef M, StringRef SR) {
|
||||
return checkOffset(M, uintptr_t(SR.data()), SR.size());
|
||||
}
|
||||
|
||||
// Sets Obj unless any bytes in [addr, addr + size) fall outsize of m.
|
||||
// Returns unexpected_eof if error.
|
||||
template <typename T>
|
||||
static std::error_code getObject(const T *&Obj, MemoryBufferRef M,
|
||||
const void *Ptr,
|
||||
const uint64_t Size = sizeof(T)) {
|
||||
uintptr_t Addr = uintptr_t(Ptr);
|
||||
if (std::error_code EC = checkOffset(M, Addr, Size))
|
||||
return EC;
|
||||
Obj = reinterpret_cast<const T *>(Addr);
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
static uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize) {
|
||||
return alignTo(NumBytes, BlockSize) / BlockSize;
|
||||
}
|
||||
|
||||
static uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize) {
|
||||
return BlockNumber * BlockSize;
|
||||
}
|
||||
|
||||
struct PDBStructureContext {
|
||||
const PDB::SuperBlock *SB;
|
||||
MemoryBufferRef M;
|
||||
std::vector<uint32_t> StreamSizes;
|
||||
DenseMap<uint32_t, std::vector<uint32_t>> StreamMap;
|
||||
|
||||
SmallVector<char, 512> Scratch;
|
||||
|
||||
// getObject tries to stitch together non-contiguous blocks into a contiguous
|
||||
// value. The storage for the value comes from the memory mapped file if the
|
||||
// memory would be contiguous. Otherwise, it uses 'Scratch' to buffer the
|
||||
// data.
|
||||
template <typename T>
|
||||
void getObject(const T *&Obj, uint32_t StreamIdx, uint32_t &Offset) {
|
||||
// Make sure the stream index is valid.
|
||||
auto StreamBlockI = StreamMap.find(StreamIdx);
|
||||
if (StreamBlockI == StreamMap.end())
|
||||
reportError(M.getBufferIdentifier(),
|
||||
std::make_error_code(std::errc::bad_address));
|
||||
|
||||
auto &StreamBlocks = StreamBlockI->second;
|
||||
uint32_t BlockNum = Offset / SB->BlockSize;
|
||||
uint32_t OffsetInBlock = Offset % SB->BlockSize;
|
||||
|
||||
// Make sure we aren't trying to read beyond the end of the stream.
|
||||
if (Offset + sizeof(T) > StreamSizes[StreamIdx])
|
||||
reportError(M.getBufferIdentifier(),
|
||||
std::make_error_code(std::errc::bad_address));
|
||||
|
||||
// Modify the passed in offset to point to the data after the object.
|
||||
Offset += sizeof(T);
|
||||
|
||||
// Handle the contiguous case: the offset + size stays within a block.
|
||||
if (OffsetInBlock + sizeof(T) <= SB->BlockSize) {
|
||||
uint32_t StreamBlockAddr = StreamBlocks[BlockNum];
|
||||
uint64_t StreamBlockOffset =
|
||||
blockToOffset(StreamBlockAddr, SB->BlockSize) + OffsetInBlock;
|
||||
// Return a pointer to the memory buffer.
|
||||
Obj = reinterpret_cast<const T *>(M.getBufferStart() + StreamBlockOffset);
|
||||
return;
|
||||
}
|
||||
|
||||
// The non-contiguous case: we will stitch together non-contiguous chunks
|
||||
// into the scratch buffer.
|
||||
Scratch.clear();
|
||||
|
||||
uint32_t BytesLeft = sizeof(T);
|
||||
while (BytesLeft > 0) {
|
||||
uint32_t StreamBlockAddr = StreamBlocks[BlockNum];
|
||||
uint64_t StreamBlockOffset =
|
||||
blockToOffset(StreamBlockAddr, SB->BlockSize) + OffsetInBlock;
|
||||
|
||||
const char *ChunkStart =
|
||||
M.getBufferStart() + StreamBlockOffset;
|
||||
uint32_t BytesInChunk =
|
||||
std::min(BytesLeft, SB->BlockSize - OffsetInBlock);
|
||||
Scratch.append(ChunkStart, ChunkStart + BytesInChunk);
|
||||
|
||||
BytesLeft -= BytesInChunk;
|
||||
++BlockNum;
|
||||
OffsetInBlock = 0;
|
||||
}
|
||||
|
||||
// Return a pointer to the scratch buffer.
|
||||
Obj = reinterpret_cast<const T *>(Scratch.data());
|
||||
}
|
||||
|
||||
if (opts::DumpHeaders)
|
||||
outs() << "NumDirectoryBlocks: " << File.getNumDirectoryBlocks() << '\n';
|
||||
template <typename T>
|
||||
T getInt(uint32_t StreamIdx, uint32_t &Offset) {
|
||||
const support::detail::packed_endian_specific_integral<
|
||||
T, support::little, support::unaligned> *P;
|
||||
getObject(P, StreamIdx, Offset);
|
||||
return *P;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T getObject(uint32_t StreamIdx, uint32_t &Offset) {
|
||||
const T *P;
|
||||
getObject(P, StreamIdx, Offset);
|
||||
return *P;
|
||||
}
|
||||
};
|
||||
|
||||
static void dumpStructure(MemoryBufferRef M) {
|
||||
const PDB::SuperBlock *SB;
|
||||
|
||||
auto Error = [&](std::error_code EC) {
|
||||
if (EC)
|
||||
reportError(M.getBufferIdentifier(), EC);
|
||||
};
|
||||
|
||||
Error(getObject(SB, M, M.getBufferStart()));
|
||||
|
||||
if (opts::DumpHeaders) {
|
||||
outs() << "BlockSize: " << SB->BlockSize << '\n';
|
||||
outs() << "Unknown0: " << SB->Unknown0 << '\n';
|
||||
outs() << "NumBlocks: " << SB->NumBlocks << '\n';
|
||||
outs() << "NumDirectoryBytes: " << SB->NumDirectoryBytes << '\n';
|
||||
outs() << "Unknown1: " << SB->Unknown1 << '\n';
|
||||
outs() << "BlockMapAddr: " << SB->BlockMapAddr << '\n';
|
||||
}
|
||||
|
||||
// We don't support blocksizes which aren't a multiple of four bytes.
|
||||
if (SB->BlockSize % sizeof(support::ulittle32_t) != 0)
|
||||
Error(std::make_error_code(std::errc::not_supported));
|
||||
|
||||
// We don't support directories whose sizes aren't a multiple of four bytes.
|
||||
if (SB->NumDirectoryBytes % sizeof(support::ulittle32_t) != 0)
|
||||
Error(std::make_error_code(std::errc::not_supported));
|
||||
|
||||
// The number of blocks which comprise the directory is a simple function of
|
||||
// the number of bytes it contains.
|
||||
uint64_t NumDirectoryBlocks =
|
||||
bytesToBlocks(SB->NumDirectoryBytes, SB->BlockSize);
|
||||
if (opts::DumpHeaders)
|
||||
outs() << "BlockMapOffset: " << File.getBlockMapOffset() << '\n';
|
||||
outs() << "NumDirectoryBlocks: " << NumDirectoryBlocks << '\n';
|
||||
|
||||
// The block map, as we understand it, is a block which consists of a list of
|
||||
// block numbers.
|
||||
// It is unclear what would happen if the number of blocks couldn't fit on a
|
||||
// single block.
|
||||
if (NumDirectoryBlocks > SB->BlockSize / sizeof(support::ulittle32_t))
|
||||
Error(std::make_error_code(std::errc::illegal_byte_sequence));
|
||||
|
||||
uint64_t BlockMapOffset = (uint64_t)SB->BlockMapAddr * SB->BlockSize;
|
||||
if (opts::DumpHeaders)
|
||||
outs() << "BlockMapOffset: " << BlockMapOffset << '\n';
|
||||
|
||||
// The directory is not contiguous. Instead, the block map contains a
|
||||
// contiguous list of block numbers whose contents, when concatenated in
|
||||
// order, make up the directory.
|
||||
auto DirectoryBlocks = File.getDirectoryBlockArray();
|
||||
auto DirectoryBlocks =
|
||||
makeArrayRef(reinterpret_cast<const support::ulittle32_t *>(
|
||||
M.getBufferStart() + BlockMapOffset),
|
||||
NumDirectoryBlocks);
|
||||
Error(checkOffset(M, DirectoryBlocks));
|
||||
|
||||
if (opts::DumpHeaders) {
|
||||
outs() << "DirectoryBlocks: [";
|
||||
for (const uint32_t &DirectoryBlockAddr : DirectoryBlocks) {
|
||||
for (const support::ulittle32_t &DirectoryBlockAddr : DirectoryBlocks) {
|
||||
if (&DirectoryBlockAddr != &DirectoryBlocks.front())
|
||||
outs() << ", ";
|
||||
outs() << DirectoryBlockAddr;
|
||||
@ -188,23 +339,96 @@ static void dumpStructure(RawSession &RS) {
|
||||
outs() << "]\n";
|
||||
}
|
||||
|
||||
if (opts::DumpHeaders)
|
||||
outs() << "NumStreams: " << File.getNumStreams() << '\n';
|
||||
uint32_t StreamCount = File.getNumStreams();
|
||||
if (opts::DumpStreamSizes) {
|
||||
for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx)
|
||||
outs() << "StreamSizes[" << StreamIdx
|
||||
<< "]: " << File.getStreamByteSize(StreamIdx) << '\n';
|
||||
bool SeenNumStreams = false;
|
||||
uint32_t NumStreams = 0;
|
||||
uint32_t StreamIdx = 0;
|
||||
uint64_t DirectoryBytesRead = 0;
|
||||
PDBStructureContext Ctx;
|
||||
Ctx.SB = SB;
|
||||
Ctx.M = M;
|
||||
// The structure of the directory is as follows:
|
||||
// struct PDBDirectory {
|
||||
// uint32_t NumStreams;
|
||||
// uint32_t StreamSizes[NumStreams];
|
||||
// uint32_t StreamMap[NumStreams][];
|
||||
// };
|
||||
//
|
||||
// Empty streams don't consume entries in the StreamMap.
|
||||
for (uint32_t DirectoryBlockAddr : DirectoryBlocks) {
|
||||
uint64_t DirectoryBlockOffset =
|
||||
blockToOffset(DirectoryBlockAddr, SB->BlockSize);
|
||||
auto DirectoryBlock =
|
||||
makeArrayRef(reinterpret_cast<const support::ulittle32_t *>(
|
||||
M.getBufferStart() + DirectoryBlockOffset),
|
||||
SB->BlockSize / sizeof(support::ulittle32_t));
|
||||
Error(checkOffset(M, DirectoryBlock));
|
||||
|
||||
// We read data out of the directory four bytes at a time. Depending on
|
||||
// where we are in the directory, the contents may be: the number of streams
|
||||
// in the directory, a stream's size, or a block in the stream map.
|
||||
for (uint32_t Data : DirectoryBlock) {
|
||||
// Don't read beyond the end of the directory.
|
||||
if (DirectoryBytesRead == SB->NumDirectoryBytes)
|
||||
break;
|
||||
|
||||
DirectoryBytesRead += sizeof(Data);
|
||||
|
||||
// This data must be the number of streams if we haven't seen it yet.
|
||||
if (!SeenNumStreams) {
|
||||
NumStreams = Data;
|
||||
SeenNumStreams = true;
|
||||
continue;
|
||||
}
|
||||
// This data must be a stream size if we have not seen them all yet.
|
||||
if (Ctx.StreamSizes.size() < NumStreams) {
|
||||
// It seems like some streams have their set to -1 when their contents
|
||||
// are not present. Treat them like empty streams for now.
|
||||
if (Data == UINT32_MAX)
|
||||
Ctx.StreamSizes.push_back(0);
|
||||
else
|
||||
Ctx.StreamSizes.push_back(Data);
|
||||
continue;
|
||||
}
|
||||
|
||||
// This data must be a stream block number if we have seen all of the
|
||||
// stream sizes.
|
||||
std::vector<uint32_t> *StreamBlocks = nullptr;
|
||||
// Figure out which stream this block number belongs to.
|
||||
while (StreamIdx < NumStreams) {
|
||||
uint64_t NumExpectedStreamBlocks =
|
||||
bytesToBlocks(Ctx.StreamSizes[StreamIdx], SB->BlockSize);
|
||||
StreamBlocks = &Ctx.StreamMap[StreamIdx];
|
||||
if (NumExpectedStreamBlocks > StreamBlocks->size())
|
||||
break;
|
||||
++StreamIdx;
|
||||
}
|
||||
// It seems this block doesn't belong to any stream? The stream is either
|
||||
// corrupt or something more mysterious is going on.
|
||||
if (StreamIdx == NumStreams)
|
||||
Error(std::make_error_code(std::errc::illegal_byte_sequence));
|
||||
|
||||
StreamBlocks->push_back(Data);
|
||||
}
|
||||
}
|
||||
|
||||
// We should have read exactly SB->NumDirectoryBytes bytes.
|
||||
assert(DirectoryBytesRead == SB->NumDirectoryBytes);
|
||||
|
||||
if (opts::DumpHeaders)
|
||||
outs() << "NumStreams: " << NumStreams << '\n';
|
||||
if (opts::DumpStreamSizes)
|
||||
for (uint32_t StreamIdx = 0; StreamIdx < NumStreams; ++StreamIdx)
|
||||
outs() << "StreamSizes[" << StreamIdx
|
||||
<< "]: " << Ctx.StreamSizes[StreamIdx] << '\n';
|
||||
|
||||
if (opts::DumpStreamBlocks) {
|
||||
for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
|
||||
for (uint32_t StreamIdx = 0; StreamIdx < NumStreams; ++StreamIdx) {
|
||||
outs() << "StreamBlocks[" << StreamIdx << "]: [";
|
||||
auto StreamBlocks = File.getStreamBlockList(StreamIdx);
|
||||
for (size_t i = 0; i < StreamBlocks.size(); ++i) {
|
||||
if (i != 0)
|
||||
std::vector<uint32_t> &StreamBlocks = Ctx.StreamMap[StreamIdx];
|
||||
for (uint32_t &StreamBlock : StreamBlocks) {
|
||||
if (&StreamBlock != &StreamBlocks.front())
|
||||
outs() << ", ";
|
||||
outs() << StreamBlocks[i];
|
||||
outs() << StreamBlock;
|
||||
}
|
||||
outs() << "]\n";
|
||||
}
|
||||
@ -213,107 +437,103 @@ static void dumpStructure(RawSession &RS) {
|
||||
StringRef DumpStreamStr = opts::DumpStreamData;
|
||||
uint32_t DumpStreamNum;
|
||||
if (!DumpStreamStr.getAsInteger(/*Radix=*/0U, DumpStreamNum) &&
|
||||
DumpStreamNum < StreamCount) {
|
||||
DumpStreamNum < NumStreams) {
|
||||
uint32_t StreamBytesRead = 0;
|
||||
uint32_t StreamSize = File.getStreamByteSize(DumpStreamNum);
|
||||
auto StreamBlocks = File.getStreamBlockList(DumpStreamNum);
|
||||
|
||||
for (uint32_t StreamBlockAddr : StreamBlocks) {
|
||||
uint32_t StreamSize = Ctx.StreamSizes[DumpStreamNum];
|
||||
std::vector<uint32_t> &StreamBlocks = Ctx.StreamMap[DumpStreamNum];
|
||||
for (uint32_t &StreamBlockAddr : StreamBlocks) {
|
||||
uint64_t StreamBlockOffset = blockToOffset(StreamBlockAddr, SB->BlockSize);
|
||||
uint32_t BytesLeftToReadInStream = StreamSize - StreamBytesRead;
|
||||
if (BytesLeftToReadInStream == 0)
|
||||
break;
|
||||
|
||||
uint32_t BytesToReadInBlock = std::min(
|
||||
BytesLeftToReadInStream, static_cast<uint32_t>(File.getBlockSize()));
|
||||
BytesLeftToReadInStream, static_cast<uint32_t>(SB->BlockSize));
|
||||
auto StreamBlockData =
|
||||
File.getBlockData(StreamBlockAddr, BytesToReadInBlock);
|
||||
StringRef(M.getBufferStart() + StreamBlockOffset, BytesToReadInBlock);
|
||||
Error(checkOffset(M, StreamBlockData));
|
||||
|
||||
outs() << StreamBlockData;
|
||||
StreamBytesRead += StreamBlockData.size();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Offset = 0;
|
||||
|
||||
// Stream 1 starts with the following header:
|
||||
// uint32_t Version;
|
||||
// uint32_t Signature;
|
||||
// uint32_t Age;
|
||||
// GUID Guid;
|
||||
PDBStream Stream1(1, File);
|
||||
uint32_t Version;
|
||||
uint32_t Signature;
|
||||
uint32_t Age;
|
||||
PDB_UniqueId Guid;
|
||||
|
||||
Stream1.readInteger(Version);
|
||||
auto Version = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);
|
||||
outs() << "Version: " << Version << '\n';
|
||||
|
||||
// PDB's with versions before PDBImpvVC70 might not have the Guid field, we
|
||||
// don't support them.
|
||||
if (Version < 20000404)
|
||||
reportError("", std::make_error_code(std::errc::not_supported));
|
||||
Error(std::make_error_code(std::errc::not_supported));
|
||||
|
||||
// This appears to be the time the PDB was last opened by an MSVC tool?
|
||||
// It is definitely a timestamp of some sort.
|
||||
Stream1.readInteger(Signature);
|
||||
auto Signature = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);
|
||||
outs() << "Signature: ";
|
||||
outs().write_hex(Signature) << '\n';
|
||||
|
||||
// This appears to be a number which is used to determine that the PDB is kept
|
||||
// in sync with the EXE.
|
||||
Stream1.readInteger(Age);
|
||||
auto Age = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);
|
||||
outs() << "Age: " << Age << '\n';
|
||||
|
||||
// I'm not sure what the purpose of the GUID is.
|
||||
Stream1.readObject(&Guid);
|
||||
outs() << "Guid: " << Guid << '\n';
|
||||
using GuidTy = char[16];
|
||||
const GuidTy *Guid;
|
||||
Ctx.getObject(Guid, /*PDBStream=*/1, Offset);
|
||||
outs() << "Guid: ";
|
||||
for (char C : *Guid)
|
||||
outs().write_hex(C & 0xff) << ' ';
|
||||
outs() << '\n';
|
||||
|
||||
// This is some sort of weird string-set/hash table encoded in the stream.
|
||||
// It starts with the number of bytes in the table.
|
||||
uint32_t NumberOfBytes;
|
||||
Stream1.readInteger(NumberOfBytes);
|
||||
auto NumberOfBytes = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);
|
||||
outs() << "NumberOfBytes: " << NumberOfBytes << '\n';
|
||||
|
||||
// Following that field is the starting offset of strings in the name table.
|
||||
uint32_t StringsOffset = Stream1.getOffset();
|
||||
Stream1.setOffset(StringsOffset + NumberOfBytes);
|
||||
uint32_t StringsOffset = Offset;
|
||||
Offset += NumberOfBytes;
|
||||
|
||||
// This appears to be equivalent to the total number of strings *actually*
|
||||
// in the name table.
|
||||
uint32_t HashSize;
|
||||
Stream1.readInteger(HashSize);
|
||||
auto HashSize = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);
|
||||
outs() << "HashSize: " << HashSize << '\n';
|
||||
|
||||
// This appears to be an upper bound on the number of strings in the name
|
||||
// table.
|
||||
uint32_t MaxNumberOfStrings;
|
||||
Stream1.readInteger(MaxNumberOfStrings);
|
||||
auto MaxNumberOfStrings = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);
|
||||
outs() << "MaxNumberOfStrings: " << MaxNumberOfStrings << '\n';
|
||||
|
||||
// This appears to be a hash table which uses bitfields to determine whether
|
||||
// or not a bucket is 'present'.
|
||||
uint32_t NumPresentWords;
|
||||
Stream1.readInteger(NumPresentWords);
|
||||
auto NumPresentWords = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);
|
||||
outs() << "NumPresentWords: " << NumPresentWords << '\n';
|
||||
|
||||
// Store all the 'present' bits in a vector for later processing.
|
||||
SmallVector<uint32_t, 1> PresentWords;
|
||||
for (uint32_t I = 0; I != NumPresentWords; ++I) {
|
||||
uint32_t Word;
|
||||
Stream1.readInteger(Word);
|
||||
auto Word = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);
|
||||
PresentWords.push_back(Word);
|
||||
outs() << "Word: " << Word << '\n';
|
||||
}
|
||||
|
||||
// This appears to be a hash table which uses bitfields to determine whether
|
||||
// or not a bucket is 'deleted'.
|
||||
uint32_t NumDeletedWords;
|
||||
Stream1.readInteger(NumDeletedWords);
|
||||
auto NumDeletedWords = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);
|
||||
outs() << "NumDeletedWords: " << NumDeletedWords << '\n';
|
||||
|
||||
// Store all the 'deleted' bits in a vector for later processing.
|
||||
SmallVector<uint32_t, 1> DeletedWords;
|
||||
for (uint32_t I = 0; I != NumDeletedWords; ++I) {
|
||||
uint32_t Word;
|
||||
Stream1.readInteger(Word);
|
||||
auto Word = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);
|
||||
DeletedWords.push_back(Word);
|
||||
outs() << "Word: " << Word << '\n';
|
||||
}
|
||||
@ -334,25 +554,26 @@ static void dumpStructure(RawSession &RS) {
|
||||
|
||||
// This appears to be an offset relative to the start of the strings.
|
||||
// It tells us where the null-terminated string begins.
|
||||
uint32_t NameOffset;
|
||||
Stream1.readInteger(NameOffset);
|
||||
auto NameOffset = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);
|
||||
outs() << "NameOffset: " << NameOffset << '\n';
|
||||
|
||||
// This appears to be a stream number into the stream directory.
|
||||
uint32_t NameIndex;
|
||||
Stream1.readInteger(NameIndex);
|
||||
auto NameIndex = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);
|
||||
outs() << "NameIndex: " << NameIndex << '\n';
|
||||
|
||||
// Compute the offset of the start of the string relative to the stream.
|
||||
uint32_t StringOffset = StringsOffset + NameOffset;
|
||||
uint32_t OldOffset = Stream1.getOffset();
|
||||
|
||||
// Pump out our c-string from the stream.
|
||||
std::string Str;
|
||||
Stream1.setOffset(StringOffset);
|
||||
Stream1.readZeroString(Str);
|
||||
SmallString<8> Str;
|
||||
char C;
|
||||
do {
|
||||
C = Ctx.getObject<char>(/*PDBStream=*/1, StringOffset);
|
||||
if (C != '\0')
|
||||
Str += C;
|
||||
} while (C != '\0');
|
||||
outs() << "String: " << Str << "\n\n";
|
||||
|
||||
Stream1.setOffset(OldOffset);
|
||||
// Add this to a string-map from name to stream number.
|
||||
NamedStreams.insert({Str, NameIndex});
|
||||
}
|
||||
@ -360,38 +581,45 @@ static void dumpStructure(RawSession &RS) {
|
||||
// Let's try to dump out the named stream "/names".
|
||||
auto NameI = NamedStreams.find("/names");
|
||||
if (NameI != NamedStreams.end()) {
|
||||
PDBStream NameStream(NameI->second, File);
|
||||
outs() << "NameStream: " << NameI->second << '\n';
|
||||
uint32_t NameStream = NameI->second;
|
||||
outs() << "NameStream: " << NameStream << '\n';
|
||||
|
||||
uint32_t NameStreamOffset = 0;
|
||||
|
||||
// The name stream appears to start with a signature and version.
|
||||
uint32_t NameStreamSignature;
|
||||
NameStream.readInteger(NameStreamSignature);
|
||||
auto NameStreamSignature =
|
||||
Ctx.getInt<uint32_t>(/*PDBStream=*/NameStream, NameStreamOffset);
|
||||
outs() << "NameStreamSignature: ";
|
||||
outs().write_hex(NameStreamSignature) << '\n';
|
||||
|
||||
uint32_t NameStreamVersion;
|
||||
NameStream.readInteger(NameStreamVersion);
|
||||
auto NameStreamVersion =
|
||||
Ctx.getInt<uint32_t>(/*PDBStream=*/NameStream, NameStreamOffset);
|
||||
outs() << "NameStreamVersion: " << NameStreamVersion << '\n';
|
||||
|
||||
// We only support this particular version of the name stream.
|
||||
if (NameStreamSignature != 0xeffeeffe || NameStreamVersion != 1)
|
||||
reportError("", std::make_error_code(std::errc::not_supported));
|
||||
Error(std::make_error_code(std::errc::not_supported));
|
||||
}
|
||||
}
|
||||
|
||||
static void dumpInput(StringRef Path) {
|
||||
std::unique_ptr<IPDBSession> Session;
|
||||
if (opts::DumpHeaders || !opts::DumpStreamData.empty()) {
|
||||
PDB_ErrorCode Error = loadDataForPDB(PDB_ReaderType::Raw, Path, Session);
|
||||
if (Error == PDB_ErrorCode::Success) {
|
||||
RawSession *RS = static_cast<RawSession *>(Session.get());
|
||||
dumpStructure(*RS);
|
||||
}
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
|
||||
MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
|
||||
/*RequiresNullTerminator=*/false);
|
||||
|
||||
if (std::error_code EC = ErrorOrBuffer.getError())
|
||||
reportError(Path, EC);
|
||||
|
||||
std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();
|
||||
|
||||
dumpStructure(Buffer->getMemBufferRef());
|
||||
|
||||
outs().flush();
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBSession> Session;
|
||||
PDB_ErrorCode Error = loadDataForPDB(PDB_ReaderType::DIA, Path, Session);
|
||||
switch (Error) {
|
||||
case PDB_ErrorCode::Success:
|
||||
|
Loading…
x
Reference in New Issue
Block a user