<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 21, 2016 at 1:58 PM, Zachary Turner via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: zturner<br>
Date: Thu Apr 21 15:58:35 2016<br>
New Revision: 267049<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=267049&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=267049&view=rev</a><br>
Log:<br>
Refactor raw pdb dumper into library<br>
<br>
PDB parsing code was hand-rolled into llvm-pdbdump. This patch moves the<br>
parsing of this code into DebugInfoPDB and makes the dumper use this.<br>
<br>
This is achieved by implementing the skeleton of RawPdbSession, the<br>
non-DIA counterpart to the existing PDB read interface. None of the type /<br>
source file / etc information is accessible yet, so this implementation is<br>
not yet close to achieving parity with the DIA counterpart, but the<br>
RawSession class simply holds a reference to a PDBFile class which handles<br>
parsing the file format. Additionally a PDBStream class is introduced<br>
which allows accessing the bytes of a particular stream in a PDB file.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D19343" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19343</a><br>
Reviewed By: majnemer<br>
<br>
Added:<br>
    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/<br>
    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h<br>
    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBStream.h<br>
    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawSession.h<br>
    llvm/trunk/lib/DebugInfo/PDB/Raw/<br>
    llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp<br>
    llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp<br>
    llvm/trunk/lib/DebugInfo/PDB/Raw/RawSession.cpp<br>
Modified:<br>
    llvm/trunk/include/llvm/DebugInfo/PDB/IPDBSession.h<br>
    llvm/trunk/include/llvm/DebugInfo/PDB/PDBTypes.h<br>
    llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt<br>
    llvm/trunk/lib/DebugInfo/PDB/PDB.cpp<br>
    llvm/trunk/tools/llvm-pdbdump/BuiltinDumper.h<br>
    llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/IPDBSession.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/IPDBSession.h?rev=267049&r1=267048&r2=267049&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/IPDBSession.h?rev=267049&r1=267048&r2=267049&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/PDB/IPDBSession.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/PDB/IPDBSession.h Thu Apr 21 15:58:35 2016<br>
@@ -11,6 +11,7 @@<br>
 #define LLVM_DEBUGINFO_PDB_IPDBSESSION_H<br>
<br>
 #include "PDBTypes.h"<br>
+#include "llvm/ADT/StringRef.h"<br>
 #include "llvm/Support/Casting.h"<br>
 #include <memory><br>
<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/PDBTypes.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/PDBTypes.h?rev=267049&r1=267048&r2=267049&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/PDBTypes.h?rev=267049&r1=267048&r2=267049&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/PDB/PDBTypes.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/PDB/PDBTypes.h Thu Apr 21 15:58:35 2016<br>
@@ -12,7 +12,6 @@<br>
<br>
 #include "llvm/Config/llvm-config.h"<br>
 #include "llvm/DebugInfo/CodeView/CodeView.h"<br>
-#include "llvm/Support/Endian.h"<br>
 #include <functional><br>
 #include <cstdint><br>
 #include <cstring><br>
@@ -70,6 +69,7 @@ class PDBSymbolUnknown;<br>
 /// of PDB_ReaderType::DIA is supported.<br>
 enum class PDB_ReaderType {<br>
   DIA = 0,<br>
+  Raw = 1,<br>
 };<br>
<br>
 /// Defines a 128-bit unique identifier.  This maps to a GUID on Windows, but<br>
@@ -429,35 +429,6 @@ struct Variant {<br>
   }<br>
 };<br>
<br>
-namespace PDB {<br>
-static const char Magic[] = {'M',  'i',  'c',    'r', 'o', 's',  'o',  'f',<br>
-                             't',  ' ',  'C',    '/', 'C', '+',  '+',  ' ',<br>
-                             'M',  'S',  'F',    ' ', '7', '.',  '0',  '0',<br>
-                             '\r', '\n', '\x1a', 'D', 'S', '\0', '\0', '\0'};<br>
-<br>
-// The superblock is overlaid at the beginning of the file (offset 0).<br>
-// It starts with a magic header and is followed by information which describes<br>
-// the layout of the file system.<br>
-struct SuperBlock {<br>
-  char MagicBytes[sizeof(Magic)];<br>
-  // The file system is split into a variable number of fixed size elements.<br>
-  // These elements are referred to as blocks.  The size of a block may vary<br>
-  // from system to system.<br>
-  support::ulittle32_t BlockSize;<br>
-  // This field's purpose is not yet known.<br>
-  support::ulittle32_t Unknown0;<br>
-  // This contains the number of blocks resident in the file system.  In<br>
-  // practice, NumBlocks * BlockSize is equivalent to the size of the PDB file.<br>
-  support::ulittle32_t NumBlocks;<br>
-  // This contains the number of bytes which make up the directory.<br>
-  support::ulittle32_t NumDirectoryBytes;<br>
-  // This field's purpose is not yet known.<br>
-  support::ulittle32_t Unknown1;<br>
-  // This contains the block # of the block map.<br>
-  support::ulittle32_t BlockMapAddr;<br>
-};<br>
-} // end namespace PDB<br>
-<br>
 } // end namespace llvm<br>
