<div dir="ltr">Alright I see what's wrong, will have a fix shortly.</div><br><div class="gmail_quote"><div dir="ltr">On Mon, May 2, 2016 at 3:12 PM Zachary Turner <<a href="mailto:zturner@google.com">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hmm, I'm not sure how.  It looks like this bot doesn't build with line information, which is unfortunate.  I can try to run an ASAN build locally, but it will take me a little bit as I normally work on Windows, and I will have to switch to Linux or get someone to help me in that regard.  I will update in a little bit.</div><br><div class="gmail_quote"><div dir="ltr">On Mon, May 2, 2016 at 2:58 PM Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Zachary,<br>
<br>
Is it possible that one of your changes around this revision introduced the ASAN failure below?<br>
<br>
You can see the failing build here: <a href="http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan_check/1606" rel="noreferrer" target="_blank">http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan_check/1606</a><br>
<br>
(still failing as of r268274)<br>
<br>
<br>
******************** TEST 'LLVM :: DebugInfo/PDB/pdbdump-headers.test' FAILED ********************<br>
<br>
Script:<br>
--<br>
llvm-pdbdump --dump-headers /Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/llvm/test/DebugInfo/PDB/Inputs/empty.pdb | /Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/FileCheck -check-prefix=EMPTY /Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/llvm/test/DebugInfo/PDB/pdbdump-headers.test<br>
llvm-pdbdump --dump-headers /Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/llvm/test/DebugInfo/PDB/Inputs/big-read.pdb | /Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/FileCheck -check-prefix=BIG /Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/llvm/test/DebugInfo/PDB/pdbdump-headers.test<br>
llvm-pdbdump --dump-headers /Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/llvm/test/DebugInfo/PDB/Inputs/bad-block-size.pdb | /Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/FileCheck -check-prefix=BAD-BLOCK-SIZE /Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/llvm/test/DebugInfo/PDB/pdbdump-headers.test<br>
--<br>
Exit Code: 2<br>
<br>
Command Output (stderr):<br>
--<br>
=================================================================<br>
==32535==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60f00000f000 at pc 0x000107ede190 bp 0x7fff57de3250 sp 0x7fff57de3248<br>
READ of size 4 at 0x60f00000f000 thread T0<br>
==32535==WARNING: Can't read from symbolizer at fd 4<br>
==32535==WARNING: Can't read from symbolizer at fd 4<br>
==32535==WARNING: Can't read from symbolizer at fd 4<br>
==32535==WARNING: Can't read from symbolizer at fd 4<br>
==32535==WARNING: Failed to use and restart external symbolizer!<br>
    #0 0x107ede18f in llvm::pdb::PDBFile::parseFileHeaders() (/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/llvm-pdbdump+0x1000c318f)<br>
    #1 0x107eeb68f in llvm::pdb::RawSession::createFromPdb(llvm::StringRef, std::__1::unique_ptr<llvm::IPDBSession, std::__1::default_delete<llvm::IPDBSession> >&) (/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/llvm-pdbdump+0x1000d068f)<br>
    #2 0x107e1ed02 in main (/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/llvm-pdbdump+0x100003d02)<br>
    #3 0x7fff8ba7c5c8 in start (/usr/lib/system/libdyld.dylib+0x35c8)<br>
    #4 0x2  (<unknown module>)<br>
<br>
0x60f00000f000 is located 2 bytes to the right of 174-byte region [0x60f00000ef50,0x60f00000effe)<br>
allocated by thread T0 here:<br>
    #0 0x10806f59b in wrap__ZnwmRKSt9nothrow_t (/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/host-compiler/lib/clang/3.8.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib+0x5659b)<br>
    #1 0x107e84c68 in llvm::MemoryBuffer::getNewUninitMemBuffer(unsigned long, llvm::Twine const&) (/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/llvm-pdbdump+0x100069c68)<br>
    #2 0x107e85ccc in getOpenFileImpl(int, llvm::Twine const&, unsigned long long, unsigned long long, long long, bool, bool) (/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/llvm-pdbdump+0x10006accc)<br>
    #3 0x107e854f2 in getFileAux(llvm::Twine const&, long long, unsigned long long, unsigned long long, bool, bool) (/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/llvm-pdbdump+0x10006a4f2)<br>
    #4 0x107e851ca in llvm::MemoryBuffer::getFileOrSTDIN(llvm::Twine const&, long long, bool) (/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/llvm-pdbdump+0x10006a1ca)<br>
    #5 0x107eeb4e3 in llvm::pdb::RawSession::createFromPdb(llvm::StringRef, std::__1::unique_ptr<llvm::IPDBSession, std::__1::default_delete<llvm::IPDBSession> >&) (/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/llvm-pdbdump+0x1000d04e3)<br>
    #6 0x107e1ed02 in main (/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/llvm-pdbdump+0x100003d02)<br>
    #7 0x7fff8ba7c5c8 in start (/usr/lib/system/libdyld.dylib+0x35c8)<br>
    #8 0x2  (<unknown module>)<br>
