Coverage for /Syzygy/pdb/pdb_dbi_stream.h

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%18180.C++source

Line-by-line coverage:

   1    :  // Copyright 2012 Google Inc. All Rights Reserved.
   2    :  //
   3    :  // Licensed under the Apache License, Version 2.0 (the "License");
   4    :  // you may not use this file except in compliance with the License.
   5    :  // You may obtain a copy of the License at
   6    :  //
   7    :  //     http://www.apache.org/licenses/LICENSE-2.0
   8    :  //
   9    :  // Unless required by applicable law or agreed to in writing, software
  10    :  // distributed under the License is distributed on an "AS IS" BASIS,
  11    :  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12    :  // See the License for the specific language governing permissions and
  13    :  // limitations under the License.
  14    :  //
  15    :  // This header file provides a utility class to read a Dbi stream from a PDB and
  16    :  // give access to its data.
  17    :  //
  18    :  // The Dbi stream of a PDB contains different substream containing various
  19    :  // debug information. These different substreams are (see pdb_data.h for more
  20    :  // details on the sub-structures used in each substream):
  21    :  // - The DbiHeader;
  22    :  // - A set of DbiModuleInfoBase;
  23    :  // - A set of DbiSectionContrib;
  24    :  // - A set of DbiSectionMapItem;
  25    :  // - A set of file informations;
  26    :  // - The TS map (but this substream is always empty so we ignore it);
  27    :  // - The EC informations; and
  28    :  // - The DbiDbgHeader.
  29    :  
  30    :  #ifndef SYZYGY_PDB_PDB_DBI_STREAM_H_
  31    :  #define SYZYGY_PDB_PDB_DBI_STREAM_H_
  32    :  
  33    :  #include <map>
  34    :  #include <string>
  35    :  #include <utility>
  36    :  #include <vector>
  37    :  
  38    :  #include "syzygy/common/binary_stream.h"
  39    :  #include "syzygy/pdb/pdb_data.h"
  40    :  #include "syzygy/pdb/pdb_stream.h"
  41    :  #include "syzygy/pdb/pdb_util.h"
  42    :  
  43    :  namespace pdb {
  44    :  
  45    :  // This class represent a module info element as it is present in the module
  46    :  // info substream of the Dbi stream of a PDB file. It extends the
  47    :  // DbiModuleInfoBase structure by adding some fields with variable length.
  48    :  class DbiModuleInfo {
  49    :   public:
  50    :    // Default constructor.
  51  E :    DbiModuleInfo() {
  52  E :      memset(&module_info_base_, 0, sizeof(module_info_base_));
  53  E :    }
  54    :  
  55    :    // Copy constructor. It is required because this class is used in a STL
  56    :    // container.
  57    :    DbiModuleInfo(const DbiModuleInfo& other)
  58  E :        : module_info_base_(other.module_info_base_),
  59  E :          module_name_(other.module_name_),
  60  E :          object_name_(other.object_name_) {
  61  E :    }
  62    :  
  63    :    // Destructor.
  64  E :    ~DbiModuleInfo() {
  65  E :    }
  66    :  
  67    :    // Reads a module info from a PDB stream.
  68    :    //
  69    :    // @param stream The parser for the module info. It must be positioned
  70    :    //     at the beginning of a module info.
  71    :    // @returns true on success, false otherwise.
  72    :    bool Read(common::BinaryStreamParser* parser);
  73    :  
  74    :    // @name Accessors.
  75    :    // @{
  76  E :    const DbiModuleInfoBase& module_info_base() const {
  77  E :      return module_info_base_;
  78  E :    }
  79  E :    const std::string& module_name() const { return module_name_; }
  80    :    const std::string& object_name() const { return object_name_; }
  81    :    // @}
  82    :  
  83    :   private:
  84    :    DbiModuleInfoBase module_info_base_;
  85    :    std::string module_name_;
  86    :    std::string object_name_;
  87    :  };
  88    :  
  89    :  // This class represent the Dbi stream of a PDB. It contains some serialization
  90    :  // functions to be able to load the different substreams.
  91    :  class DbiStream {
  92    :   public:
  93    :    // Typedefs used to store the content of the Dbi Stream.
  94    :    typedef std::vector<DbiModuleInfo> DbiModuleVector;
  95    :    typedef std::vector<DbiSectionContrib> DbiSectionContribVector;
  96    :    typedef std::vector<uint32_t> DbiFileInfoFileList;
  97    :    typedef std::vector<DbiFileInfoFileList> DbiFileInfoVector;
  98    :    typedef std::map<uint32_t, std::string> DbiFileInfoNameMap;
  99    :    typedef std::pair<DbiFileInfoVector, DbiFileInfoNameMap> DbiFileInfo;
 100    :    typedef std::map<uint16_t, DbiSectionMapItem> DbiSectionMap;
 101    :    typedef OffsetStringMap DbiEcInfoVector;
 102    :  
 103    :    // Default constructor.
 104  E :    DbiStream() {
 105  E :    }
 106    :  
 107    :    // Copy constructor.
 108    :    DbiStream(const DbiStream& other)
 109    :        : header_(other.header_),
 110    :          modules_(other.modules_),
 111    :          section_contribs_(other.section_contribs_),
 112    :          section_map_(other.section_map_),
 113    :          file_info_(other.file_info_),
 114    :          ec_info_vector_(other.ec_info_vector_),
 115    :          dbg_header_(other.dbg_header_) {
 116    :    }
 117    :  
 118    :    // Destructor.
 119  E :    ~DbiStream() {
 120  E :    }
 121    :  
 122    :    // @name Accessors.
 123    :    // @{
 124    :    const DbiDbgHeader& dbg_header() const { return dbg_header_; }
 125    :    const DbiHeader& header() const { return header_; }
 126  E :    const DbiModuleVector& modules() const { return modules_; }
 127    :    const DbiSectionMap& section_map() const { return section_map_; }
 128    :    // @}
 129    :  
 130    :    // Reads the Dbi stream of a PDB.
 131    :    //
 132    :    // @param stream The stream containing the Dbi data.
 133    :    // @returns true on success, false otherwise.
 134    :    bool Read(pdb::PdbStream* stream);
 135    :  
 136    :   private:
 137    :    // Serialization of the Dbi header.
 138    :    //
 139    :    // @param stream The stream containing the Dbi header.
 140    :    // @returns true on success, false otherwise.
 141    :    bool ReadDbiHeaders(pdb::PdbStream* stream);
 142    :  
 143    :    // Serialization of the module info substream.
 144    :    //
 145    :    // @param stream The stream containing the module info substream.
 146    :    // @returns true on success, false otherwise.
 147    :    bool ReadDbiModuleInfo(pdb::PdbStream* stream);
 148    :  
 149    :    // Serialization of the section contribs substream.
 150    :    //
 151    :    // @param stream The stream containing the section contribs substream.
 152    :    // @returns true on success, false otherwise.
 153    :    bool ReadDbiSectionContribs(pdb::PdbStream* stream);
 154    :  
 155    :    // Serialization of the section map substream.
 156    :    //
 157    :    // @param stream The stream containing the section map substream.
 158    :    // @returns true on success, false otherwise.
 159    :    bool ReadDbiSectionMap(pdb::PdbStream* stream);
 160    :  
 161    :    // Serialization of the file info substream.
 162    :    //
 163    :    // @param stream The stream containing the file info substream.
 164    :    // @returns true on success, false otherwise.
 165    :    bool ReadDbiFileInfo(pdb::PdbStream* stream);
 166    :  
 167    :    // Serialization of the file-blocks section of the file info substream.
 168    :    //
 169    :    // @param stream The stream containing the file info substream.
 170    :    // @param file_blocks_table_size The size of the file-blocks table.
 171    :    // @param file_blocks_table_start The address of the beginning of the
 172    :    //     file-blocks table in the stream.
 173    :    // @param offset_table_size The size of the offset table.
 174    :    // @param offset_table_start The address of the beginning of the
 175    :    //     offset table in the stream.
 176    :    // @returns true on success, false otherwise.
 177    :    bool ReadDbiFileInfoBlocks(pdb::PdbStream* stream,
 178    :                               uint16_t file_blocks_table_size,
 179    :                               size_t file_blocks_table_start,
 180    :                               size_t offset_table_start);
 181    :  
 182    :    // Serialization of the name table in the file info substream.
 183    :    //
 184    :    // @param stream The stream containing the file info substream.
 185    :    // @param name_table_start The address of the beginning of the name table in
 186    :    //     the stream.
 187    :    // @param name_table_end The address of the end of the name table in the
 188    :    //     stream.
 189    :    // @returns true on success, false otherwise.
 190    :    bool ReadDbiFileNameTable(pdb::PdbStream* stream,
 191    :                              size_t name_table_start,
 192    :                              size_t name_table_end);
 193    :  
 194    :    // Serialization of the EC info substream. For now we don't know for what the
 195    :    // EC acronym stand for. This substream is composed of a list of source file
 196    :    // and PDB names.
 197    :    //
 198    :    // @param stream The stream containing the EC info substream.
 199    :    // @returns true on success, false otherwise.
 200    :    bool ReadDbiECInfo(pdb::PdbStream* stream);
 201    :  
 202    :    // Header of the stream.
 203    :    DbiHeader header_;
 204    :  
 205    :    // All the modules we contain.
 206    :    DbiModuleVector modules_;
 207    :  
 208    :    // All section contributions we contain.
 209    :    DbiSectionContribVector section_contribs_;
 210    :  
 211    :    // Map of the sections that we contain.
 212    :    DbiSectionMap section_map_;
 213    :  
 214    :    // File info that we contain.
 215    :    DbiFileInfo file_info_;
 216    :  
 217    :    // Vector of the EC info that we contain.
 218    :    DbiEcInfoVector ec_info_vector_;
 219    :  
 220    :    // Debug header.
 221    :    DbiDbgHeader dbg_header_;
 222    :  };
 223    :  
 224    :  }  // namespace pdb
 225    :  
 226    :  #endif  // SYZYGY_PDB_PDB_DBI_STREAM_H_

Coverage information generated Fri Jul 29 11:00:21 2016.