summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-04-29 17:22:58 +0000
committerZachary Turner <zturner@google.com>2016-04-29 17:22:58 +0000
commit6ba65deeb9b017e4144cdae341dcb9e3564c7c7b (patch)
tree7b038a1cbb48d78056d0af5bd76f9a3ad44ea9d6 /llvm/include
parenteaaec4a4c85a81ee9169e1647b733d839159c648 (diff)
downloadbcm5719-llvm-6ba65deeb9b017e4144cdae341dcb9e3564c7c7b.tar.gz
bcm5719-llvm-6ba65deeb9b017e4144cdae341dcb9e3564c7c7b.zip
Refactor the PDB Stream reading interface.
The motivation for this change is that PDB has the notion of streams and substreams. Substreams often consist of variable length structures that are convenient to be able to treat as guaranteed, contiguous byte arrays, whereas the streams they are contained in are not necessarily so, as a single stream could be spread across many discontiguous blocks. So, when processing data from a substream, we want to be able to assume that we have a contiguous byte array so that we can cast pointers to variable length arrays and such. This leads to the question of how to be able to read the same data structure from either a stream or a substream using the same interface, which is where this patch comes in. We separate out the stream's read state from the underlying representation, and introduce a `StreamReader` class. Then we change the name of `PDBStream` to `MappedBlockStream`, and introduce a second kind of stream called a `ByteStream` which is simply a sequence of contiguous bytes. Finally, we update all of the std::vectors in `PDBDbiStream` to use `ByteStream` instead as a proof of concept. llvm-svn: 268071
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm/DebugInfo/PDB/Raw/ByteStream.h47
-rw-r--r--llvm/include/llvm/DebugInfo/PDB/Raw/MappedBlockStream.h38
-rw-r--r--llvm/include/llvm/DebugInfo/PDB/Raw/PDBDbiStream.h20
-rw-r--r--llvm/include/llvm/DebugInfo/PDB/Raw/PDBInfoStream.h4
-rw-r--r--llvm/include/llvm/DebugInfo/PDB/Raw/PDBNameMap.h4
-rw-r--r--llvm/include/llvm/DebugInfo/PDB/Raw/PDBStream.h46
-rw-r--r--llvm/include/llvm/DebugInfo/PDB/Raw/StreamInterface.h29
-rw-r--r--llvm/include/llvm/DebugInfo/PDB/Raw/StreamReader.h46
8 files changed, 175 insertions, 59 deletions
diff --git a/llvm/include/llvm/DebugInfo/PDB/Raw/ByteStream.h b/llvm/include/llvm/DebugInfo/PDB/Raw/ByteStream.h
new file mode 100644
index 00000000000..11b9366f73a
--- /dev/null
+++ b/llvm/include/llvm/DebugInfo/PDB/Raw/ByteStream.h
@@ -0,0 +1,47 @@
+//===- ByteStream.h - Reads stream data from a byte sequence ----*- 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_BYTESTREAM_H
+#define LLVM_DEBUGINFO_PDB_RAW_BYTESTREAM_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/DebugInfo/PDB/Raw/StreamInterface.h"
+
+#include <stdint.h>
+
+#include <system_error>
+#include <vector>
+
+namespace llvm {
+class StreamReader;
+class ByteStream : public StreamInterface {
+public:
+ ByteStream();
+ explicit ByteStream(MutableArrayRef<uint8_t> Bytes);
+ explicit ByteStream(uint32_t Length);
+ ~ByteStream() override;
+
+ void reset();
+ void initialize(MutableArrayRef<uint8_t> Bytes);
+ void initialize(uint32_t Length);
+ std::error_code initialize(StreamReader &Reader, uint32_t Length);
+
+ std::error_code readBytes(uint32_t Offset,
+ MutableArrayRef<uint8_t> Buffer) const override;
+ uint32_t getLength() const override;
+
+ ArrayRef<uint8_t> data() const { return Data; }
+
+private:
+ MutableArrayRef<uint8_t> Data;
+ bool Owned;
+};
+}
+
+#endif
diff --git a/llvm/include/llvm/DebugInfo/PDB/Raw/MappedBlockStream.h b/llvm/include/llvm/DebugInfo/PDB/Raw/MappedBlockStream.h
new file mode 100644
index 00000000000..74fae96ffdf
--- /dev/null
+++ b/llvm/include/llvm/DebugInfo/PDB/Raw/MappedBlockStream.h
@@ -0,0 +1,38 @@
+//===- MappedBlockStream.h - Reads stream data from a PDBFile ---*- 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_MAPPEDBLOCKSTREAM_H
+#define LLVM_DEBUGINFO_PDB_RAW_MAPPEDBLOCKSTREAM_H
+
+#include "llvm/DebugInfo/PDB/Raw/StreamInterface.h"
+
+#include <stdint.h>
+
+#include <system_error>
+#include <vector>
+
+namespace llvm {
+class PDBFile;
+
+class MappedBlockStream : public StreamInterface {
+public:
+ MappedBlockStream(uint32_t StreamIdx, const PDBFile &File);
+
+ std::error_code readBytes(uint32_t Offset,
+ MutableArrayRef<uint8_t> Buffer) const override;
+ uint32_t getLength() const override { return StreamLength; }
+
+private:
+ uint32_t StreamLength;
+ std::vector<uint32_t> BlockList;
+ const PDBFile &Pdb;
+};
+}
+
+#endif
diff --git a/llvm/include/llvm/DebugInfo/PDB/Raw/PDBDbiStream.h b/llvm/include/llvm/DebugInfo/PDB/Raw/PDBDbiStream.h
index eac7e4bbb75..0286e36f39f 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Raw/PDBDbiStream.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Raw/PDBDbiStream.h
@@ -11,9 +11,10 @@
#define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H
#include "llvm/DebugInfo/PDB/PDBTypes.h"
+#include "llvm/DebugInfo/PDB/Raw/ByteStream.h"
+#include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h"
#include "llvm/DebugInfo/PDB/Raw/ModInfo.h"
#include "llvm/DebugInfo/PDB/Raw/PDBRawConstants.h"
-#include "llvm/DebugInfo/PDB/Raw/PDBStream.h"
#include "llvm/Support/Endian.h"
namespace llvm {
@@ -46,20 +47,21 @@ public:
ArrayRef<ModuleInfoEx> modules() const;
private:
- std::error_code readSubstream(std::vector<uint8_t> &Bytes, uint32_t Size);
std::error_code initializeFileInfo();
PDBFile &Pdb;
- PDBStream Stream;
+ MappedBlockStream Stream;
std::vector<ModuleInfoEx> ModuleInfos;
- std::vector<uint8_t> ModInfoSubstream;
- std::vector<uint8_t> SecContrSubstream;
- std::vector<uint8_t> SecMapSubstream;
- std::vector<uint8_t> FileInfoSubstream;
- std::vector<uint8_t> TypeServerMapSubstream;
- std::vector<uint8_t> ECSubstream;
+ ByteStream ModInfoSubstream;
+ ByteStream SecContrSubstream;
+ ByteStream SecMapSubstream;
+ ByteStream FileInfoSubstream;
+ ByteStream TypeServerMapSubstream;
+ ByteStream ECSubstream;
+ ByteStream DbgHeader;
+
std::unique_ptr<HeaderInfo> Header;
};
}
diff --git a/llvm/include/llvm/DebugInfo/PDB/Raw/PDBInfoStream.h b/llvm/include/llvm/DebugInfo/PDB/Raw/PDBInfoStream.h
index ed914348d9f..0887c28910e 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Raw/PDBInfoStream.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Raw/PDBInfoStream.h
@@ -12,9 +12,9 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/DebugInfo/PDB/PDBTypes.h"
+#include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h"
#include "llvm/DebugInfo/PDB/Raw/PDBNameMap.h"
#include "llvm/DebugInfo/PDB/Raw/PDBRawConstants.h"
-#include "llvm/DebugInfo/PDB/Raw/PDBStream.h"
#include "llvm/Support/Endian.h"
@@ -37,7 +37,7 @@ public:
private:
PDBFile &Pdb;
- PDBStream Stream1;
+ MappedBlockStream Stream;
// PDB file format version. We only support VC70. See the enumeration
// `PdbRaw_ImplVer` for the other possible values.
diff --git a/llvm/include/llvm/DebugInfo/PDB/Raw/PDBNameMap.h b/llvm/include/llvm/DebugInfo/PDB/Raw/PDBNameMap.h
index c747e499689..3f4aea41767 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Raw/PDBNameMap.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Raw/PDBNameMap.h
@@ -17,12 +17,12 @@
#include <utility>
namespace llvm {
-class PDBStream;
+class StreamReader;
class PDBNameMap {
public:
PDBNameMap();
- std::error_code load(PDBStream &Stream);
+ std::error_code load(StreamReader &Stream);
bool tryGetValue(StringRef Name, uint32_t &Value) const;
diff --git a/llvm/include/llvm/DebugInfo/PDB/Raw/PDBStream.h b/llvm/include/llvm/DebugInfo/PDB/Raw/PDBStream.h
deleted file mode 100644
index 0f71e81cf2e..00000000000
--- a/llvm/include/llvm/DebugInfo/PDB/Raw/PDBStream.h
+++ /dev/null
@@ -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
diff --git a/llvm/include/llvm/DebugInfo/PDB/Raw/StreamInterface.h b/llvm/include/llvm/DebugInfo/PDB/Raw/StreamInterface.h
new file mode 100644
index 00000000000..6f235049d7e
--- /dev/null
+++ b/llvm/include/llvm/DebugInfo/PDB/Raw/StreamInterface.h
@@ -0,0 +1,29 @@
+//===- StreamInterface.h - Base interface for 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_STREAMINTERFACE_H
+#define LLVM_DEBUGINFO_PDB_RAW_STREAMINTERFACE_H
+
+#include "llvm/ADT/ArrayRef.h"
+
+#include <stdint.h>
+#include <system_error>
+
+namespace llvm {
+class StreamInterface {
+public:
+ virtual ~StreamInterface() {}
+
+ virtual std::error_code readBytes(uint32_t Offset,
+ MutableArrayRef<uint8_t> Buffer) const = 0;
+ virtual uint32_t getLength() const = 0;
+};
+}
+
+#endif
diff --git a/llvm/include/llvm/DebugInfo/PDB/Raw/StreamReader.h b/llvm/include/llvm/DebugInfo/PDB/Raw/StreamReader.h
new file mode 100644
index 00000000000..84527ab840f
--- /dev/null
+++ b/llvm/include/llvm/DebugInfo/PDB/Raw/StreamReader.h
@@ -0,0 +1,46 @@
+//===- StreamReader.h - Reads bytes and objects from a 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_STREAMREADER_H
+#define LLVM_DEBUGINFO_PDB_RAW_STREAMREADER_H
+
+#include "llvm/DebugInfo/PDB/Raw/StreamInterface.h"
+#include "llvm/Support/Endian.h"
+
+#include <string>
+#include <system_error>
+
+namespace llvm {
+
+class StreamReader {
+public:
+ StreamReader(const StreamInterface &S);
+
+ std::error_code readBytes(MutableArrayRef<uint8_t> Buffer);
+ std::error_code readInteger(uint32_t &Dest);
+ std::error_code readZeroString(std::string &Dest);
+
+ template <typename T> std::error_code readObject(T *Dest) {
+ MutableArrayRef<uint8_t> Buffer(reinterpret_cast<uint8_t *>(Dest),
+ sizeof(T));
+ return readBytes(Buffer);
+ }
+
+ void setOffset(uint32_t Off) { Offset = Off; }
+ uint32_t getOffset() const { return Offset; }
+ uint32_t getLength() const { return Stream.getLength(); }
+ uint32_t bytesRemaining() const { return getLength() - getOffset(); }
+
+private:
+ const StreamInterface &Stream;
+ uint32_t Offset;
+};
+}
+
+#endif
OpenPOWER on IntegriCloud