Coverage for /Syzygy/pdb/pdb_stream_record.cc

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
87.8%65740.C++source

Line-by-line coverage:

   1    :  // Copyright 2015 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    :  #include "syzygy/pdb/pdb_stream_record.h"
  16    :  
  17    :  #include "base/strings/utf_string_conversions.h"
  18    :  #include "syzygy/pdb/pdb_util.h"
  19    :  #include "syzygy/pe/cvinfo_ext.h"
  20    :  
  21    :  namespace pdb {
  22    :  
  23  E :  NumericConstant::NumericConstant() : kind_(CONSTANT_UNINITIALIZED) {
  24  E :  }
  25    :  
  26    :  bool ReadWideString(common::BinaryStreamParser* parser,
  27  E :                      base::string16* string_field) {
  28  E :    std::string narrow_string;
  29  E :    if (!parser->ReadString(&narrow_string))
  30  E :      return false;
  31  E :    return base::UTF8ToWide(narrow_string.c_str(), narrow_string.length(),
  32    :                            string_field);
  33  E :  }
  34    :  
  35    :  bool ReadUnsignedNumeric(common::BinaryStreamParser* parser,
  36  E :                           uint64_t* data_field) {
  37  E :    DCHECK_NE(static_cast<common::BinaryStreamParser*>(nullptr), parser);
  38  E :    DCHECK_NE(static_cast<uint64_t*>(nullptr), data_field);
  39    :  
  40  E :    NumericConstant numeric;
  41  E :    if (!ReadNumericConstant(parser, &numeric))
  42  E :      return false;
  43    :  
  44  E :    if (numeric.kind() != NumericConstant::CONSTANT_UNSIGNED)
  45  i :      return false;
  46    :  
  47  E :    *data_field = numeric.unsigned_value();
  48  E :    return true;
  49  E :  }
  50    :  
  51    :  bool ReadNumericConstant(common::BinaryStreamParser* parser,
  52  E :                           NumericConstant* constant) {
  53  E :    DCHECK_NE(static_cast<common::BinaryStreamParser*>(nullptr), parser);
  54  E :    DCHECK_NE(static_cast<NumericConstant*>(nullptr), constant);
  55    :  
  56  E :    uint16_t value_type = 0;
  57  E :    if (!parser->Read(&value_type))
  58  E :      return false;
  59    :  
  60    :    // If the value is small then it's simply this value.
  61  E :    if (value_type < Microsoft_Cci_Pdb::LF_NUMERIC) {
  62  E :      constant->kind_ = NumericConstant::CONSTANT_UNSIGNED;
  63  E :      constant->unsigned_value_ = value_type;
  64  E :      return true;
  65    :    }
  66    :  
  67    :    // Otherwise load the constant given its value type.
  68  E :    switch (value_type) {
  69    :      case Microsoft_Cci_Pdb::LF_CHAR: {
  70  E :        int8_t value = 0;
  71  E :        if (!parser->Read(&value))
  72  i :          return false;
  73  E :        constant->kind_ = NumericConstant::CONSTANT_SIGNED;
  74  E :        constant->signed_value_ = value;
  75  E :        return true;
  76    :      }
  77    :      case Microsoft_Cci_Pdb::LF_USHORT: {
  78  E :        uint16_t value = 0;
  79  E :        if (!parser->Read(&value))
  80  i :          return false;
  81  E :        constant->kind_ = NumericConstant::CONSTANT_UNSIGNED;
  82  E :        constant->unsigned_value_ = value;
  83  E :        return true;
  84    :      }
  85    :      case Microsoft_Cci_Pdb::LF_ULONG: {
  86  E :        uint32_t value = 0;
  87  E :        if (!parser->Read(&value))
  88  i :          return false;
  89  E :        constant->kind_ = NumericConstant::CONSTANT_UNSIGNED;
  90  E :        constant->unsigned_value_ = value;
  91  E :        return true;
  92    :      }
  93    :      case Microsoft_Cci_Pdb::LF_UQUADWORD: {
  94  E :        uint64_t value = 0;
  95  E :        if (!parser->Read(&value))
  96  i :          return false;
  97  E :        constant->kind_ = NumericConstant::CONSTANT_UNSIGNED;
  98  E :        constant->unsigned_value_ = value;
  99  E :        return true;
 100    :      }
 101    :      case Microsoft_Cci_Pdb::LF_SHORT: {
 102  E :        int16_t value = 0;
 103  E :        if (!parser->Read(&value))
 104  i :          return false;
 105  E :        constant->kind_ = NumericConstant::CONSTANT_SIGNED;
 106  E :        constant->unsigned_value_ = value;
 107  E :        return true;
 108    :      }
 109    :      case Microsoft_Cci_Pdb::LF_LONG: {
 110  E :        int32_t value = 0;
 111  E :        if (!parser->Read(&value))
 112  i :          return false;
 113  E :        constant->kind_ = NumericConstant::CONSTANT_SIGNED;
 114  E :        constant->unsigned_value_ = value;
 115  E :        return true;
 116    :      }
 117    :      case Microsoft_Cci_Pdb::LF_QUADWORD: {
 118  E :        int64_t value = 0;
 119  E :        if (!parser->Read(&value))
 120  i :          return false;
 121  E :        constant->kind_ = NumericConstant::CONSTANT_SIGNED;
 122  E :        constant->unsigned_value_ = value;
 123  E :        return true;
 124    :      }
 125  i :      default: { return false; }
 126    :    }
 127  E :  }
 128    :  
 129    :  }  // namespace pdb

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