mirror of
https://github.com/RPCS3/llvm.git
synced 2025-05-13 17:06:15 +00:00
Fix PDB warnings and test
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267071 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4913b3f2cf
commit
a1d19be01d
@ -12,6 +12,7 @@
|
||||
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/Support/Endian.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -45,6 +46,14 @@ public:
|
||||
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;
|
||||
};
|
||||
|
@ -50,8 +50,7 @@ struct llvm::PDBContext {
|
||||
DenseMap<uint32_t, std::vector<uint32_t>> StreamMap;
|
||||
};
|
||||
|
||||
namespace {
|
||||
std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr,
|
||||
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()) ||
|
||||
@ -62,19 +61,10 @@ std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr,
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::error_code checkOffset(MemoryBufferRef M, ArrayRef<T> AR) {
|
||||
static std::error_code checkOffset(MemoryBufferRef M, ArrayRef<T> AR) {
|
||||
return checkOffset(M, uintptr_t(AR.data()), (uint64_t)AR.size() * sizeof(T));
|
||||
}
|
||||
|
||||
uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize) {
|
||||
return alignTo(NumBytes, BlockSize) / BlockSize;
|
||||
}
|
||||
|
||||
uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize) {
|
||||
return BlockNumber * BlockSize;
|
||||
}
|
||||
}
|
||||
|
||||
PDBFile::PDBFile(std::unique_ptr<MemoryBuffer> MemBuffer) {
|
||||
Context.reset(new PDBContext());
|
||||
Context->Buffer = std::move(MemBuffer);
|
||||
@ -130,6 +120,10 @@ std::error_code PDBFile::parseFileHeaders() {
|
||||
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);
|
||||
|
@ -12,14 +12,6 @@
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
PDBStream::PDBStream(uint32_t StreamIdx, const PDBFile &File) : Pdb(File) {
|
||||
this->StreamLength = Pdb.getStreamByteSize(StreamIdx);
|
||||
this->BlockList = Pdb.getStreamBlockList(StreamIdx);
|
||||
@ -73,7 +65,8 @@ std::error_code PDBStream::readBytes(void *Dest, uint32_t Length) {
|
||||
while (BytesLeft > 0) {
|
||||
uint32_t StreamBlockAddr = this->BlockList[BlockNum];
|
||||
uint64_t StreamBlockOffset =
|
||||
blockToOffset(StreamBlockAddr, Pdb.getBlockSize()) + OffsetInBlock;
|
||||
PDBFile::blockToOffset(StreamBlockAddr, Pdb.getBlockSize()) +
|
||||
OffsetInBlock;
|
||||
|
||||
StringRef Data = Pdb.getBlockData(StreamBlockAddr, Pdb.getBlockSize());
|
||||
|
||||
|
@ -192,7 +192,7 @@ static void dumpStructure(RawSession &RS) {
|
||||
outs() << "NumStreams: " << File.getNumStreams() << '\n';
|
||||
uint32_t StreamCount = File.getNumStreams();
|
||||
if (opts::DumpStreamSizes) {
|
||||
for (uint32_t StreamIdx = 0; StreamCount; ++StreamIdx)
|
||||
for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx)
|
||||
outs() << "StreamSizes[" << StreamIdx
|
||||
<< "]: " << File.getStreamByteSize(StreamIdx) << '\n';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user