toolkit/crashreporter/google-breakpad/src/common/dwarf/bytereader-inl.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/dwarf/bytereader-inl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,175 @@
     1.4 +// Copyright 2006 Google Inc. All Rights Reserved.
     1.5 +//
     1.6 +// Redistribution and use in source and binary forms, with or without
     1.7 +// modification, are permitted provided that the following conditions are
     1.8 +// met:
     1.9 +//
    1.10 +//     * Redistributions of source code must retain the above copyright
    1.11 +// notice, this list of conditions and the following disclaimer.
    1.12 +//     * Redistributions in binary form must reproduce the above
    1.13 +// copyright notice, this list of conditions and the following disclaimer
    1.14 +// in the documentation and/or other materials provided with the
    1.15 +// distribution.
    1.16 +//     * Neither the name of Google Inc. nor the names of its
    1.17 +// contributors may be used to endorse or promote products derived from
    1.18 +// this software without specific prior written permission.
    1.19 +//
    1.20 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.21 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.22 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.23 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.24 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.25 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.26 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.27 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.28 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.29 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.30 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.31 +
    1.32 +#ifndef UTIL_DEBUGINFO_BYTEREADER_INL_H__
    1.33 +#define UTIL_DEBUGINFO_BYTEREADER_INL_H__
    1.34 +
    1.35 +#include "common/dwarf/bytereader.h"
    1.36 +
    1.37 +#include <assert.h>
    1.38 +
    1.39 +namespace dwarf2reader {
    1.40 +
    1.41 +inline uint8 ByteReader::ReadOneByte(const char* buffer) const {
    1.42 +  return buffer[0];
    1.43 +}
    1.44 +
    1.45 +inline uint16 ByteReader::ReadTwoBytes(const char* signed_buffer) const {
    1.46 +  const unsigned char *buffer
    1.47 +    = reinterpret_cast<const unsigned char *>(signed_buffer);
    1.48 +  const uint16 buffer0 = buffer[0];
    1.49 +  const uint16 buffer1 = buffer[1];
    1.50 +  if (endian_ == ENDIANNESS_LITTLE) {
    1.51 +    return buffer0 | buffer1 << 8;
    1.52 +  } else {
    1.53 +    return buffer1 | buffer0 << 8;
    1.54 +  }
    1.55 +}
    1.56 +
    1.57 +inline uint64 ByteReader::ReadFourBytes(const char* signed_buffer) const {
    1.58 +  const unsigned char *buffer
    1.59 +    = reinterpret_cast<const unsigned char *>(signed_buffer);
    1.60 +  const uint32 buffer0 = buffer[0];
    1.61 +  const uint32 buffer1 = buffer[1];
    1.62 +  const uint32 buffer2 = buffer[2];
    1.63 +  const uint32 buffer3 = buffer[3];
    1.64 +  if (endian_ == ENDIANNESS_LITTLE) {
    1.65 +    return buffer0 | buffer1 << 8 | buffer2 << 16 | buffer3 << 24;
    1.66 +  } else {
    1.67 +    return buffer3 | buffer2 << 8 | buffer1 << 16 | buffer0 << 24;
    1.68 +  }
    1.69 +}
    1.70 +
    1.71 +inline uint64 ByteReader::ReadEightBytes(const char* signed_buffer) const {
    1.72 +  const unsigned char *buffer
    1.73 +    = reinterpret_cast<const unsigned char *>(signed_buffer);
    1.74 +  const uint64 buffer0 = buffer[0];
    1.75 +  const uint64 buffer1 = buffer[1];
    1.76 +  const uint64 buffer2 = buffer[2];
    1.77 +  const uint64 buffer3 = buffer[3];
    1.78 +  const uint64 buffer4 = buffer[4];
    1.79 +  const uint64 buffer5 = buffer[5];
    1.80 +  const uint64 buffer6 = buffer[6];
    1.81 +  const uint64 buffer7 = buffer[7];
    1.82 +  if (endian_ == ENDIANNESS_LITTLE) {
    1.83 +    return buffer0 | buffer1 << 8 | buffer2 << 16 | buffer3 << 24 |
    1.84 +      buffer4 << 32 | buffer5 << 40 | buffer6 << 48 | buffer7 << 56;
    1.85 +  } else {
    1.86 +    return buffer7 | buffer6 << 8 | buffer5 << 16 | buffer4 << 24 |
    1.87 +      buffer3 << 32 | buffer2 << 40 | buffer1 << 48 | buffer0 << 56;
    1.88 +  }
    1.89 +}
    1.90 +
    1.91 +// Read an unsigned LEB128 number.  Each byte contains 7 bits of
    1.92 +// information, plus one bit saying whether the number continues or
    1.93 +// not.
    1.94 +
    1.95 +inline uint64 ByteReader::ReadUnsignedLEB128(const char* buffer,
    1.96 +                                             size_t* len) const {
    1.97 +  uint64 result = 0;
    1.98 +  size_t num_read = 0;
    1.99 +  unsigned int shift = 0;
   1.100 +  unsigned char byte;
   1.101 +
   1.102 +  do {
   1.103 +    byte = *buffer++;
   1.104 +    num_read++;
   1.105 +
   1.106 +    result |= (static_cast<uint64>(byte & 0x7f)) << shift;
   1.107 +
   1.108 +    shift += 7;
   1.109 +
   1.110 +  } while (byte & 0x80);
   1.111 +
   1.112 +  *len = num_read;
   1.113 +
   1.114 +  return result;
   1.115 +}
   1.116 +
   1.117 +// Read a signed LEB128 number.  These are like regular LEB128
   1.118 +// numbers, except the last byte may have a sign bit set.
   1.119 +
   1.120 +inline int64 ByteReader::ReadSignedLEB128(const char* buffer,
   1.121 +                                          size_t* len) const {
   1.122 +  int64 result = 0;
   1.123 +  unsigned int shift = 0;
   1.124 +  size_t num_read = 0;
   1.125 +  unsigned char byte;
   1.126 +
   1.127 +  do {
   1.128 +      byte = *buffer++;
   1.129 +      num_read++;
   1.130 +      result |= (static_cast<uint64>(byte & 0x7f) << shift);
   1.131 +      shift += 7;
   1.132 +  } while (byte & 0x80);
   1.133 +
   1.134 +  if ((shift < 8 * sizeof (result)) && (byte & 0x40))
   1.135 +    result |= -((static_cast<int64>(1)) << shift);
   1.136 +  *len = num_read;
   1.137 +  return result;
   1.138 +}
   1.139 +
   1.140 +inline uint64 ByteReader::ReadOffset(const char* buffer) const {
   1.141 +  assert(this->offset_reader_);
   1.142 +  return (this->*offset_reader_)(buffer);
   1.143 +}
   1.144 +
   1.145 +inline uint64 ByteReader::ReadAddress(const char* buffer) const {
   1.146 +  assert(this->address_reader_);
   1.147 +  return (this->*address_reader_)(buffer);
   1.148 +}
   1.149 +
   1.150 +inline void ByteReader::SetCFIDataBase(uint64 section_base,
   1.151 +                                       const char *buffer_base) {
   1.152 +  section_base_ = section_base;
   1.153 +  buffer_base_ = buffer_base;
   1.154 +  have_section_base_ = true;
   1.155 +}
   1.156 +
   1.157 +inline void ByteReader::SetTextBase(uint64 text_base) {
   1.158 +  text_base_ = text_base;
   1.159 +  have_text_base_ = true;
   1.160 +}
   1.161 +
   1.162 +inline void ByteReader::SetDataBase(uint64 data_base) {
   1.163 +  data_base_ = data_base;
   1.164 +  have_data_base_ = true;
   1.165 +}
   1.166 +
   1.167 +inline void ByteReader::SetFunctionBase(uint64 function_base) {
   1.168 +  function_base_ = function_base;
   1.169 +  have_function_base_ = true;
   1.170 +}
   1.171 +
   1.172 +inline void ByteReader::ClearFunctionBase() {
   1.173 +  have_function_base_ = false;
   1.174 +}
   1.175 +
   1.176 +}  // namespace dwarf2reader
   1.177 +
   1.178 +#endif  // UTIL_DEBUGINFO_BYTEREADER_INL_H__

mercurial