[llvm] r267071 - Fix PDB warnings and test
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 21 15:37:55 PDT 2016
Author: rnk
Date: Thu Apr 21 17:37:55 2016
New Revision: 267071
URL: http://llvm.org/viewvc/llvm-project?rev=267071&view=rev
Log:
Fix PDB warnings and test
Modified:
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp
llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h?rev=267071&r1=267070&r2=267071&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h Thu Apr 21 17:37:55 2016
@@ -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;
};
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp?rev=267071&r1=267070&r2=267071&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp Thu Apr 21 17:37:55 2016
@@ -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(MemoryBuffer
}
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::parseFileHeader
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);
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp?rev=267071&r1=267070&r2=267071&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp Thu Apr 21 17:37:55 2016
@@ -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(voi
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());
Modified: llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp?rev=267071&r1=267070&r2=267071&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp Thu Apr 21 17:37:55 2016
@@ -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';
}
More information about the llvm-commits
mailing list