<br>
 namespace std {<br>
<br>
Added: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h?rev=267049&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h?rev=267049&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h (added)<br>
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h Thu Apr 21 15:58:35 2016<br>
@@ -0,0 +1,53 @@<br>
+//===- PDBFile.h - Low level interface to a PDB file ------------*- C++ -*-===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBFILE_H<br>
+#define LLVM_DEBUGINFO_PDB_RAW_PDBFILE_H<br>
+<br>
+#include "llvm/ADT/DenseMap.h"<br>
+#include "llvm/Support/Endian.h"<br>
+<br>
+#include <memory><br>
+<br>
+namespace llvm {<br>
+class MemoryBuffer;<br>
+<br>
+struct PDBContext;<br>
+<br>
+class PDBFile {<br>
+public:<br>
+  explicit PDBFile(std::unique_ptr<MemoryBuffer> MemBuffer);<br>
+  ~PDBFile();<br>
+<br>
+  uint32_t getBlockSize() const;<br>
+  uint32_t getUnknown0() const;<br>
+  uint32_t getBlockCount() const;<br>
+  uint32_t getNumDirectoryBytes() const;<br>
+  uint32_t getBlockMapIndex() const;<br>
+  uint32_t getUnknown1() const;<br>
+  uint32_t getNumDirectoryBlocks() const;<br>
+  uint64_t getBlockMapOffset() const;<br>
+<br>
+  uint32_t getNumStreams() const;<br>
+  uint32_t getStreamByteSize(uint32_t StreamIndex) const;<br>
+  llvm::ArrayRef<uint32_t> getStreamBlockList(uint32_t StreamIndex) const;<br>
+<br>
+  StringRef getBlockData(uint32_t BlockIndex, uint32_t NumBytes) const;<br>
+<br>
+  llvm::ArrayRef<uint32_t> getDirectoryBlockArray();<br>
+<br>
+  std::error_code parseFileHeaders();<br>
+  std::error_code parseStreamData();<br>
+<br>
+private:<br>
+  std::unique_ptr<PDBContext> Context;<br>
+};<br>
+}<br>
+<br>
+#endif<br>
<br>
Added: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBStream.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBStream.h?rev=267049&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBStream.h?rev=267049&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBStream.h (added)<br>
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBStream.h Thu Apr 21 15:58:35 2016<br>
@@ -0,0 +1,46 @@<br>
+//===- PDBStream.h - Low level interface to a PDB stream --------*- C++ -*-===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBSTREAM_H<br>
+#define LLVM_DEBUGINFO_PDB_RAW_PDBSTREAM_H<br>
+<br>
+#include "llvm/ADT/ArrayRef.h"<br>
+#include "llvm/ADT/StringRef.h"<br>
+<br>
+namespace llvm {<br>
+<br>
+class MemoryBufferRef;<br>
+class PDBFile;<br>
+<br>
+class PDBStream {<br>
+public:<br>
+  PDBStream(uint32_t StreamIdx, const PDBFile &File);<br>
+<br>
+  std::error_code readInteger(uint32_t &Dest);<br>
+  std::error_code readZeroString(std::string &Dest);<br>
+  std::error_code readBytes(void *Dest, uint32_t Length);<br>
+<br>
+  void setOffset(uint32_t Off);<br>
+  uint32_t getOffset() const;<br>
+  uint32_t getLength() const;<br>
+<br>
+  template <typename T> std::error_code readObject(T *Dest) {<br>
+    return readBytes(reinterpret_cast<void *>(Dest), sizeof(T));<br>
+  }<br>
+<br>
+private:<br>
+  uint32_t Offset;<br>
+<br>
+  uint32_t StreamLength;<br>
+  std::vector<uint32_t> BlockList;<br>
+  const PDBFile &Pdb;<br>
+};<br>
+}<br>
+<br>
+#endif<br>
<br>
Added: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawSession.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawSession.h?rev=267049&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawSession.h?rev=267049&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawSession.h (added)<br>
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawSession.h Thu Apr 21 15:58:35 2016<br>
@@ -0,0 +1,72 @@<br>
+//===- RawSession.h - Native implementation of IPDBSession ------*- C++ -*-===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_DEBUGINFO_PDB_RAW_RAWSESSION_H<br>
+#define LLVM_DEBUGINFO_PDB_RAW_RAWSESSION_H<br>
+<br>
+#include "llvm/DebugInfo/PDB/IPDBSession.h"<br>
+<br>
+namespace llvm {<br>
+class PDBFile;<br>
+class StringRef;<br>
+<br>
+class RawSession : public IPDBSession {<br>
+public:<br>
+  explicit RawSession(std::unique_ptr<PDBFile> PdbFile);<br>
+  ~RawSession() override;<br>
+<br>
+  static PDB_ErrorCode createFromPdb(StringRef Path,<br>
+                                     std::unique_ptr<IPDBSession> &Session);<br>
+  static PDB_ErrorCode createFromExe(StringRef Path,<br>
+                                     std::unique_ptr<IPDBSession> &Session);<br>
+<br>
+  uint64_t getLoadAddress() const override;<br>
+  void setLoadAddress(uint64_t Address) override;<br>
+  std::unique_ptr<PDBSymbolExe> getGlobalScope() const override;<br>
+  std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const override;<br>
+<br>
+  std::unique_ptr<PDBSymbol><br>
+  findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override;<br>
+<br>
+  std::unique_ptr<IPDBEnumLineNumbers><br>
+  findLineNumbers(const PDBSymbolCompiland &Compiland,<br>
+                  const IPDBSourceFile &File) const override;<br>
+  std::unique_ptr<IPDBEnumLineNumbers><br>
+  findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override;<br>
+<br>
+  std::unique_ptr<IPDBEnumSourceFiles><br>
+  findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern,<br>
+                  PDB_NameSearchFlags Flags) const override;<br>
+  std::unique_ptr<IPDBSourceFile><br>
+  findOneSourceFile(const PDBSymbolCompiland *Compiland,<br>
+                    llvm::StringRef Pattern,<br>
+                    PDB_NameSearchFlags Flags) const override;<br>
+  std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>><br>
+  findCompilandsForSourceFile(llvm::StringRef Pattern,<br>
+                              PDB_NameSearchFlags Flags) const override;<br>
+  std::unique_ptr<PDBSymbolCompiland><br>
+  findOneCompilandForSourceFile(llvm::StringRef Pattern,<br>
+                                PDB_NameSearchFlags Flags) const override;<br>
+  std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override;<br>
+  std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland(<br>
+      const PDBSymbolCompiland &Compiland) const override;<br>
+  std::unique_ptr<IPDBSourceFile><br>
+  getSourceFileById(uint32_t FileId) const override;<br>
+<br>
+  std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override;<br>
+<br>
+  PDBFile &getPDBFile() { return *Pdb; }<br>
+  const PDBFile &getPDBFile() const { return *Pdb; }<br>
+<br>
+private:<br>
+  std::unique_ptr<PDBFile> Pdb;<br>
+};<br>
+}<br>
+<br>
+#endif<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt?rev=267049&r1=267048&r2=267049&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt?rev=267049&r1=267048&r2=267049&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt (original)<br>
+++ llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt Thu Apr 21 15:58:35 2016<br>
@@ -24,9 +24,13 @@ if(HAVE_DIA_SDK)<br>
     )<br>
<br>
     set(LIBPDB_ADDITIONAL_HEADER_DIRS "${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/PDB/DIA")<br>
-<br>
 endif()<br>
<br>
+add_pdb_impl_folder(Raw<br>
+  Raw/PDBFile.cpp<br>
+  Raw/PDBStream.cpp<br>
+  Raw/RawSession.cpp)<br>
+<br>
 list(APPEND LIBPDB_ADDITIONAL_HEADER_DIRS "${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/PDB")<br>
