summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/PDB
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2016-04-21 22:37:55 +0000
committerReid Kleckner <rnk@google.com>2016-04-21 22:37:55 +0000
commit5037674ae2d41705461b64b8d894f97ebd437ee4 (patch)
tree8bc6046d754c7ef23b1175cd81afc287c87d5816 /llvm/lib/DebugInfo/PDB
parent025191d42feb2636026efeb93d9f5b05de0571ea (diff)
downloadbcm5719-llvm-5037674ae2d41705461b64b8d894f97ebd437ee4.tar.gz
bcm5719-llvm-5037674ae2d41705461b64b8d894f97ebd437ee4.zip
Fix PDB warnings and test
llvm-svn: 267071
Diffstat (limited to 'llvm/lib/DebugInfo/PDB')
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp20
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/PDBStream.cpp11
2 files changed, 9 insertions, 22 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp
index fc5231f552b..12a717db49b 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp
@@ -50,9 +50,8 @@ struct llvm::PDBContext {
DenseMap<uint32_t, std::vector<uint32_t>> StreamMap;
};
-namespace {
-std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr,
- const uint64_t Size) {
+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())) {
@@ -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);
diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBStream.cpp
index 310454df824..c20ffc914d2 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/PDBStream.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/PDBStream.cpp
@@ -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());
OpenPOWER on IntegriCloud