<br>
SUMMARY: AddressSanitizer: heap-buffer-overflow (/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-RgSan@2/clang-build/./bin/llvm-pdbdump+0x1000c318f) in llvm::pdb::PDBFile::parseFileHeaders()<br>
<br>
Thanks,<br>
<br>
--<br>
Mehdi<br>
<br>
> On Apr 29, 2016, at 10:22 AM, Zachary Turner via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: zturner<br>
> Date: Fri Apr 29 12:22:58 2016<br>
> New Revision: 268071<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=268071&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=268071&view=rev</a><br>
> Log:<br>
> Refactor the PDB Stream reading interface.<br>
><br>
> The motivation for this change is that PDB has the notion of<br>
> streams and substreams.  Substreams often consist of variable<br>
> length structures that are convenient to be able to treat as<br>
> guaranteed, contiguous byte arrays, whereas the streams they<br>
> are contained in are not necessarily so, as a single stream<br>
> could be spread across many discontiguous blocks.<br>
><br>
> So, when processing data from a substream, we want to be able<br>
> to assume that we have a contiguous byte array so that we can<br>
> cast pointers to variable length arrays and such.<br>
><br>
> This leads to the question of how to be able to read the same<br>
> data structure from either a stream or a substream using the<br>
> same interface, which is where this patch comes in.<br>
><br>
> We separate out the stream's read state from the underlying<br>
> representation, and introduce a `StreamReader` class.  Then<br>
> we change the name of `PDBStream` to `MappedBlockStream`, and<br>
> introduce a second kind of stream called a `ByteStream` which is<br>
> simply a sequence of contiguous bytes.  Finally, we update all<br>
> of the std::vectors in `PDBDbiStream` to use `ByteStream` instead<br>
> as a proof of concept.<br>
><br>
> Added:<br>
>    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/ByteStream.h<br>
>    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/MappedBlockStream.h<br>
>    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StreamInterface.h<br>
>    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StreamReader.h<br>
>    llvm/trunk/lib/DebugInfo/PDB/Raw/ByteStream.cpp<br>
>    llvm/trunk/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp<br>
>      - copied, changed from r268069, llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp<br>
>    llvm/trunk/lib/DebugInfo/PDB/Raw/StreamReader.cpp<br>
> Removed:<br>
>    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBStream.h<br>
>    llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp<br>
> Modified:<br>
>    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBDbiStream.h<br>
>    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBInfoStream.h<br>
>    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBNameMap.h<br>
>    llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt<br>
>    llvm/trunk/lib/DebugInfo/PDB/Raw/PDBDbiStream.cpp<br>
>    llvm/trunk/lib/DebugInfo/PDB/Raw/PDBInfoStream.cpp<br>
>    llvm/trunk/lib/DebugInfo/PDB/Raw/PDBNameMap.cpp<br>
>    llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp<br>
><br>
> Added: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/ByteStream.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/ByteStream.h?rev=268071&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/ByteStream.h?rev=268071&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/ByteStream.h (added)<br>
> +++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/ByteStream.h Fri Apr 29 12:22:58 2016<br>
> @@ -0,0 +1,47 @@<br>
> +//===- ByteStream.h - Reads stream data from a byte sequence ----*- 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_BYTESTREAM_H<br>
> +#define LLVM_DEBUGINFO_PDB_RAW_BYTESTREAM_H<br>
> +<br>
> +#include "llvm/ADT/ArrayRef.h"<br>
> +#include "llvm/DebugInfo/PDB/Raw/StreamInterface.h"<br>
> +<br>
> +#include <stdint.h><br>
> +<br>
> +#include <system_error><br>
> +#include <vector><br>
> +<br>
> +namespace llvm {<br>
> +class StreamReader;<br>
> +class ByteStream : public StreamInterface {<br>
> +public:<br>
> +  ByteStream();<br>
> +  explicit ByteStream(MutableArrayRef<uint8_t> Bytes);<br>
> +  explicit ByteStream(uint32_t Length);<br>
> +  ~ByteStream() override;<br>
> +<br>
> +  void reset();<br>
> +  void initialize(MutableArrayRef<uint8_t> Bytes);<br>
> +  void initialize(uint32_t Length);<br>
> +  std::error_code initialize(StreamReader &Reader, uint32_t Length);<br>
> +<br>
> +  std::error_code readBytes(uint32_t Offset,<br>
> +                            MutableArrayRef<uint8_t> Buffer) const override;<br>
> +  uint32_t getLength() const override;<br>
> +<br>
> +  ArrayRef<uint8_t> data() const { return Data; }<br>
> +<br>
> +private:<br>
> +  MutableArrayRef<uint8_t> Data;<br>
> +  bool Owned;<br>
> +};<br>
> +}<br>
> +<br>
> +#endif<br>
><br>
> Added: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/MappedBlockStream.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/MappedBlockStream.h?rev=268071&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/MappedBlockStream.h?rev=268071&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/MappedBlockStream.h (added)<br>
> +++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/MappedBlockStream.h Fri Apr 29 12:22:58 2016<br>
> @@ -0,0 +1,38 @@<br>
> +//===- MappedBlockStream.h - Reads stream data from a PDBFile ---*- 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_MAPPEDBLOCKSTREAM_H<br>
> +#define LLVM_DEBUGINFO_PDB_RAW_MAPPEDBLOCKSTREAM_H<br>
> +<br>
> +#include "llvm/DebugInfo/PDB/Raw/StreamInterface.h"<br>
> +<br>
> +#include <stdint.h><br>
> +<br>
> +#include <system_error><br>
> +#include <vector><br>
> +<br>
> +namespace llvm {<br>
> +class PDBFile;<br>
> +<br>
> +class MappedBlockStream : public StreamInterface {<br>
> +public:<br>
> +  MappedBlockStream(uint32_t StreamIdx, const PDBFile &File);<br>
> +<br>
> +  std::error_code readBytes(uint32_t Offset,<br>
> +                            MutableArrayRef<uint8_t> Buffer) const override;<br>
> +  uint32_t getLength() const override { return StreamLength; }<br>
> +<br>
> +private:<br>
> +  uint32_t StreamLength;<br>
> +  std::vector<uint32_t> BlockList;<br>
> +  const PDBFile &Pdb;<br>
> +};<br>
> +}<br>
> +<br>
> +#endif<br>
><br>
> Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBDbiStream.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBDbiStream.h?rev=268071&r1=268070&r2=268071&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBDbiStream.h?rev=268071&r1=268070&r2=268071&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBDbiStream.h (original)<br>
> +++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBDbiStream.h Fri Apr 29 12:22:58 2016<br>
> @@ -11,9 +11,10 @@<br>
> #define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H<br>
><br>
> #include "llvm/DebugInfo/PDB/PDBTypes.h"<br>
> +#include "llvm/DebugInfo/PDB/Raw/ByteStream.h"<br>
> +#include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h"<br>
> #include "llvm/DebugInfo/PDB/Raw/ModInfo.h"<br>
> #include "llvm/DebugInfo/PDB/Raw/PDBRawConstants.h"<br>
> -#include "llvm/DebugInfo/PDB/Raw/PDBStream.h"<br>
> #include "llvm/Support/Endian.h"<br>
><br>
> namespace llvm {<br>
> @@ -46,20 +47,21 @@ public:<br>
>   ArrayRef<ModuleInfoEx> modules() const;<br>
><br>
> private:<br>
> -  std::error_code readSubstream(std::vector<uint8_t> &Bytes, uint32_t Size);<br>
>   std::error_code initializeFileInfo();<br>
><br>
>   PDBFile &Pdb;<br>
> -  PDBStream Stream;<br>
> +  MappedBlockStream Stream;<br>
><br>
>   std::vector<ModuleInfoEx> ModuleInfos;<br>
><br>
> -  std::vector<uint8_t> ModInfoSubstream;<br>
> -  std::vector<uint8_t> SecContrSubstream;<br>
> -  std::vector<uint8_t> SecMapSubstream;<br>
> -  std::vector<uint8_t> FileInfoSubstream;<br>
> -  std::vector<uint8_t> TypeServerMapSubstream;<br>
> -  std::vector<uint8_t> ECSubstream;<br>
> +  ByteStream ModInfoSubstream;<br>
> +  ByteStream SecContrSubstream;<br>
> +  ByteStream SecMapSubstream;<br>
> +  ByteStream FileInfoSubstream;<br>
> +  ByteStream TypeServerMapSubstream;<br>
> +  ByteStream ECSubstream;<br>
> +  ByteStream DbgHeader;<br>
> +<br>
>   std::unique_ptr<HeaderInfo> Header;<br>
> };<br>
> }<br>
><br>
> Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBInfoStream.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBInfoStream.h?rev=268071&r1=268070&r2=268071&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBInfoStream.h?rev=268071&r1=268070&r2=268071&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBInfoStream.h (original)<br>
> +++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBInfoStream.h Fri Apr 29 12:22:58 2016<br>
> @@ -12,9 +12,9 @@<br>
><br>
> #include "llvm/ADT/StringMap.h"<br>
> #include "llvm/DebugInfo/PDB/PDBTypes.h"<br>
> +#include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h"<br>
> #include "llvm/DebugInfo/PDB/Raw/PDBNameMap.h"<br>
> #include "llvm/DebugInfo/PDB/Raw/PDBRawConstants.h"<br>
> -#include "llvm/DebugInfo/PDB/Raw/PDBStream.h"<br>
><br>
> #include "llvm/Support/Endian.h"<br>
><br>
> @@ -37,7 +37,7 @@ public:<br>
><br>
> private:<br>
>   PDBFile &Pdb;<br>
> -  PDBStream Stream1;<br>
> +  MappedBlockStream Stream;<br>
><br>
>   // PDB file format version.  We only support VC70.  See the enumeration<br>
>   // `PdbRaw_ImplVer` for the other possible values.<br>
><br>
> Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBNameMap.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBNameMap.h?rev=268071&r1=268070&r2=268071&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBNameMap.h?rev=268071&r1=268070&r2=268071&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBNameMap.h (original)<br>
> +++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBNameMap.h Fri Apr 29 12:22:58 2016<br>
> @@ -17,12 +17,12 @@<br>
> #include <utility><br>
><br>
> namespace llvm {<br>
> -class PDBStream;<br>
> +class StreamReader;<br>
> class PDBNameMap {<br>
> public:<br>
>   PDBNameMap();<br>
><br>
> -  std::error_code load(PDBStream &Stream);<br>
> +  std::error_code load(StreamReader &Stream);<br>
><br>
>   bool tryGetValue(StringRef Name, uint32_t &Value) const;<br>
><br>
><br>
> Removed: 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=268070&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBStream.h?rev=268070&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBStream.h (original)<br>
> +++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBStream.h (removed)<br>
> @@ -1,46 +0,0 @@<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/StreamInterface.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StreamInterface.h?rev=268071&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StreamInterface.h?rev=268071&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StreamInterface.h (added)<br>
> +++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StreamInterface.h Fri Apr 29 12:22:58 2016<br>
> @@ -0,0 +1,29 @@<br>
> +//===- StreamInterface.h - Base interface for 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_STREAMINTERFACE_H<br>
> +#define LLVM_DEBUGINFO_PDB_RAW_STREAMINTERFACE_H<br>
> +<br>
> +#include "llvm/ADT/ArrayRef.h"<br>
> +<br>
> +#include <stdint.h><br>
> +#include <system_error><br>
> +<br>
> +namespace llvm {<br>
> +class StreamInterface {<br>
> +public:<br>
> +  virtual ~StreamInterface() {}<br>
> +<br>
> +  virtual std::error_code readBytes(uint32_t Offset,<br>
> +                                    MutableArrayRef<uint8_t> Buffer) const = 0;<br>
> +  virtual uint32_t getLength() const = 0;<br>
> +};<br>
> +}<br>
> +<br>
> +#endif<br>
><br>
> Added: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StreamReader.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StreamReader.h?rev=268071&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StreamReader.h?rev=268071&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StreamReader.h (added)<br>
> +++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StreamReader.h Fri Apr 29 12:22:58 2016<br>
> @@ -0,0 +1,46 @@<br>
> +//===- StreamReader.h - Reads bytes and objects from a 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_STREAMREADER_H<br>
> +#define LLVM_DEBUGINFO_PDB_RAW_STREAMREADER_H<br>
> +<br>
> +#include "llvm/DebugInfo/PDB/Raw/StreamInterface.h"<br>
> +#include "llvm/Support/Endian.h"<br>
> +<br>
> +#include <string><br>
> +#include <system_error><br>
> +<br>
> +namespace llvm {<br>
> +<br>
> +class StreamReader {<br>
> +public:<br>
> +  StreamReader(const StreamInterface &S);<br>
> +<br>
> +  std::error_code readBytes(MutableArrayRef<uint8_t> Buffer);<br>
> +  std::error_code readInteger(uint32_t &Dest);<br>
> +  std::error_code readZeroString(std::string &Dest);<br>
> +<br>
> +  template <typename T> std::error_code readObject(T *Dest) {<br>
> +    MutableArrayRef<uint8_t> Buffer(reinterpret_cast<uint8_t *>(Dest),<br>
> +                                    sizeof(T));<br>
> +    return readBytes(Buffer);<br>
> +  }<br>
> +<br>
> +  void setOffset(uint32_t Off) { Offset = Off; }<br>
> +  uint32_t getOffset() const { return Offset; }<br>
> +  uint32_t getLength() const { return Stream.getLength(); }<br>
> +  uint32_t bytesRemaining() const { return getLength() - getOffset(); }<br>
> +<br>
> +private:<br>
> +  const StreamInterface &Stream;<br>
> +  uint32_t Offset;<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=268071&r1=268070&r2=268071&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt?rev=268071&r1=268070&r2=268071&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt (original)<br>
> +++ llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt Fri Apr 29 12:22:58 2016<br>
> @@ -27,13 +27,15 @@ if(HAVE_DIA_SDK)<br>
> endif()<br>
><br>
> add_pdb_impl_folder(Raw<br>
> +  Raw/ByteStream.cpp<br>
> +  Raw/MappedBlockStream.cpp<br>
>   Raw/ModInfo.cpp<br>
>   Raw/PDBFile.cpp<br>
>   Raw/PDBDbiStream.cpp<br>
>   Raw/PDBInfoStream.cpp<br>
>   Raw/PDBNameMap.cpp<br>
> -  Raw/PDBStream.cpp<br>
> -  Raw/RawSession.cpp)<br>
> +  Raw/RawSession.cpp<br>
> +  Raw/StreamReader.cpp)<br>
><br>
> list(APPEND LIBPDB_ADDITIONAL_HEADER_DIRS "${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/PDB")<br>
><br>
><br>
> Added: llvm/trunk/lib/DebugInfo/PDB/Raw/ByteStream.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/ByteStream.cpp?rev=268071&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/ByteStream.cpp?rev=268071&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/DebugInfo/PDB/Raw/ByteStream.cpp (added)<br>
> +++ llvm/trunk/lib/DebugInfo/PDB/Raw/ByteStream.cpp Fri Apr 29 12:22:58 2016<br>
> @@ -0,0 +1,60 @@<br>
> +//===- ByteStream.cpp - Reads stream data from a byte sequence ------------===//<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/ByteStream.h"<br>
> +#include "llvm/DebugInfo/PDB/Raw/StreamReader.h"<br>
> +<br>
> +using namespace llvm;<br>
> +<br>
> +ByteStream::ByteStream() : Owned(false) {}<br>
> +<br>
> +ByteStream::ByteStream(MutableArrayRef<uint8_t> Bytes) : Owned(false) {<br>
> +  initialize(Bytes);<br>
> +}<br>
> +<br>
> +ByteStream::ByteStream(uint32_t Length) : Owned(false) { initialize(Length); }<br>
> +<br>
> +ByteStream::~ByteStream() { reset(); }<br>
> +<br>
> +void ByteStream::reset() {<br>
> +  if (Owned)<br>
> +    delete[] Data.data();<br>
> +  Owned = false;<br>
> +  Data = MutableArrayRef<uint8_t>();<br>
> +}<br>
> +<br>
> +void ByteStream::initialize(MutableArrayRef<uint8_t> Bytes) {<br>
> +  reset();<br>
> +  Data = Bytes;<br>
> +  Owned = false;<br>
> +}<br>
> +<br>
> +void ByteStream::initialize(uint32_t Length) {<br>
> +  reset();<br>
> +  Data = MutableArrayRef<uint8_t>(new uint8_t[Length], Length);<br>
> +  Owned = true;<br>
> +}<br>
> +<br>
> +std::error_code ByteStream::initialize(StreamReader &Reader, uint32_t Length) {<br>
> +  initialize(Length);<br>
> +  std::error_code EC = Reader.readBytes(Data);<br>
> +  if (EC)<br>
> +    reset();<br>
> +  return EC;<br>
> +}<br>
> +<br>
> +std::error_code ByteStream::readBytes(uint32_t Offset,<br>
> +                                      MutableArrayRef<uint8_t> Buffer) const {<br>
> +  if (Data.size() < Buffer.size() + Offset)<br>
> +    return std::make_error_code(std::errc::bad_address);<br>
> +  ::memcpy(Buffer.data(), Data.data() + Offset, Buffer.size());<br>
> +  return std::error_code();<br>
> +}<br>
> +<br>
> +uint32_t ByteStream::getLength() const { return Data.size(); }<br>
><br>
> Copied: llvm/trunk/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp (from r268069, llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp)<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp?p2=llvm/trunk/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp&p1=llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp&r1=268069&r2=268071&rev=268071&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp?p2=llvm/trunk/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp&p1=llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp&r1=268069&r2=268071&rev=268071&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp (original)<br>
> +++ llvm/trunk/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp Fri Apr 29 12:22:58 2016<br>
> @@ -1,4 +1,4 @@<br>
> -//===- PDBStream.cpp - Low level interface to a PDB stream ------*- C++ -*-===//<br>
> +//===- MappedBlockStream.cpp - Reads stream data from a PDBFile -----------===//<br>
> //<br>
> //                     The LLVM Compiler Infrastructure<br>
> //<br>
> @@ -7,48 +7,31 @@<br>
> //<br>
> //===----------------------------------------------------------------------===//<br>
><br>
> -#include "llvm/DebugInfo/PDB/Raw/PDBStream.h"<br>
> +#include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h"<br>
> #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"<br>
><br>
> using namespace llvm;<br>
><br>
> -PDBStream::PDBStream(uint32_t StreamIdx, const PDBFile &File) : Pdb(File) {<br>
> +MappedBlockStream::MappedBlockStream(uint32_t StreamIdx, const PDBFile &File) : Pdb(File) {<br>
>   StreamLength = Pdb.getStreamByteSize(StreamIdx);<br>
>   BlockList = Pdb.getStreamBlockList(StreamIdx);<br>
> -  Offset = 0;<br>
> }<br>
><br>
> -std::error_code PDBStream::readInteger(uint32_t &Dest) {<br>
> -  support::ulittle32_t 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>
> +std::error_code<br>
> +MappedBlockStream::readBytes(uint32_t Offset,<br>
> +                             MutableArrayRef<uint8_t> Buffer) const {<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 (Length > StreamLength)<br>
> +  if (Buffer.size() > StreamLength)<br>
>     return std::make_error_code(std::errc::bad_address);<br>
> -  if (Offset > StreamLength - Length)<br>
> +  if (Offset > StreamLength - Buffer.size())<br>
>     return std::make_error_code(std::errc::bad_address);<br>
><br>
> -  uint32_t BytesLeft = Length;<br>
> +  uint32_t BytesLeft = Buffer.size();<br>
>   uint32_t BytesWritten = 0;<br>
> -  char *WriteBuffer = static_cast<char *>(Dest);<br>
> +  uint8_t *WriteBuffer = Buffer.data();<br>
>   while (BytesLeft > 0) {<br>
>     uint32_t StreamBlockAddr = BlockList[BlockNum];<br>
><br>
> @@ -65,14 +48,5 @@ std::error_code PDBStream::readBytes(voi<br>
>     OffsetInBlock = 0;<br>
>   }<br>
><br>
> -  // Modify the offset to point to the data after the object.<br>
> -  Offset += Length;<br>
> -<br>
>   return std::error_code();<br>
> }<br>
> -<br>
> -void PDBStream::setOffset(uint32_t O) { Offset = O; }<br>
> -<br>
> -uint32_t PDBStream::getOffset() const { return Offset; }<br>
> -<br>
> -uint32_t PDBStream::getLength() const { return StreamLength; }<br>
><br>
> Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBDbiStream.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBDbiStream.cpp?rev=268071&r1=268070&r2=268071&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBDbiStream.cpp?rev=268071&r1=268070&r2=268071&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBDbiStream.cpp (original)<br>
> +++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBDbiStream.cpp Fri Apr 29 12:22:58 2016<br>
> @@ -12,6 +12,7 @@<br>
> #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"<br>
> #include "llvm/DebugInfo/PDB/Raw/PDBInfoStream.h"<br>
> #include "llvm/DebugInfo/PDB/Raw/PDBRawConstants.h"<br>
> +#include "llvm/DebugInfo/PDB/Raw/StreamReader.h"<br>
><br>
> using namespace llvm;<br>
> using namespace llvm::support;<br>
> @@ -58,12 +59,12 @@ struct PDBDbiStream::HeaderInfo {<br>
>   little32_t SecContrSubstreamSize; // Size of sec. contribution stream<br>
>   little32_t SectionMapSize;        // Size of sec. map substream<br>
>   little32_t FileInfoSize;          // Size of file info substream<br>
> -  little32_t TypeServerSize;      // Size of type server map<br>
> -  ulittle32_t MFCTypeServerIndex; // Index of MFC Type Server<br>
> -  little32_t OptionalDbgHdrSize;  // Size of DbgHeader info<br>
> -  little32_t ECSubstreamSize;     // Size of EC stream (what is EC?)<br>
> -  ulittle16_t Flags;              // See DbiFlags enum.<br>
> -  ulittle16_t MachineType;        // See PDB_MachineType enum.<br>
> +  little32_t TypeServerSize;        // Size of type server map<br>
> +  ulittle32_t MFCTypeServerIndex;   // Index of MFC Type Server<br>
> +  little32_t OptionalDbgHdrSize;    // Size of DbgHeader info<br>
> +  little32_t ECSubstreamSize;       // Size of EC stream (what is EC?)<br>
> +  ulittle16_t Flags;                // See DbiFlags enum.<br>
> +  ulittle16_t MachineType;          // See PDB_MachineType enum.<br>
><br>
>   ulittle32_t Reserved; // Pad to 64 bytes<br>
> };<br>
> @@ -75,12 +76,13 @@ PDBDbiStream::PDBDbiStream(PDBFile &File<br>
> PDBDbiStream::~PDBDbiStream() {}<br>
><br>
> std::error_code PDBDbiStream::reload() {<br>
> -  Stream.setOffset(0);<br>
> +  StreamReader Reader(Stream);<br>
> +<br>
>   Header.reset(new HeaderInfo());<br>
><br>
>   if (Stream.getLength() < sizeof(HeaderInfo))<br>
>     return std::make_error_code(std::errc::illegal_byte_sequence);<br>
> -  Stream.readObject(Header.get());<br>
> +  Reader.readObject(Header.get());<br>
><br>
>   if (Header->VersionSignature != -1)<br>
>     return std::make_error_code(std::errc::illegal_byte_sequence);<br>
> @@ -115,30 +117,35 @@ std::error_code PDBDbiStream::reload() {<br>
>     return std::make_error_code(std::errc::illegal_byte_sequence);<br>
><br>
>   std::error_code EC;<br>
> -  if ((EC = readSubstream(ModInfoSubstream, Header->ModiSubstreamSize)))<br>
> -    return EC;<br>
> +  ModInfoSubstream.initialize(Reader, Header->ModiSubstreamSize);<br>
><br>
>   // Since each ModInfo in the stream is a variable length, we have to iterate<br>
>   // them to know how many there actually are.<br>
> -  auto Range = llvm::make_range(ModInfoIterator(&ModInfoSubstream.front()),<br>
> -                                ModInfoIterator(&ModInfoSubstream.back() + 1));<br>
> +  auto Range =<br>
> +      llvm::make_range(ModInfoIterator(&ModInfoSubstream.data().front()),<br>
> +                       ModInfoIterator(&ModInfoSubstream.data().back() + 1));<br>
>   for (auto Info : Range)<br>
>     ModuleInfos.push_back(ModuleInfoEx(Info));<br>
><br>
> -  if ((EC = readSubstream(SecContrSubstream, Header->SecContrSubstreamSize)))<br>
> +  if ((EC = SecContrSubstream.initialize(Reader, Header->SecContrSubstreamSize)))<br>
>     return EC;<br>
> -  if ((EC = readSubstream(SecMapSubstream, Header->SectionMapSize)))<br>
> +  if ((EC = SecMapSubstream.initialize(Reader, Header->SectionMapSize)))<br>
>     return EC;<br>
> -  if ((EC = readSubstream(FileInfoSubstream, Header->FileInfoSize)))<br>
> +  if ((EC = FileInfoSubstream.initialize(Reader, Header->FileInfoSize)))<br>
>     return EC;<br>
> -  if ((EC = readSubstream(TypeServerMapSubstream, Header->TypeServerSize)))<br>
> +  if ((EC = TypeServerMapSubstream.initialize(Reader, Header->TypeServerSize)))<br>
>     return EC;<br>
> -  if ((EC = readSubstream(ECSubstream, Header->ECSubstreamSize)))<br>
> +  if ((EC = ECSubstream.initialize(Reader, Header->ECSubstreamSize)))<br>
> +    return EC;<br>
> +  if ((EC = DbgHeader.initialize(Reader, Header->OptionalDbgHdrSize)))<br>
>     return EC;<br>
><br>
>   if ((EC = initializeFileInfo()))<br>
>     return EC;<br>
><br>
> +  if (Reader.bytesRemaining() > 0)<br>
> +    return std::make_error_code(std::errc::illegal_byte_sequence);<br>
> +<br>
>   return std::error_code();<br>
> }<br>
><br>
> @@ -182,15 +189,6 @@ PDB_Machine PDBDbiStream::getMachineType<br>
><br>
> ArrayRef<ModuleInfoEx> PDBDbiStream::modules() const { return ModuleInfos; }<br>
><br>
> -std::error_code PDBDbiStream::readSubstream(std::vector<uint8_t> &Bytes, uint32_t Size) {<br>
> -  Bytes.clear();<br>
> -  if (Size == 0)<br>
> -    return std::error_code();<br>
> -<br>
> -  Bytes.resize(Size);<br>
> -  return Stream.readBytes(&Bytes[0], Size);<br>
> -}<br>
> -<br>
> std::error_code PDBDbiStream::initializeFileInfo() {<br>
>   struct FileInfoSubstreamHeader {<br>
>     ulittle16_t NumModules;     // Total # of modules, should match number of<br>
> @@ -213,7 +211,7 @@ std::error_code PDBDbiStream::initialize<br>
>   // with the caveat that `NumSourceFiles` cannot be trusted, so<br>
>   // it is computed by summing `ModFileCounts`.<br>
>   //<br>
> -  const uint8_t *Buf = &FileInfoSubstream[0];<br>
> +  const uint8_t *Buf = &FileInfoSubstream.data().front();<br>
>   auto FI = reinterpret_cast<const FileInfoSubstreamHeader *>(Buf);<br>
>   Buf += sizeof(FileInfoSubstreamHeader);<br>
>   // The number of modules in the stream should be the same as reported by<br>
><br>
> Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBInfoStream.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBInfoStream.cpp?rev=268071&r1=268070&r2=268071&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBInfoStream.cpp?rev=268071&r1=268070&r2=268071&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBInfoStream.cpp (original)<br>
> +++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBInfoStream.cpp Fri Apr 29 12:22:58 2016<br>
> @@ -10,28 +10,30 @@<br>
> #include "llvm/DebugInfo/PDB/Raw/PDBInfoStream.h"<br>
> #include "llvm/ADT/BitVector.h"<br>
> #include "llvm/ADT/SmallVector.h"<br>
> +#include "llvm/DebugInfo/PDB/Raw/StreamReader.h"<br>
><br>
> using namespace llvm;<br>
><br>
> -PDBInfoStream::PDBInfoStream(PDBFile &File) : Pdb(File), Stream1(1, File) {}<br>
> +PDBInfoStream::PDBInfoStream(PDBFile &File) : Pdb(File), Stream(1, File) {}<br>
><br>
> std::error_code PDBInfoStream::reload() {<br>
> -  Stream1.setOffset(0);<br>
> +  StreamReader Reader(Stream);<br>
> +<br>
>   support::ulittle32_t Value;<br>
><br>
> -  Stream1.readObject(&Value);<br>
> +  Reader.readObject(&Value);<br>
>   Version = Value;<br>
>   if (Version < PdbRaw_ImplVer::PdbImplVC70)<br>
>     return std::make_error_code(std::errc::not_supported);<br>
><br>
> -  Stream1.readObject(&Value);<br>
> +  Reader.readObject(&Value);<br>
>   Signature = Value;<br>
><br>
> -  Stream1.readObject(&Value);<br>
> +  Reader.readObject(&Value);<br>
>   Age = Value;<br>
><br>
> -  Stream1.readObject(&Guid);<br>
> -  NamedStreams.load(Stream1);<br>
> +  Reader.readObject(&Guid);<br>
> +  NamedStreams.load(Reader);<br>
><br>
>   return std::error_code();<br>
> }<br>
><br>
> Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBNameMap.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBNameMap.cpp?rev=268071&r1=268070&r2=268071&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBNameMap.cpp?rev=268071&r1=268070&r2=268071&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBNameMap.cpp (original)<br>
> +++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBNameMap.cpp Fri Apr 29 12:22:58 2016<br>
> @@ -9,13 +9,14 @@<br>
><br>
> #include "llvm/DebugInfo/PDB/Raw/PDBNameMap.h"<br>
> #include "llvm/ADT/BitVector.h"<br>
> -#include "llvm/DebugInfo/PDB/Raw/PDBStream.h"<br>
> +#include "llvm/DebugInfo/PDB/Raw/StreamReader.h"<br>
><br>
> using namespace llvm;<br>
><br>
> PDBNameMap::PDBNameMap() {}<br>
><br>
> -std::error_code PDBNameMap::load(PDBStream &Stream) {<br>
> +std::error_code PDBNameMap::load(StreamReader &Stream) {<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>
>   uint32_t NumberOfBytes;<br>
><br>
> Removed: 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=268070&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp?rev=268070&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp (original)<br>
> +++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBStream.cpp (removed)<br>
> @@ -1,78 +0,0 @@<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>
> -PDBStream::PDBStream(uint32_t StreamIdx, const PDBFile &File) : Pdb(File) {<br>
> -  StreamLength = Pdb.getStreamByteSize(StreamIdx);<br>
> -  BlockList = Pdb.getStreamBlockList(StreamIdx);<br>
> -  Offset = 0;<br>
> -}<br>
> -<br>
> -std::error_code PDBStream::readInteger(uint32_t &Dest) {<br>
> -  support::ulittle32_t 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 (Length > StreamLength)<br>
> -    return std::make_error_code(std::errc::bad_address);<br>
> -  if (Offset > StreamLength - Length)<br>
> -    return std::make_error_code(std::errc::bad_address);<br>
> -<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 = BlockList[BlockNum];<br>
> -<br>
> -    StringRef Data = Pdb.getBlockData(StreamBlockAddr, Pdb.getBlockSize());<br>
> -<br>
> -    const char *ChunkStart = Data.data() + OffsetInBlock;<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>
> -<br>
> -  // Modify the offset to point to the data after the object.<br>
> -  Offset += Length;<br>
> -<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -void PDBStream::setOffset(uint32_t O) { Offset = O; }<br>
> -<br>
> -uint32_t PDBStream::getOffset() const { return Offset; }<br>
> -<br>
> -uint32_t PDBStream::getLength() const { return StreamLength; }<br>
><br>
> Added: llvm/trunk/lib/DebugInfo/PDB/Raw/StreamReader.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/StreamReader.cpp?rev=268071&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/StreamReader.cpp?rev=268071&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/DebugInfo/PDB/Raw/StreamReader.cpp (added)<br>
> +++ llvm/trunk/lib/DebugInfo/PDB/Raw/StreamReader.cpp Fri Apr 29 12:22:58 2016<br>
> @@ -0,0 +1,40 @@<br>
> +//===- StreamReader.cpp - Reads bytes and objects from a stream -----------===//<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/StreamReader.h"<br>
> +<br>
> +using namespace llvm;<br>
> +<br>
> +StreamReader::StreamReader(const StreamInterface &S) : Stream(S), Offset(0) {}<br>
> +<br>
> +std::error_code StreamReader::readBytes(MutableArrayRef<uint8_t> Buffer) {<br>
> +  if (auto EC = Stream.readBytes(Offset, Buffer))<br>
> +    return EC;<br>
> +  Offset += Buffer.size();<br>
> +  return std::error_code();<br>
> +}<br>
> +<br>
> +std::error_code StreamReader::readInteger(uint32_t &Dest) {<br>
> +  support::ulittle32_t 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 StreamReader::readZeroString(std::string &Dest) {<br>
> +  Dest.clear();<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>
> 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=268071&r1=268070&r2=268071&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp?rev=268071&r1=268070&r2=268071&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp (original)<br>
> +++ llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp Fri Apr 29 12:22:58 2016<br>
> @@ -35,12 +35,13 @@<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/MappedBlockStream.h"<br>
> #include "llvm/DebugInfo/PDB/Raw/ModInfo.h"<br>
> #include "llvm/DebugInfo/PDB/Raw/PDBDbiStream.h"<br>
> #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"<br>
> #include "llvm/DebugInfo/PDB/Raw/PDBInfoStream.h"<br>
> -#include "llvm/DebugInfo/PDB/Raw/PDBStream.h"<br>
> #include "llvm/DebugInfo/PDB/Raw/RawSession.h"<br>
> +#include "llvm/DebugInfo/PDB/Raw/StreamReader.h"<br>
> #include "llvm/Support/CommandLine.h"<br>
> #include "llvm/Support/ConvertUTF.h"<br>
> #include "llvm/Support/FileSystem.h"<br>
> @@ -246,17 +247,19 @@ static void dumpStructure(RawSession &RS<br>
>   // Let's try to dump out the named stream "/names".<br>
>   uint32_t NameStreamIndex = InfoStream.getNamedStreamIndex("/names");<br>
>   if (NameStreamIndex != 0) {<br>
> -    PDBStream NameStream(NameStreamIndex, File);<br>
> +    MappedBlockStream NameStream(NameStreamIndex, File);<br>
> +    StreamReader Reader(NameStream);<br>
> +<br>
>     outs() << "NameStream: " << NameStreamIndex << '\n';<br>
><br>
>     // The name stream appears to start with a signature and version.<br>
>     uint32_t NameStreamSignature;<br>
> -    NameStream.readInteger(NameStreamSignature);<br>
> +    Reader.readInteger(NameStreamSignature);<br>
>     outs() << "NameStreamSignature: ";<br>
>     outs().write_hex(NameStreamSignature) << '\n';<br>
><br>
>     uint32_t NameStreamVersion;<br>
> -    NameStream.readInteger(NameStreamVersion);<br>
> +    Reader.readInteger(NameStreamVersion);<br>
>     outs() << "NameStreamVersion: " << NameStreamVersion << '\n';<br>
><br>
>     // We only support this particular version of the name stream.<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">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>
<br>
</blockquote></div></blockquote></div>