LCOV - code coverage report
Current view: top level - lib/DebugInfo/PDB/Native - PublicsStream.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 19 32 59.4 %
Date: 2017-09-14 15:23:50 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- PublicsStream.cpp - PDB Public Symbol Stream -----------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // The data structures defined in this file are based on the reference
      11             : // implementation which is available at
      12             : // https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.h
      13             : //
      14             : // When you are reading the reference source code, you'd find the
      15             : // information below useful.
      16             : //
      17             : //  - ppdb1->m_fMinimalDbgInfo seems to be always true.
      18             : //  - SMALLBUCKETS macro is defined.
      19             : //
      20             : // The reference doesn't compile, so I learned just by reading code.
      21             : // It's not guaranteed to be correct.
      22             : //
      23             : //===----------------------------------------------------------------------===//
      24             : 
      25             : #include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
      26             : #include "llvm/ADT/iterator_range.h"
      27             : #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
      28             : #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
      29             : #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
      30             : #include "llvm/DebugInfo/PDB/Native/RawError.h"
      31             : #include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
      32             : #include "llvm/Support/BinaryStreamReader.h"
      33             : #include "llvm/Support/Endian.h"
      34             : #include "llvm/Support/Error.h"
      35             : #include <algorithm>
      36             : #include <cstdint>
      37             : 
      38             : using namespace llvm;
      39             : using namespace llvm::msf;
      40             : using namespace llvm::support;
      41             : using namespace llvm::pdb;
      42             : 
      43           3 : PublicsStream::PublicsStream(std::unique_ptr<MappedBlockStream> Stream)
      44          18 :     : Stream(std::move(Stream)) {}
      45             : 
      46             : PublicsStream::~PublicsStream() = default;
      47             : 
      48           2 : uint32_t PublicsStream::getSymHash() const { return Header->SymHash; }
      49           1 : uint16_t PublicsStream::getThunkTableSection() const {
      50           2 :   return Header->ISectThunkTable;
      51             : }
      52           1 : uint32_t PublicsStream::getThunkTableOffset() const {
      53           2 :   return Header->OffThunkTable;
      54             : }
      55             : 
      56             : // Publics stream contains fixed-size headers and a serialized hash table.
      57             : // This implementation is not complete yet. It reads till the end of the
      58             : // stream so that we verify the stream is at least not corrupted. However,
      59             : // we skip over the hash table which we believe contains information about
      60             : // public symbols.
      61           3 : Error PublicsStream::reload() {
      62           9 :   BinaryStreamReader Reader(*Stream);
      63             : 
      64             :   // Check stream size.
      65           3 :   if (Reader.bytesRemaining() <
      66             :       sizeof(PublicsStreamHeader) + sizeof(GSIHashHeader))
      67             :     return make_error<RawError>(raw_error_code::corrupt_file,
      68           0 :                                 "Publics Stream does not contain a header.");
      69             : 
      70             :   // Read PSGSIHDR struct.
      71           9 :   if (Reader.readObject(Header))
      72             :     return make_error<RawError>(raw_error_code::corrupt_file,
      73           0 :                                 "Publics Stream does not contain a header.");
      74             : 
      75             :   // Read the hash table.
      76           9 :   if (auto E = PublicsTable.read(Reader))
      77           0 :     return E;
      78             : 
      79             :   // Something called "address map" follows.
      80           6 :   uint32_t NumAddressMapEntries = Header->AddrMap / sizeof(uint32_t);
      81           9 :   if (auto EC = Reader.readArray(AddressMap, NumAddressMapEntries))
      82           0 :     return joinErrors(std::move(EC),
      83           0 :                       make_error<RawError>(raw_error_code::corrupt_file,
      84           0 :                                            "Could not read an address map."));
      85             : 
      86             :   // Something called "thunk map" follows.
      87          12 :   if (auto EC = Reader.readArray(ThunkMap, Header->NumThunks))
      88           0 :     return joinErrors(std::move(EC),
      89           0 :                       make_error<RawError>(raw_error_code::corrupt_file,
      90           0 :                                            "Could not read a thunk map."));
      91             : 
      92             :   // Something called "section map" follows.
      93           3 :   if (Reader.bytesRemaining() > 0) {
      94           4 :     if (auto EC = Reader.readArray(SectionOffsets, Header->NumSections))
      95           0 :       return joinErrors(std::move(EC),
      96           0 :                         make_error<RawError>(raw_error_code::corrupt_file,
      97           0 :                                              "Could not read a section map."));
      98             :   }
      99             : 
     100           3 :   if (Reader.bytesRemaining() > 0)
     101             :     return make_error<RawError>(raw_error_code::corrupt_file,
     102           0 :                                 "Corrupted publics stream.");
     103           9 :   return Error::success();
     104             : }

Generated by: LCOV version 1.13