<br>
 add_llvm_library(LLVMDebugInfoPDB<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/PDB/PDB.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/PDB.cpp?rev=267049&r1=267048&r2=267049&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/PDB.cpp?rev=267049&r1=267048&r2=267049&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/PDB/PDB.cpp (original)<br>
+++ llvm/trunk/lib/DebugInfo/PDB/PDB.cpp Thu Apr 21 15:58:35 2016<br>
@@ -17,23 +17,28 @@<br>
 #if HAVE_DIA_SDK<br>
 #include "llvm/DebugInfo/PDB/DIA/DIASession.h"<br>
 #endif<br>
+#include "llvm/DebugInfo/PDB/Raw/RawSession.h"<br>
<br>
 using namespace llvm;<br>
<br>
 PDB_ErrorCode llvm::loadDataForPDB(PDB_ReaderType Type, StringRef Path,<br>
                                    std::unique_ptr<IPDBSession> &Session) {<br>
   // Create the correct concrete instance type based on the value of Type.<br>
+  if (Type == PDB_ReaderType::Raw)<br>
+    return RawSession::createFromPdb(Path, Session);<br>
+<br>
 #if HAVE_DIA_SDK<br>
   return DIASession::createFromPdb(Path, Session);<br>
 #endif<br>
-  return PDB_ErrorCode::NoDiaSupport;<br></blockquote><div><br></div><div>Tihs (& the same below) triggers -Wreturn-type in the case where HAVE_DIA_SDK is false. I'm not sure what the right fix is? Should the old return be added back again?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 }<br>
<br>
 PDB_ErrorCode llvm::loadDataForEXE(PDB_ReaderType Type, StringRef Path,<br>
                                    std::unique_ptr<IPDBSession> &Session) {<br>
   // Create the correct concrete instance type based on the value of Type.<br>
+  if (Type == PDB_ReaderType::Raw)<br>
+    return RawSession::createFromExe(Path, Session);<br>
+<br>
 #if HAVE_DIA_SDK<br>
   return DIASession::createFromExe(Path, Session);<br>
 #endif<br>
-  return PDB_ErrorCode::NoDiaSupport;<br>
 }<br>
<br>
Added: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp?rev=267049&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp?rev=267049&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp (added)<br>
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp Thu Apr 21 15:58:35 2016<br>
@@ -0,0 +1,249 @@<br>
+//===- PDBFile.cpp - Low level interface to a PDB file ----------*- C++ -*-===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"<br>
+#include "llvm/ADT/ArrayRef.h"<br>
+#include "llvm/Support/Endian.h"<br>
+#include "llvm/Support/MemoryBuffer.h"<br>
+<br>
+using namespace llvm;<br>
+<br>
+namespace {<br>
+static const char Magic[] = {'M',  'i',  'c',    'r', 'o', 's',  'o',  'f',<br>
+                             't',  ' ',  'C',    '/', 'C', '+',  '+',  ' ',<br>
+                             'M',  'S',  'F',    ' ', '7', '.',  '0',  '0',<br>
+                             '\r', '\n', '\x1a', 'D', 'S', '\0', '\0', '\0'};<br>
+<br>
+// The superblock is overlaid at the beginning of the file (offset 0).<br>
+// It starts with a magic header and is followed by information which describes<br>
+// the layout of the file system.<br>
+struct SuperBlock {<br>
+  char MagicBytes[sizeof(Magic)];<br>
+  // The file system is split into a variable number of fixed size elements.<br>
+  // These elements are referred to as blocks.  The size of a block may vary<br>
+  // from system to system.<br>
+  support::ulittle32_t BlockSize;<br>
+  // This field's purpose is not yet known.<br>
+  support::ulittle32_t Unknown0;<br>
+  // This contains the number of blocks resident in the file system.  In<br>
+  // practice, NumBlocks * BlockSize is equivalent to the size of the PDB file.<br>
+  support::ulittle32_t NumBlocks;<br>
+  // This contains the number of bytes which make up the directory.<br>
+  support::ulittle32_t NumDirectoryBytes;<br>
+  // This field's purpose is not yet known.<br>
+  support::ulittle32_t Unknown1;<br>
+  // This contains the block # of the block map.<br>
+  support::ulittle32_t BlockMapAddr;<br>
+};<br>
+}<br>
+<br>
+struct llvm::PDBContext {<br>
+  std::unique_ptr<MemoryBuffer> Buffer;<br>
+  const SuperBlock *SB;<br>
+  std::vector<uint32_t> StreamSizes;<br>
+  DenseMap<uint32_t, std::vector<uint32_t>> StreamMap;<br>
+};<br>
+<br>
+namespace {<br>
+std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr,<br>
+                            const uint64_t Size) {<br>
+  if (Addr + Size < Addr || Addr + Size < Size ||<br>
+      Addr + Size > uintptr_t(M.getBufferEnd()) ||<br>
+      Addr < uintptr_t(M.getBufferStart())) {<br>
+    return std::make_error_code(std::errc::bad_address);<br>
+  }<br>
+  return std::error_code();<br>
+}<br>
+<br>
+template <typename T><br>
+std::error_code checkOffset(MemoryBufferRef M, ArrayRef<T> AR) {<br>
+  return checkOffset(M, uintptr_t(AR.data()), (uint64_t)AR.size() * sizeof(T));<br>
+}<br>
+<br>
+std::error_code checkOffset(MemoryBufferRef M, StringRef SR) {<br>
+  return checkOffset(M, uintptr_t(SR.data()), SR.size());<br>
+}<br>
+<br>
+uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize) {<br>
+  return alignTo(NumBytes, BlockSize) / BlockSize;<br>
+}<br>
+<br>
+uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize) {<br>
+  return BlockNumber * BlockSize;<br>
+}<br>
+}<br>
+<br>
+PDBFile::PDBFile(std::unique_ptr<MemoryBuffer> MemBuffer) {<br>
+  Context.reset(new PDBContext());<br>
+  Context->Buffer = std::move(MemBuffer);<br>
+}<br>
+<br>
+PDBFile::~PDBFile() {}<br>
+<br>
+uint32_t PDBFile::getBlockSize() const { return Context->SB->BlockSize; }<br>
+<br>
+uint32_t PDBFile::getUnknown0() const { return Context->SB->Unknown0; }<br>
+<br>
+uint32_t PDBFile::getBlockCount() const { return Context->SB->NumBlocks; }<br>
+<br>
+uint32_t PDBFile::getNumDirectoryBytes() const {<br>
+  return Context->SB->NumDirectoryBytes;<br>
+}<br>
+<br>
+uint32_t PDBFile::getBlockMapIndex() const { return Context->SB->BlockMapAddr; }<br>
+<br>
+uint32_t PDBFile::getUnknown1() const { return Context->SB->Unknown1; }<br>
+<br>
+uint32_t PDBFile::getNumDirectoryBlocks() const {<br>
+  return bytesToBlocks(Context->SB->NumDirectoryBytes, Context->SB->BlockSize);<br>
+}<br>
+<br>
+uint64_t PDBFile::getBlockMapOffset() const {<br>
+  return (uint64_t)Context->SB->BlockMapAddr * Context->SB->BlockSize;<br>
+}<br>
+<br>
+uint32_t PDBFile::getNumStreams() const { return Context->StreamSizes.size(); }<br>
+<br>
+uint32_t PDBFile::getStreamByteSize(uint32_t StreamIndex) const {<br>
+  return Context->StreamSizes[StreamIndex];<br>
+}<br>
+<br>
+llvm::ArrayRef<uint32_t><br>
+PDBFile::getStreamBlockList(uint32_t StreamIndex) const {<br>
+  auto &Data = Context->StreamMap[StreamIndex];<br>
+  return llvm::ArrayRef<uint32_t>(Data);<br>
+}<br>
+<br>
+StringRef PDBFile::getBlockData(uint32_t BlockIndex, uint32_t NumBytes) const {<br>
+  uint64_t StreamBlockOffset = blockToOffset(BlockIndex, getBlockSize());<br>
+<br>
+  return StringRef(Context->Buffer->getBufferStart() + StreamBlockOffset,<br>
+                   NumBytes);<br>
+}<br>
+<br>
+std::error_code PDBFile::parseFileHeaders() {<br>
+  std::error_code EC;<br>
+  MemoryBufferRef BufferRef = *Context->Buffer;<br>
+<br>
+  Context->SB =<br>
+      reinterpret_cast<const SuperBlock *>(BufferRef.getBufferStart());<br>
+  const SuperBlock *SB = Context->SB;<br>
+  // We don't support blocksizes which aren't a multiple of four bytes.<br>
+  if (SB->BlockSize % sizeof(support::ulittle32_t) != 0)<br>
+    return std::make_error_code(std::errc::not_supported);<br>
+<br>
+  // We don't support directories whose sizes aren't a multiple of four bytes.<br>
+  if (SB->NumDirectoryBytes % sizeof(support::ulittle32_t) != 0)<br>
+    return std::make_error_code(std::errc::not_supported);<br>
+<br>
+  // The number of blocks which comprise the directory is a simple function of<br>
+  // the number of bytes it contains.<br>
+  uint64_t NumDirectoryBlocks = getNumDirectoryBlocks();<br>
+<br>
+  // The block map, as we understand it, is a block which consists of a list of<br>
+  // block numbers.<br>
+  // It is unclear what would happen if the number of blocks couldn't fit on a<br>
+  // single block.<br>
+  if (NumDirectoryBlocks > SB->BlockSize / sizeof(support::ulittle32_t))<br>
+    return std::make_error_code(std::errc::illegal_byte_sequence);<br>
+<br>
+  return std::error_code();<br>
+}<br>
+<br>
+std::error_code PDBFile::parseStreamData() {<br>
+  assert(Context && Context->SB);<br>
+<br>
+  bool SeenNumStreams = false;<br>
+  uint32_t NumStreams = 0;<br>
+  uint32_t StreamIdx = 0;<br>
+  uint64_t DirectoryBytesRead = 0;<br>
+  std::error_code EC;<br>
+<br>
+  MemoryBufferRef M = *Context->Buffer;<br>
+  const SuperBlock *SB = Context->SB;<br>
+<br>
+  auto DirectoryBlocks = getDirectoryBlockArray();<br>
+<br>
+  // The structure of the directory is as follows:<br>
+  //    struct PDBDirectory {<br>
+  //      uint32_t NumStreams;<br>
+  //      uint32_t StreamSizes[NumStreams];<br>
+  //      uint32_t StreamMap[NumStreams][];<br>
+  //    };<br>
+  //<br>
+  //  Empty streams don't consume entries in the StreamMap.<br>
+  for (uint32_t DirectoryBlockAddr : DirectoryBlocks) {<br>
+    uint64_t DirectoryBlockOffset =<br>
+        blockToOffset(DirectoryBlockAddr, SB->BlockSize);<br>
+    auto DirectoryBlock =<br>
+        makeArrayRef(reinterpret_cast<const uint32_t *>(M.getBufferStart() +<br>
+                                                        DirectoryBlockOffset),<br>
+                     SB->BlockSize / sizeof(support::ulittle32_t));<br>
+    if (EC = checkOffset(M, DirectoryBlock))<br>
+      return EC;<br>
+<br>
+    // We read data out of the directory four bytes at a time.  Depending on<br>
+    // where we are in the directory, the contents may be: the number of streams<br>
+    // in the directory, a stream's size, or a block in the stream map.<br>
+    for (uint32_t Data : DirectoryBlock) {<br>
+      // Don't read beyond the end of the directory.<br>
+      if (DirectoryBytesRead == SB->NumDirectoryBytes)<br>
+        break;<br>
+<br>
+      DirectoryBytesRead += sizeof(Data);<br>
+<br>
+      // This data must be the number of streams if we haven't seen it yet.<br>
+      if (!SeenNumStreams) {<br>
+        NumStreams = Data;<br>
+        SeenNumStreams = true;<br>
+        continue;<br>
+      }<br>
+      // This data must be a stream size if we have not seen them all yet.<br>
+      if (Context->StreamSizes.size() < NumStreams) {<br>
+        // It seems like some streams have their set to -1 when their contents<br>
+        // are not present.  Treat them like empty streams for now.<br>
+        if (Data == UINT32_MAX)<br>
+          Context->StreamSizes.push_back(0);<br>
+        else<br>
+          Context->StreamSizes.push_back(Data);<br>
+        continue;<br>
+      }<br>
+<br>
+      // This data must be a stream block number if we have seen all of the<br>
+      // stream sizes.<br>
+      std::vector<uint32_t> *StreamBlocks = nullptr;<br>
+      // Figure out which stream this block number belongs to.<br>
+      while (StreamIdx < NumStreams) {<br>
+        uint64_t NumExpectedStreamBlocks =<br>
+            bytesToBlocks(Context->StreamSizes[StreamIdx], SB->BlockSize);<br>
+        StreamBlocks = &Context->StreamMap[StreamIdx];<br>
+        if (NumExpectedStreamBlocks > StreamBlocks->size())<br>
+          break;<br>
+        ++StreamIdx;<br>
+      }<br>
+      // It seems this block doesn't belong to any stream?  The stream is either<br>
+      // corrupt or something more mysterious is going on.<br>
+      if (StreamIdx == NumStreams)<br>
+        return std::make_error_code(std::errc::illegal_byte_sequence);<br>
+<br>
+      StreamBlocks->push_back(Data);<br>
+    }<br>
+  }<br>
+<br>
+  // We should have read exactly SB->NumDirectoryBytes bytes.<br>
+  assert(DirectoryBytesRead == SB->NumDirectoryBytes);<br>
+  return std::error_code();<br>
+}<br>
+<br>
+llvm::ArrayRef<uint32_t> PDBFile::getDirectoryBlockArray() {<br>
+  return makeArrayRef(<br>
+      reinterpret_cast<const uint32_t *>(Context->Buffer->getBufferStart() +<br>
+                                         getBlockMapOffset()),<br>
+      getNumDirectoryBlocks());<br>
+}<br>
<br>
Added: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp?rev=267049&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp?rev=267049&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp (added)<br>
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp Thu Apr 21 15:58:35 2016<br>
@@ -0,0 +1,97 @@<br>
+//===- PDBStream.cpp - Low level interface to a PDB stream ------*- C++ -*-===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/DebugInfo/PDB/Raw/PDBStream.h"<br>
+#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"<br>
+<br>
+using namespace llvm;<br>
+<br>
+static uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize) {<br>
+  return alignTo(NumBytes, BlockSize) / BlockSize;<br>
+}<br>
+<br>
+static uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize) {<br>
+  return BlockNumber * BlockSize;<br>
+}<br>
+<br>
+PDBStream::PDBStream(uint32_t StreamIdx, const PDBFile &File) : Pdb(File) {<br>
+  this->StreamLength = Pdb.getStreamByteSize(StreamIdx);<br>
+  this->BlockList = Pdb.getStreamBlockList(StreamIdx);<br>
+  this->Offset = 0;<br>
+}<br>
+<br>
+std::error_code PDBStream::readInteger(uint32_t &Dest) {<br>
+  support::detail::packed_endian_specific_integral<uint32_t, support::little,<br>
+                                                   support::unaligned><br>
+      P;<br>
+  if (std::error_code EC = readObject(&P))<br>
+    return EC;<br>
+  Dest = P;<br>
+  return std::error_code();<br>
+}<br>
+<br>
+std::error_code PDBStream::readZeroString(std::string &Dest) {<br>
+  char C;<br>
+  do {<br>
+    readObject(&C);<br>
+    if (C != '\0')<br>
+      Dest.push_back(C);<br>
+  } while (C != '\0');<br>
+  return std::error_code();<br>
+}<br>
+<br>
+std::error_code PDBStream::readBytes(void *Dest, uint32_t Length) {<br>
+  uint32_t BlockNum = Offset / Pdb.getBlockSize();<br>
+  uint32_t OffsetInBlock = Offset % Pdb.getBlockSize();<br>
+<br>
+  // Make sure we aren't trying to read beyond the end of the stream.<br>
+  if (this->Offset + Length > this->StreamLength)<br>
+    return std::make_error_code(std::errc::bad_address);<br>
+<br>
+  // Modify the passed in offset to point to the data after the object.<br>
+  Offset += Length;<br>
+<br>
+  // Handle the contiguous case: the offset + size stays within a block.<br>
+  if (OffsetInBlock + Length <= Pdb.getBlockSize()) {<br>
+    uint32_t StreamBlockAddr = this->BlockList[BlockNum];<br>
+<br>
+    StringRef Data = Pdb.getBlockData(StreamBlockAddr, Pdb.getBlockSize());<br>
+    ::memcpy(Dest, Data.data() + OffsetInBlock, Length);<br>
+    return std::error_code();<br>
+  }<br>
+<br>
+  // The non-contiguous case: we will stitch together non-contiguous chunks<br>
+  uint32_t BytesLeft = Length;<br>
+  uint32_t BytesWritten = 0;<br>
+  char *WriteBuffer = static_cast<char *>(Dest);<br>
+  while (BytesLeft > 0) {<br>
+    uint32_t StreamBlockAddr = this->BlockList[BlockNum];<br>
+    uint64_t StreamBlockOffset =<br>
+        blockToOffset(StreamBlockAddr, Pdb.getBlockSize()) + OffsetInBlock;<br>
+<br>
+    StringRef Data = Pdb.getBlockData(StreamBlockAddr, Pdb.getBlockSize());<br>
+<br>
+    const char *ChunkStart = Data.data() + StreamBlockOffset;<br>
+    uint32_t BytesInChunk =<br>
+        std::min(BytesLeft, Pdb.getBlockSize() - OffsetInBlock);<br>
+    ::memcpy(WriteBuffer + BytesWritten, ChunkStart, BytesInChunk);<br>
+<br>
+    BytesWritten += BytesInChunk;<br>
+    BytesLeft -= BytesInChunk;<br>
+    ++BlockNum;<br>
+    OffsetInBlock = 0;<br>
+  }<br>
+  return std::error_code();<br>
+}<br>
+<br>
+void PDBStream::setOffset(uint32_t O) { this->Offset = O; }<br>
+<br>
+uint32_t PDBStream::getOffset() const { return this->Offset; }<br>
+<br>
+uint32_t PDBStream::getLength() const { return this->StreamLength; }<br>
<br>
Added: llvm/trunk/lib/DebugInfo/PDB/Raw/RawSession.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/RawSession.cpp?rev=267049&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/RawSession.cpp?rev=267049&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/PDB/Raw/RawSession.cpp (added)<br>
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/RawSession.cpp Thu Apr 21 15:58:35 2016<br>
@@ -0,0 +1,126 @@<br>
+//===- RawSession.cpp - Raw implementation of IPDBSession -------*- C++ -*-===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/DebugInfo/PDB/Raw/RawSession.h"<br>
+#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"<br>
+#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"<br>
+#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"<br>
+#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"<br>
+#include "llvm/DebugInfo/PDB/Raw/PdbFile.h"<br>
+<br>
+#include "llvm/Support/ErrorOr.h"<br>
+#include "llvm/Support/MemoryBuffer.h"<br>
+<br>
+using namespace llvm;<br>
+<br>
+RawSession::RawSession(std::unique_ptr<PDBFile> PdbFile)<br>
+    : Pdb(std::move(PdbFile)) {}<br>
+<br>
+RawSession::~RawSession() {}<br>
+<br>
+PDB_ErrorCode RawSession::createFromPdb(StringRef Path,<br>
+                                        std::unique_ptr<IPDBSession> &Session) {<br>
+<br>
+  ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =<br>
+      MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,<br>
+                                   /*RequiresNullTerminator=*/false);<br>
+<br>
+  std::error_code EC;<br>
+  if (EC = ErrorOrBuffer.getError())<br>
+    return PDB_ErrorCode::CouldNotCreateImpl;<br>
+<br>
+  std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();<br>
+<br>
+  std::unique_ptr<PDBFile> File(new PDBFile(std::move(Buffer)));<br>
+  if (EC = File->parseFileHeaders())<br>
+    return PDB_ErrorCode::InvalidFileFormat;<br>
+  if (EC = File->parseStreamData())<br>
+    return PDB_ErrorCode::InvalidFileFormat;<br>
+<br>
+  Session.reset(new RawSession(std::move(File)));<br>
+<br>
+  return PDB_ErrorCode::Success;<br>
+}<br>
+<br>
+PDB_ErrorCode RawSession::createFromExe(StringRef Path,<br>
+                                        std::unique_ptr<IPDBSession> &Session) {<br>
+  return PDB_ErrorCode::CouldNotCreateImpl;<br>
+}<br>
+<br>
+uint64_t RawSession::getLoadAddress() const { return 0; }<br>
+<br>
+void RawSession::setLoadAddress(uint64_t Address) {}<br>
+<br>
+std::unique_ptr<PDBSymbolExe> RawSession::getGlobalScope() const {<br>
+  return nullptr;<br>
+}<br>
+<br>
+std::unique_ptr<PDBSymbol> RawSession::getSymbolById(uint32_t SymbolId) const {<br>
+  return nullptr;<br>
+}<br>
+<br>
+std::unique_ptr<PDBSymbol><br>
+RawSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {<br>
+  return nullptr;<br>
+}<br>
+<br>
+std::unique_ptr<IPDBEnumLineNumbers><br>
+RawSession::findLineNumbers(const PDBSymbolCompiland &Compiland,<br>
+                            const IPDBSourceFile &File) const {<br>
+  return nullptr;<br>
+}<br>
+<br>
+std::unique_ptr<IPDBEnumLineNumbers><br>
+RawSession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const {<br>
+  return nullptr;<br>
+}<br>
+<br>
+std::unique_ptr<IPDBEnumSourceFiles><br>
+RawSession::findSourceFiles(const PDBSymbolCompiland *Compiland,<br>
+                            llvm::StringRef Pattern,<br>
+                            PDB_NameSearchFlags Flags) const {<br>
+  return nullptr;<br>
+}<br>
+<br>
+std::unique_ptr<IPDBSourceFile><br>
+RawSession::findOneSourceFile(const PDBSymbolCompiland *Compiland,<br>
+                              llvm::StringRef Pattern,<br>
+                              PDB_NameSearchFlags Flags) const {<br>
+  return nullptr;<br>
+}<br>
+<br>
+std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>><br>
+RawSession::findCompilandsForSourceFile(llvm::StringRef Pattern,<br>
+                                        PDB_NameSearchFlags Flags) const {<br>
+  return nullptr;<br>
+}<br>
+<br>
+std::unique_ptr<PDBSymbolCompiland><br>
+RawSession::findOneCompilandForSourceFile(llvm::StringRef Pattern,<br>
+                                          PDB_NameSearchFlags Flags) const {<br>
+  return nullptr;<br>
+}<br>
+<br>
+std::unique_ptr<IPDBEnumSourceFiles> RawSession::getAllSourceFiles() const {<br>
+  return nullptr;<br>
+}<br>
+<br>
+std::unique_ptr<IPDBEnumSourceFiles> RawSession::getSourceFilesForCompiland(<br>
+    const PDBSymbolCompiland &Compiland) const {<br>
+  return nullptr;<br>
+}<br>
+<br>
+std::unique_ptr<IPDBSourceFile><br>
+RawSession::getSourceFileById(uint32_t FileId) const {<br>
+  return nullptr;<br>
+}<br>
+<br>
+std::unique_ptr<IPDBEnumDataStreams> RawSession::getDebugStreams() const {<br>
+  return nullptr;<br>
+}<br>
<br>
Modified: llvm/trunk/tools/llvm-pdbdump/BuiltinDumper.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/BuiltinDumper.h?rev=267049&r1=267048&r2=267049&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/BuiltinDumper.h?rev=267049&r1=267048&r2=267049&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-pdbdump/BuiltinDumper.h (original)<br>
+++ llvm/trunk/tools/llvm-pdbdump/BuiltinDumper.h Thu Apr 21 15:58:35 2016<br>
@@ -10,6 +10,7 @@<br>
 #ifndef LLVM_TOOLS_LLVMPDBDUMP_BUILTINDUMPER_H<br>
 #define LLVM_TOOLS_LLVMPDBDUMP_BUILTINDUMPER_H<br>
<br>
+#include "llvm/ADT/StringRef.h"<br>
 #include "llvm/DebugInfo/PDB/PDBSymDumper.h"<br>
<br>
 namespace llvm {<br>
<br>
Modified: llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp?rev=267049&r1=267048&r2=267049&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp?rev=267049&r1=267048&r2=267049&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp (original)<br>
+++ llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp Thu Apr 21 15:58:35 2016<br>
@@ -35,6 +35,9 @@<br>
 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"<br>
 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"<br>
 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"<br>
+#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"<br>
+#include "llvm/DebugInfo/PDB/Raw/PDBStream.h"<br>
+#include "llvm/DebugInfo/PDB/Raw/RawSession.h"<br>
 #include "llvm/Support/CommandLine.h"<br>
 #include "llvm/Support/ConvertUTF.h"<br>
 #include "llvm/Support/FileSystem.h"<br>
@@ -43,8 +46,8 @@<br>
 #include "llvm/Support/MemoryBuffer.h"<br>
 #include "llvm/Support/PrettyStackTrace.h"<br>
 #include "llvm/Support/Process.h"<br>
-#include "llvm/Support/raw_ostream.h"<br>
 #include "llvm/Support/Signals.h"<br>
+#include "llvm/Support/raw_ostream.h"<br>
<br>
 #if defined(HAVE_DIA_SDK)<br>
 #ifndef NOMINMAX<br>
@@ -152,186 +155,32 @@ static void reportError(StringRef Input,<br>
   reportError(Input, EC.message());<br>
 }<br>
<br>
-static std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr,<br>
-                                   const uint64_t Size) {<br>
-  if (Addr + Size < Addr || Addr + Size < Size ||<br>
-      Addr + Size > uintptr_t(M.getBufferEnd()) ||<br>
-      Addr < uintptr_t(M.getBufferStart())) {<br>
-    return std::make_error_code(std::errc::bad_address);<br>
-  }<br>
-  return std::error_code();<br>
-}<br>
-<br>
-template <typename T><br>
-static std::error_code checkOffset(MemoryBufferRef M, ArrayRef<T> AR) {<br>
-  return checkOffset(M, uintptr_t(AR.data()), (uint64_t)AR.size() * sizeof(T));<br>
-}<br>
-<br>
-static std::error_code checkOffset(MemoryBufferRef M, StringRef SR) {<br>
-  return checkOffset(M, uintptr_t(SR.data()), SR.size());<br>
-}<br>
-<br>
-// Sets Obj unless any bytes in [addr, addr + size) fall outsize of m.<br>
-// Returns unexpected_eof if error.<br>
-template <typename T><br>
-static std::error_code getObject(const T *&Obj, MemoryBufferRef M,<br>
-                                 const void *Ptr,<br>
-                                 const uint64_t Size = sizeof(T)) {<br>
-  uintptr_t Addr = uintptr_t(Ptr);<br>
-  if (std::error_code EC = checkOffset(M, Addr, Size))<br>
-    return EC;<br>
-  Obj = reinterpret_cast<const T *>(Addr);<br>
-  return std::error_code();<br>
-}<br>
-<br>
-static uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize) {<br>
-  return alignTo(NumBytes, BlockSize) / BlockSize;<br>
-}<br>
-<br>
-static uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize) {<br>
-  return BlockNumber * BlockSize;<br>
-}<br>
-<br>
-struct PDBStructureContext {<br>
-  const PDB::SuperBlock *SB;<br>
-  MemoryBufferRef M;<br>
-  std::vector<uint32_t> StreamSizes;<br>
-  DenseMap<uint32_t, std::vector<uint32_t>> StreamMap;<br>
-<br>
-  SmallVector<char, 512> Scratch;<br>
-<br>
-  // getObject tries to stitch together non-contiguous blocks into a contiguous<br>
-  // value.  The storage for the value comes from the memory mapped file if the<br>
-  // memory would be contiguous.  Otherwise, it uses 'Scratch' to buffer the<br>
-  // data.<br>
-  template <typename T><br>
-  void getObject(const T *&Obj, uint32_t StreamIdx, uint32_t &Offset) {<br>
-    // Make sure the stream index is valid.<br>
-    auto StreamBlockI = StreamMap.find(StreamIdx);<br>
-    if (StreamBlockI == StreamMap.end())<br>
-      reportError(M.getBufferIdentifier(),<br>
-                  std::make_error_code(std::errc::bad_address));<br>
-<br>
-    auto &StreamBlocks = StreamBlockI->second;<br>
-    uint32_t BlockNum = Offset / SB->BlockSize;<br>
-    uint32_t OffsetInBlock = Offset % SB->BlockSize;<br>
-<br>
-    // Make sure we aren't trying to read beyond the end of the stream.<br>
-    if (Offset + sizeof(T) > StreamSizes[StreamIdx])<br>
-      reportError(M.getBufferIdentifier(),<br>
-                  std::make_error_code(std::errc::bad_address));<br>
-<br>
-    // Modify the passed in offset to point to the data after the object.<br>
-    Offset += sizeof(T);<br>
-<br>
-    // Handle the contiguous case: the offset + size stays within a block.<br>
-    if (OffsetInBlock + sizeof(T) <= SB->BlockSize) {<br>
-      uint32_t StreamBlockAddr = StreamBlocks[BlockNum];<br>
-      uint64_t StreamBlockOffset =<br>
-          blockToOffset(StreamBlockAddr, SB->BlockSize) + OffsetInBlock;<br>
-      // Return a pointer to the memory buffer.<br>
-      Obj = reinterpret_cast<const T *>(M.getBufferStart() + StreamBlockOffset);<br>
-      return;<br>
-    }<br>
-<br>
-    // The non-contiguous case: we will stitch together non-contiguous chunks<br>
-    // into the scratch buffer.<br>
-    Scratch.clear();<br>
-<br>
-    uint32_t BytesLeft = sizeof(T);<br>
-    while (BytesLeft > 0) {<br>
-      uint32_t StreamBlockAddr = StreamBlocks[BlockNum];<br>
-      uint64_t StreamBlockOffset =<br>
-          blockToOffset(StreamBlockAddr, SB->BlockSize) + OffsetInBlock;<br>
-<br>
-      const char *ChunkStart =<br>
-          M.getBufferStart() + StreamBlockOffset;<br>
-      uint32_t BytesInChunk =<br>
-          std::min(BytesLeft, SB->BlockSize - OffsetInBlock);<br>
-      Scratch.append(ChunkStart, ChunkStart + BytesInChunk);<br>
-<br>
-      BytesLeft -= BytesInChunk;<br>
-      ++BlockNum;<br>
-      OffsetInBlock = 0;<br>
-    }<br>
-<br>
-    // Return a pointer to the scratch buffer.<br>
-    Obj = reinterpret_cast<const T *>(Scratch.data());<br>
-  }<br>
-<br>
-  template <typename T><br>
-  T getInt(uint32_t StreamIdx, uint32_t &Offset) {<br>
-    const support::detail::packed_endian_specific_integral<<br>
-        T, support::little, support::unaligned> *P;<br>
-    getObject(P, StreamIdx, Offset);<br>
-    return *P;<br>
-  }<br>
-<br>
-  template <typename T><br>
-  T getObject(uint32_t StreamIdx, uint32_t &Offset) {<br>
-    const T *P;<br>
-    getObject(P, StreamIdx, Offset);<br>
-    return *P;<br>
-  }<br>
-};<br>
-<br>
-static void dumpStructure(MemoryBufferRef M) {<br>
-  const PDB::SuperBlock *SB;<br>
-<br>
-  auto Error = [&](std::error_code EC) {<br>
-    if (EC)<br>
-      reportError(M.getBufferIdentifier(), EC);<br>
-  };<br>
-<br>
-  Error(getObject(SB, M, M.getBufferStart()));<br>
+static void dumpStructure(RawSession &RS) {<br>
+  PDBFile &File = RS.getPDBFile();<br>
<br>
   if (opts::DumpHeaders) {<br>
-    outs() << "BlockSize: " << SB->BlockSize << '\n';<br>
-    outs() << "Unknown0: " << SB->Unknown0 << '\n';<br>
-    outs() << "NumBlocks: " << SB->NumBlocks << '\n';<br>
-    outs() << "NumDirectoryBytes: " << SB->NumDirectoryBytes << '\n';<br>
-    outs() << "Unknown1: " << SB->Unknown1 << '\n';<br>
-    outs() << "BlockMapAddr: " << SB->BlockMapAddr << '\n';<br>
+    outs() << "BlockSize: " << File.getBlockSize() << '\n';<br>
+    outs() << "Unknown0: " << File.getUnknown0() << '\n';<br>
+    outs() << "NumBlocks: " << File.getBlockCount() << '\n';<br>
+    outs() << "NumDirectoryBytes: " << File.getNumDirectoryBytes() << '\n';<br>
+    outs() << "Unknown1: " << File.getUnknown1() << '\n';<br>
+    outs() << "BlockMapAddr: " << File.getBlockMapIndex() << '\n';<br>
   }<br>
<br>
-  // We don't support blocksizes which aren't a multiple of four bytes.<br>
-  if (SB->BlockSize % sizeof(support::ulittle32_t) != 0)<br>
-    Error(std::make_error_code(std::errc::not_supported));<br>
-<br>
-  // We don't support directories whose sizes aren't a multiple of four bytes.<br>
-  if (SB->NumDirectoryBytes % sizeof(support::ulittle32_t) != 0)<br>
-    Error(std::make_error_code(std::errc::not_supported));<br>
-<br>
-  // The number of blocks which comprise the directory is a simple function of<br>
-  // the number of bytes it contains.<br>
-  uint64_t NumDirectoryBlocks =<br>
-      bytesToBlocks(SB->NumDirectoryBytes, SB->BlockSize);<br>
   if (opts::DumpHeaders)<br>
-    outs() << "NumDirectoryBlocks: " << NumDirectoryBlocks << '\n';<br>
+    outs() << "NumDirectoryBlocks: " << File.getNumDirectoryBlocks() << '\n';<br>
<br>
-  // The block map, as we understand it, is a block which consists of a list of<br>
-  // block numbers.<br>
-  // It is unclear what would happen if the number of blocks couldn't fit on a<br>
-  // single block.<br>
-  if (NumDirectoryBlocks > SB->BlockSize / sizeof(support::ulittle32_t))<br>
-    Error(std::make_error_code(std::errc::illegal_byte_sequence));<br>
-<br>
-  uint64_t BlockMapOffset = (uint64_t)SB->BlockMapAddr * SB->BlockSize;<br>
   if (opts::DumpHeaders)<br>
-    outs() << "BlockMapOffset: " << BlockMapOffset << '\n';<br>
+    outs() << "BlockMapOffset: " << File.getBlockMapOffset() << '\n';<br>
<br>
   // The directory is not contiguous.  Instead, the block map contains a<br>
   // contiguous list of block numbers whose contents, when concatenated in<br>
   // order, make up the directory.<br>
-  auto DirectoryBlocks =<br>
-      makeArrayRef(reinterpret_cast<const support::ulittle32_t *>(<br>
-                       M.getBufferStart() + BlockMapOffset),<br>
-                   NumDirectoryBlocks);<br>
-  Error(checkOffset(M, DirectoryBlocks));<br>
+  auto DirectoryBlocks = File.getDirectoryBlockArray();<br>
<br>
   if (opts::DumpHeaders) {<br>
     outs() << "DirectoryBlocks: [";<br>
-    for (const support::ulittle32_t &DirectoryBlockAddr : DirectoryBlocks) {<br>
+    for (const uint32_t &DirectoryBlockAddr : DirectoryBlocks) {<br>
       if (&DirectoryBlockAddr != &DirectoryBlocks.front())<br>
         outs() << ", ";<br>
       outs() << DirectoryBlockAddr;<br>
@@ -339,96 +188,23 @@ static void dumpStructure(MemoryBufferRe<br>
     outs() << "]\n";<br>
   }<br>
<br>
-  bool SeenNumStreams = false;<br>
-  uint32_t NumStreams = 0;<br>
-  uint32_t StreamIdx = 0;<br>
-  uint64_t DirectoryBytesRead = 0;<br>
-  PDBStructureContext Ctx;<br>
-  Ctx.SB = SB;<br>
-  Ctx.M = M;<br>
-  // The structure of the directory is as follows:<br>
-  //    struct PDBDirectory {<br>
-  //      uint32_t NumStreams;<br>
-  //      uint32_t StreamSizes[NumStreams];<br>
-  //      uint32_t StreamMap[NumStreams][];<br>
-  //    };<br>
-  //<br>
-  //  Empty streams don't consume entries in the StreamMap.<br>
-  for (uint32_t DirectoryBlockAddr : DirectoryBlocks) {<br>
-    uint64_t DirectoryBlockOffset =<br>
-        blockToOffset(DirectoryBlockAddr, SB->BlockSize);<br>
-    auto DirectoryBlock =<br>
-        makeArrayRef(reinterpret_cast<const support::ulittle32_t *>(<br>
-                         M.getBufferStart() + DirectoryBlockOffset),<br>
-                     SB->BlockSize / sizeof(support::ulittle32_t));<br>
-    Error(checkOffset(M, DirectoryBlock));<br>
-<br>
-    // We read data out of the directory four bytes at a time.  Depending on<br>
-    // where we are in the directory, the contents may be: the number of streams<br>
-    // in the directory, a stream's size, or a block in the stream map.<br>
-    for (uint32_t Data : DirectoryBlock) {<br>
-      // Don't read beyond the end of the directory.<br>
-      if (DirectoryBytesRead == SB->NumDirectoryBytes)<br>
-        break;<br>
-<br>
-      DirectoryBytesRead += sizeof(Data);<br>
-<br>
-      // This data must be the number of streams if we haven't seen it yet.<br>
-      if (!SeenNumStreams) {<br>
-        NumStreams = Data;<br>
-        SeenNumStreams = true;<br>
-        continue;<br>
-      }<br>
-      // This data must be a stream size if we have not seen them all yet.<br>
-      if (Ctx.StreamSizes.size() < NumStreams) {<br>
-        // It seems like some streams have their set to -1 when their contents<br>
-        // are not present.  Treat them like empty streams for now.<br>
-        if (Data == UINT32_MAX)<br>
-          Ctx.StreamSizes.push_back(0);<br>
-        else<br>
-          Ctx.StreamSizes.push_back(Data);<br>
-        continue;<br>
-      }<br>
-<br>
-      // This data must be a stream block number if we have seen all of the<br>
-      // stream sizes.<br>
-      std::vector<uint32_t> *StreamBlocks = nullptr;<br>
-      // Figure out which stream this block number belongs to.<br>
-      while (StreamIdx < NumStreams) {<br>
-        uint64_t NumExpectedStreamBlocks =<br>
-            bytesToBlocks(Ctx.StreamSizes[StreamIdx], SB->BlockSize);<br>
-        StreamBlocks = &Ctx.StreamMap[StreamIdx];<br>
-        if (NumExpectedStreamBlocks > StreamBlocks->size())<br>
-          break;<br>
-        ++StreamIdx;<br>
-      }<br>
-      // It seems this block doesn't belong to any stream?  The stream is either<br>
-      // corrupt or something more mysterious is going on.<br>
-      if (StreamIdx == NumStreams)<br>
-        Error(std::make_error_code(std::errc::illegal_byte_sequence));<br>
-<br>
-      StreamBlocks->push_back(Data);<br>
-    }<br>
-  }<br>
-<br>
-  // We should have read exactly SB->NumDirectoryBytes bytes.<br>
-  assert(DirectoryBytesRead == SB->NumDirectoryBytes);<br>
-<br>
   if (opts::DumpHeaders)<br>
-    outs() << "NumStreams: " << NumStreams << '\n';<br>
-  if (opts::DumpStreamSizes)<br>
-    for (uint32_t StreamIdx = 0; StreamIdx < NumStreams; ++StreamIdx)<br>
+    outs() << "NumStreams: " << File.getNumStreams() << '\n';<br>
+  uint32_t StreamCount = File.getNumStreams();<br>
+  if (opts::DumpStreamSizes) {<br>
+    for (uint32_t StreamIdx = 0; StreamCount; ++StreamIdx)<br>
       outs() << "StreamSizes[" << StreamIdx<br>
-             << "]: " << Ctx.StreamSizes[StreamIdx] << '\n';<br>
+             << "]: " << File.getStreamByteSize(StreamIdx) << '\n';<br>
+  }<br>
<br>
   if (opts::DumpStreamBlocks) {<br>
-    for (uint32_t StreamIdx = 0; StreamIdx < NumStreams; ++StreamIdx) {<br>
+    for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {<br>
       outs() << "StreamBlocks[" << StreamIdx << "]: [";<br>
-      std::vector<uint32_t> &StreamBlocks = Ctx.StreamMap[StreamIdx];<br>
-      for (uint32_t &StreamBlock : StreamBlocks) {<br>
-        if (&StreamBlock != &StreamBlocks.front())<br>
+      auto StreamBlocks = File.getStreamBlockList(StreamIdx);<br>
+      for (size_t i = 0; i < StreamBlocks.size(); ++i) {<br>
+        if (i != 0)<br>
           outs() << ", ";<br>
-        outs() << StreamBlock;<br>
+        outs() << StreamBlocks[i];<br>
       }<br>
       outs() << "]\n";<br>
     }<br>
@@ -437,103 +213,107 @@ static void dumpStructure(MemoryBufferRe<br>
   StringRef DumpStreamStr = opts::DumpStreamData;<br>
   uint32_t DumpStreamNum;<br>
   if (!DumpStreamStr.getAsInteger(/*Radix=*/0U, DumpStreamNum) &&<br>
-      DumpStreamNum < NumStreams) {<br>
+      DumpStreamNum < StreamCount) {<br>
     uint32_t StreamBytesRead = 0;<br>
-    uint32_t StreamSize = Ctx.StreamSizes[DumpStreamNum];<br>
-    std::vector<uint32_t> &StreamBlocks = Ctx.StreamMap[DumpStreamNum];<br>
-    for (uint32_t &StreamBlockAddr : StreamBlocks) {<br>
-      uint64_t StreamBlockOffset = blockToOffset(StreamBlockAddr, SB->BlockSize);<br>
+    uint32_t StreamSize = File.getStreamByteSize(DumpStreamNum);<br>
+    auto StreamBlocks = File.getStreamBlockList(DumpStreamNum);<br>
+<br>
+    for (uint32_t StreamBlockAddr : StreamBlocks) {<br>
       uint32_t BytesLeftToReadInStream = StreamSize - StreamBytesRead;<br>
       if (BytesLeftToReadInStream == 0)<br>
         break;<br>
<br>
       uint32_t BytesToReadInBlock = std::min(<br>
-          BytesLeftToReadInStream, static_cast<uint32_t>(SB->BlockSize));<br>
+          BytesLeftToReadInStream, static_cast<uint32_t>(File.getBlockSize()));<br>
       auto StreamBlockData =<br>
-          StringRef(M.getBufferStart() + StreamBlockOffset, BytesToReadInBlock);<br>
-      Error(checkOffset(M, StreamBlockData));<br>
+          File.getBlockData(StreamBlockAddr, BytesToReadInBlock);<br>
<br>
       outs() << StreamBlockData;<br>
       StreamBytesRead += StreamBlockData.size();<br>
     }<br>
   }<br>
<br>
-  uint32_t Offset = 0;<br>
-<br>
   // Stream 1 starts with the following header:<br>
   //   uint32_t Version;<br>
   //   uint32_t Signature;<br>
   //   uint32_t Age;<br>
   //   GUID Guid;<br>
-  auto Version = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);<br>
-  outs() << "Version: " << Version << '\n';<br>
+  PDBStream Stream1(1, File);<br>
+  uint32_t Version;<br>
+  uint32_t Signature;<br>
+  uint32_t Age;<br>
+  PDB_UniqueId Guid;<br>
<br>
+  Stream1.readInteger(Version);<br>
+  outs() << "Version: " << Version << '\n';<br>
   // PDB's with versions before PDBImpvVC70 might not have the Guid field, we<br>
   // don't support them.<br>
   if (Version < 20000404)<br>
-    Error(std::make_error_code(std::errc::not_supported));<br>
+    reportError("", std::make_error_code(std::errc::not_supported));<br>
<br>
   // This appears to be the time the PDB was last opened by an MSVC tool?<br>
   // It is definitely a timestamp of some sort.<br>
-  auto Signature = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);<br>
+  Stream1.readInteger(Signature);<br>
   outs() << "Signature: ";<br>
   outs().write_hex(Signature) << '\n';<br>
<br>
   // This appears to be a number which is used to determine that the PDB is kept<br>
   // in sync with the EXE.<br>
-  auto Age = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);<br>
+  Stream1.readInteger(Age);<br>
   outs() << "Age: " << Age << '\n';<br>
<br>
   // I'm not sure what the purpose of the GUID is.<br>
-  using GuidTy = char[16];<br>
-  const GuidTy *Guid;<br>
-  Ctx.getObject(Guid, /*PDBStream=*/1, Offset);<br>
-  outs() << "Guid: ";<br>
-  for (char C : *Guid)<br>
-    outs().write_hex(C & 0xff) << ' ';<br>
-  outs() << '\n';<br>
+  Stream1.readObject(&Guid);<br>
+  outs() << "Guid: " << Guid << '\n';<br>
<br>
   // This is some sort of weird string-set/hash table encoded in the stream.<br>
   // It starts with the number of bytes in the table.<br>
-  auto NumberOfBytes = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);<br>
+  uint32_t NumberOfBytes;<br>
+  Stream1.readInteger(NumberOfBytes);<br>
   outs() << "NumberOfBytes: " << NumberOfBytes << '\n';<br>
<br>
   // Following that field is the starting offset of strings in the name table.<br>
-  uint32_t StringsOffset = Offset;<br>
-  Offset += NumberOfBytes;<br>
+  uint32_t StringsOffset = Stream1.getOffset();<br>
+  Stream1.setOffset(StringsOffset + NumberOfBytes);<br>
<br>
   // This appears to be equivalent to the total number of strings *actually*<br>
   // in the name table.<br>
-  auto HashSize = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);<br>
+  uint32_t HashSize;<br>
+  Stream1.readInteger(HashSize);<br>
   outs() << "HashSize: " << HashSize << '\n';<br>
<br>
   // This appears to be an upper bound on the number of strings in the name<br>
   // table.<br>
-  auto MaxNumberOfStrings = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);<br>
+  uint32_t MaxNumberOfStrings;<br>
+  Stream1.readInteger(MaxNumberOfStrings);<br>
   outs() << "MaxNumberOfStrings: " << MaxNumberOfStrings << '\n';<br>
<br>
   // This appears to be a hash table which uses bitfields to determine whether<br>
   // or not a bucket is 'present'.<br>
-  auto NumPresentWords = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);<br>
+  uint32_t NumPresentWords;<br>
+  Stream1.readInteger(NumPresentWords);<br>
   outs() << "NumPresentWords: " << NumPresentWords << '\n';<br>
<br>
   // Store all the 'present' bits in a vector for later processing.<br>
   SmallVector<uint32_t, 1> PresentWords;<br>
   for (uint32_t I = 0; I != NumPresentWords; ++I) {<br>
-    auto Word = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);<br>
+    uint32_t Word;<br>
+    Stream1.readInteger(Word);<br>
     PresentWords.push_back(Word);<br>
     outs() << "Word: " << Word << '\n';<br>
   }<br>
<br>
   // This appears to be a hash table which uses bitfields to determine whether<br>
   // or not a bucket is 'deleted'.<br>
-  auto NumDeletedWords = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);<br>
+  uint32_t NumDeletedWords;<br>
+  Stream1.readInteger(NumDeletedWords);<br>
   outs() << "NumDeletedWords: " << NumDeletedWords << '\n';<br>
<br>
   // Store all the 'deleted' bits in a vector for later processing.<br>
   SmallVector<uint32_t, 1> DeletedWords;<br>
   for (uint32_t I = 0; I != NumDeletedWords; ++I) {<br>
-    auto Word = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);<br>
+    uint32_t Word;<br>
+    Stream1.readInteger(Word);<br>
     DeletedWords.push_back(Word);<br>
     outs() << "Word: " << Word << '\n';<br>
   }<br>
@@ -554,26 +334,25 @@ static void dumpStructure(MemoryBufferRe<br>
<br>
     // This appears to be an offset relative to the start of the strings.<br>
     // It tells us where the null-terminated string begins.<br>
-    auto NameOffset = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);<br>
+    uint32_t NameOffset;<br>
+    Stream1.readInteger(NameOffset);<br>
     outs() << "NameOffset: " << NameOffset << '\n';<br>
<br>
     // This appears to be a stream number into the stream directory.<br>
-    auto NameIndex = Ctx.getInt<uint32_t>(/*PDBStream=*/1, Offset);<br>
+    uint32_t NameIndex;<br>
+    Stream1.readInteger(NameIndex);<br>
     outs() << "NameIndex: " << NameIndex << '\n';<br>
<br>
     // Compute the offset of the start of the string relative to the stream.<br>
     uint32_t StringOffset = StringsOffset + NameOffset;<br>
-<br>
+    uint32_t OldOffset = Stream1.getOffset();<br>
     // Pump out our c-string from the stream.<br>
-    SmallString<8> Str;<br>
-    char C;<br>
-    do {<br>
-      C = Ctx.getObject<char>(/*PDBStream=*/1, StringOffset);<br>
-      if (C != '\0')<br>
-        Str += C;<br>
-    } while (C != '\0');<br>
+    std::string Str;<br>
+    Stream1.setOffset(StringOffset);<br>
+    Stream1.readZeroString(Str);<br>
     outs() << "String: " << Str << "\n\n";<br>
<br>
+    Stream1.setOffset(OldOffset);<br>
     // Add this to a string-map from name to stream number.<br>
     NamedStreams.insert({Str, NameIndex});<br>
   }<br>
@@ -581,45 +360,38 @@ static void dumpStructure(MemoryBufferRe<br>
   // Let's try to dump out the named stream "/names".<br>
   auto NameI = NamedStreams.find("/names");<br>
   if (NameI != NamedStreams.end()) {<br>
-    uint32_t NameStream = NameI->second;<br>
-    outs() << "NameStream: " << NameStream << '\n';<br>
-<br>
-    uint32_t NameStreamOffset = 0;<br>
+    PDBStream NameStream(NameI->second, File);<br>
+    outs() << "NameStream: " << NameI->second << '\n';<br>
<br>
     // The name stream appears to start with a signature and version.<br>
-    auto NameStreamSignature =<br>
-        Ctx.getInt<uint32_t>(/*PDBStream=*/NameStream, NameStreamOffset);<br>
+    uint32_t NameStreamSignature;<br>
+    NameStream.readInteger(NameStreamSignature);<br>
     outs() << "NameStreamSignature: ";<br>
     outs().write_hex(NameStreamSignature) << '\n';<br>
<br>
-    auto NameStreamVersion =<br>
-        Ctx.getInt<uint32_t>(/*PDBStream=*/NameStream, NameStreamOffset);<br>
+    uint32_t NameStreamVersion;<br>
+    NameStream.readInteger(NameStreamVersion);<br>
     outs() << "NameStreamVersion: " << NameStreamVersion << '\n';<br>
<br>
     // We only support this particular version of the name stream.<br>
     if (NameStreamSignature != 0xeffeeffe || NameStreamVersion != 1)<br>
-      Error(std::make_error_code(std::errc::not_supported));<br>
+      reportError("", std::make_error_code(std::errc::not_supported));<br>
   }<br>
 }<br>
<br>
 static void dumpInput(StringRef Path) {<br>
+  std::unique_ptr<IPDBSession> Session;<br>
   if (opts::DumpHeaders || !opts::DumpStreamData.empty()) {<br>
-    ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =<br>
-        MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,<br>
-                                     /*RequiresNullTerminator=*/false);<br>
-<br>
-    if (std::error_code EC = ErrorOrBuffer.getError())<br>
-      reportError(Path, EC);<br>
-<br>
-    std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();<br>
-<br>
-    dumpStructure(Buffer->getMemBufferRef());<br>
+    PDB_ErrorCode Error = loadDataForPDB(PDB_ReaderType::Raw, Path, Session);<br>
+    if (Error == PDB_ErrorCode::Success) {<br>
+      RawSession *RS = static_cast<RawSession *>(Session.get());<br>
+      dumpStructure(*RS);<br>
+    }<br>
<br>
     outs().flush();<br>
     return;<br>
   }<br>
<br>
-  std::unique_ptr<IPDBSession> Session;<br>
   PDB_ErrorCode Error = loadDataForPDB(PDB_ReaderType::DIA, Path, Session);<br>
   switch (Error) {<br>
   case PDB_ErrorCode::Success:<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>