| OLD | NEW |
| 1 // Copyright 2006 Google Inc. All Rights Reserved. | 1 // Copyright 2006 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are | 4 // modification, are permitted provided that the following conditions are |
| 5 // met: | 5 // met: |
| 6 // | 6 // |
| 7 // * Redistributions of source code must retain the above copyright | 7 // * Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
| 9 // * Redistributions in binary form must reproduce the above | 9 // * Redistributions in binary form must reproduce the above |
| 10 // copyright notice, this list of conditions and the following disclaimer | 10 // copyright notice, this list of conditions and the following disclaimer |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 #ifndef UTIL_DEBUGINFO_BYTEREADER_INL_H__ | 29 #ifndef UTIL_DEBUGINFO_BYTEREADER_INL_H__ |
| 30 #define UTIL_DEBUGINFO_BYTEREADER_INL_H__ | 30 #define UTIL_DEBUGINFO_BYTEREADER_INL_H__ |
| 31 | 31 |
| 32 #include "common/dwarf/bytereader.h" | 32 #include "common/dwarf/bytereader.h" |
| 33 | 33 |
| 34 #include <assert.h> | 34 #include <assert.h> |
| 35 #include <stdint.h> |
| 35 | 36 |
| 36 namespace dwarf2reader { | 37 namespace dwarf2reader { |
| 37 | 38 |
| 38 inline uint8 ByteReader::ReadOneByte(const char* buffer) const { | 39 inline uint8 ByteReader::ReadOneByte(const uint8_t *buffer) const { |
| 39 return buffer[0]; | 40 return buffer[0]; |
| 40 } | 41 } |
| 41 | 42 |
| 42 inline uint16 ByteReader::ReadTwoBytes(const char* signed_buffer) const { | 43 inline uint16 ByteReader::ReadTwoBytes(const uint8_t *buffer) const { |
| 43 const unsigned char *buffer | |
| 44 = reinterpret_cast<const unsigned char *>(signed_buffer); | |
| 45 const uint16 buffer0 = buffer[0]; | 44 const uint16 buffer0 = buffer[0]; |
| 46 const uint16 buffer1 = buffer[1]; | 45 const uint16 buffer1 = buffer[1]; |
| 47 if (endian_ == ENDIANNESS_LITTLE) { | 46 if (endian_ == ENDIANNESS_LITTLE) { |
| 48 return buffer0 | buffer1 << 8; | 47 return buffer0 | buffer1 << 8; |
| 49 } else { | 48 } else { |
| 50 return buffer1 | buffer0 << 8; | 49 return buffer1 | buffer0 << 8; |
| 51 } | 50 } |
| 52 } | 51 } |
| 53 | 52 |
| 54 inline uint64 ByteReader::ReadFourBytes(const char* signed_buffer) const { | 53 inline uint64 ByteReader::ReadFourBytes(const uint8_t *buffer) const { |
| 55 const unsigned char *buffer | |
| 56 = reinterpret_cast<const unsigned char *>(signed_buffer); | |
| 57 const uint32 buffer0 = buffer[0]; | 54 const uint32 buffer0 = buffer[0]; |
| 58 const uint32 buffer1 = buffer[1]; | 55 const uint32 buffer1 = buffer[1]; |
| 59 const uint32 buffer2 = buffer[2]; | 56 const uint32 buffer2 = buffer[2]; |
| 60 const uint32 buffer3 = buffer[3]; | 57 const uint32 buffer3 = buffer[3]; |
| 61 if (endian_ == ENDIANNESS_LITTLE) { | 58 if (endian_ == ENDIANNESS_LITTLE) { |
| 62 return buffer0 | buffer1 << 8 | buffer2 << 16 | buffer3 << 24; | 59 return buffer0 | buffer1 << 8 | buffer2 << 16 | buffer3 << 24; |
| 63 } else { | 60 } else { |
| 64 return buffer3 | buffer2 << 8 | buffer1 << 16 | buffer0 << 24; | 61 return buffer3 | buffer2 << 8 | buffer1 << 16 | buffer0 << 24; |
| 65 } | 62 } |
| 66 } | 63 } |
| 67 | 64 |
| 68 inline uint64 ByteReader::ReadEightBytes(const char* signed_buffer) const { | 65 inline uint64 ByteReader::ReadEightBytes(const uint8_t *buffer) const { |
| 69 const unsigned char *buffer | |
| 70 = reinterpret_cast<const unsigned char *>(signed_buffer); | |
| 71 const uint64 buffer0 = buffer[0]; | 66 const uint64 buffer0 = buffer[0]; |
| 72 const uint64 buffer1 = buffer[1]; | 67 const uint64 buffer1 = buffer[1]; |
| 73 const uint64 buffer2 = buffer[2]; | 68 const uint64 buffer2 = buffer[2]; |
| 74 const uint64 buffer3 = buffer[3]; | 69 const uint64 buffer3 = buffer[3]; |
| 75 const uint64 buffer4 = buffer[4]; | 70 const uint64 buffer4 = buffer[4]; |
| 76 const uint64 buffer5 = buffer[5]; | 71 const uint64 buffer5 = buffer[5]; |
| 77 const uint64 buffer6 = buffer[6]; | 72 const uint64 buffer6 = buffer[6]; |
| 78 const uint64 buffer7 = buffer[7]; | 73 const uint64 buffer7 = buffer[7]; |
| 79 if (endian_ == ENDIANNESS_LITTLE) { | 74 if (endian_ == ENDIANNESS_LITTLE) { |
| 80 return buffer0 | buffer1 << 8 | buffer2 << 16 | buffer3 << 24 | | 75 return buffer0 | buffer1 << 8 | buffer2 << 16 | buffer3 << 24 | |
| 81 buffer4 << 32 | buffer5 << 40 | buffer6 << 48 | buffer7 << 56; | 76 buffer4 << 32 | buffer5 << 40 | buffer6 << 48 | buffer7 << 56; |
| 82 } else { | 77 } else { |
| 83 return buffer7 | buffer6 << 8 | buffer5 << 16 | buffer4 << 24 | | 78 return buffer7 | buffer6 << 8 | buffer5 << 16 | buffer4 << 24 | |
| 84 buffer3 << 32 | buffer2 << 40 | buffer1 << 48 | buffer0 << 56; | 79 buffer3 << 32 | buffer2 << 40 | buffer1 << 48 | buffer0 << 56; |
| 85 } | 80 } |
| 86 } | 81 } |
| 87 | 82 |
| 88 // Read an unsigned LEB128 number. Each byte contains 7 bits of | 83 // Read an unsigned LEB128 number. Each byte contains 7 bits of |
| 89 // information, plus one bit saying whether the number continues or | 84 // information, plus one bit saying whether the number continues or |
| 90 // not. | 85 // not. |
| 91 | 86 |
| 92 inline uint64 ByteReader::ReadUnsignedLEB128(const char* buffer, | 87 inline uint64 ByteReader::ReadUnsignedLEB128(const uint8_t *buffer, |
| 93 size_t* len) const { | 88 size_t* len) const { |
| 94 uint64 result = 0; | 89 uint64 result = 0; |
| 95 size_t num_read = 0; | 90 size_t num_read = 0; |
| 96 unsigned int shift = 0; | 91 unsigned int shift = 0; |
| 97 unsigned char byte; | 92 uint8_t byte; |
| 98 | 93 |
| 99 do { | 94 do { |
| 100 byte = *buffer++; | 95 byte = *buffer++; |
| 101 num_read++; | 96 num_read++; |
| 102 | 97 |
| 103 result |= (static_cast<uint64>(byte & 0x7f)) << shift; | 98 result |= (static_cast<uint64>(byte & 0x7f)) << shift; |
| 104 | 99 |
| 105 shift += 7; | 100 shift += 7; |
| 106 | 101 |
| 107 } while (byte & 0x80); | 102 } while (byte & 0x80); |
| 108 | 103 |
| 109 *len = num_read; | 104 *len = num_read; |
| 110 | 105 |
| 111 return result; | 106 return result; |
| 112 } | 107 } |
| 113 | 108 |
| 114 // Read a signed LEB128 number. These are like regular LEB128 | 109 // Read a signed LEB128 number. These are like regular LEB128 |
| 115 // numbers, except the last byte may have a sign bit set. | 110 // numbers, except the last byte may have a sign bit set. |
| 116 | 111 |
| 117 inline int64 ByteReader::ReadSignedLEB128(const char* buffer, | 112 inline int64 ByteReader::ReadSignedLEB128(const uint8_t *buffer, |
| 118 size_t* len) const { | 113 size_t* len) const { |
| 119 int64 result = 0; | 114 int64 result = 0; |
| 120 unsigned int shift = 0; | 115 unsigned int shift = 0; |
| 121 size_t num_read = 0; | 116 size_t num_read = 0; |
| 122 unsigned char byte; | 117 uint8_t byte; |
| 123 | 118 |
| 124 do { | 119 do { |
| 125 byte = *buffer++; | 120 byte = *buffer++; |
| 126 num_read++; | 121 num_read++; |
| 127 result |= (static_cast<uint64>(byte & 0x7f) << shift); | 122 result |= (static_cast<uint64>(byte & 0x7f) << shift); |
| 128 shift += 7; | 123 shift += 7; |
| 129 } while (byte & 0x80); | 124 } while (byte & 0x80); |
| 130 | 125 |
| 131 if ((shift < 8 * sizeof (result)) && (byte & 0x40)) | 126 if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
| 132 result |= -((static_cast<int64>(1)) << shift); | 127 result |= -((static_cast<int64>(1)) << shift); |
| 133 *len = num_read; | 128 *len = num_read; |
| 134 return result; | 129 return result; |
| 135 } | 130 } |
| 136 | 131 |
| 137 inline uint64 ByteReader::ReadOffset(const char* buffer) const { | 132 inline uint64 ByteReader::ReadOffset(const uint8_t *buffer) const { |
| 138 assert(this->offset_reader_); | 133 assert(this->offset_reader_); |
| 139 return (this->*offset_reader_)(buffer); | 134 return (this->*offset_reader_)(buffer); |
| 140 } | 135 } |
| 141 | 136 |
| 142 inline uint64 ByteReader::ReadAddress(const char* buffer) const { | 137 inline uint64 ByteReader::ReadAddress(const uint8_t *buffer) const { |
| 143 assert(this->address_reader_); | 138 assert(this->address_reader_); |
| 144 return (this->*address_reader_)(buffer); | 139 return (this->*address_reader_)(buffer); |
| 145 } | 140 } |
| 146 | 141 |
| 147 inline void ByteReader::SetCFIDataBase(uint64 section_base, | 142 inline void ByteReader::SetCFIDataBase(uint64 section_base, |
| 148 const char *buffer_base) { | 143 const uint8_t *buffer_base) { |
| 149 section_base_ = section_base; | 144 section_base_ = section_base; |
| 150 buffer_base_ = buffer_base; | 145 buffer_base_ = buffer_base; |
| 151 have_section_base_ = true; | 146 have_section_base_ = true; |
| 152 } | 147 } |
| 153 | 148 |
| 154 inline void ByteReader::SetTextBase(uint64 text_base) { | 149 inline void ByteReader::SetTextBase(uint64 text_base) { |
| 155 text_base_ = text_base; | 150 text_base_ = text_base; |
| 156 have_text_base_ = true; | 151 have_text_base_ = true; |
| 157 } | 152 } |
| 158 | 153 |
| 159 inline void ByteReader::SetDataBase(uint64 data_base) { | 154 inline void ByteReader::SetDataBase(uint64 data_base) { |
| 160 data_base_ = data_base; | 155 data_base_ = data_base; |
| 161 have_data_base_ = true; | 156 have_data_base_ = true; |
| 162 } | 157 } |
| 163 | 158 |
| 164 inline void ByteReader::SetFunctionBase(uint64 function_base) { | 159 inline void ByteReader::SetFunctionBase(uint64 function_base) { |
| 165 function_base_ = function_base; | 160 function_base_ = function_base; |
| 166 have_function_base_ = true; | 161 have_function_base_ = true; |
| 167 } | 162 } |
| 168 | 163 |
| 169 inline void ByteReader::ClearFunctionBase() { | 164 inline void ByteReader::ClearFunctionBase() { |
| 170 have_function_base_ = false; | 165 have_function_base_ = false; |
| 171 } | 166 } |
| 172 | 167 |
| 173 } // namespace dwarf2reader | 168 } // namespace dwarf2reader |
| 174 | 169 |
| 175 #endif // UTIL_DEBUGINFO_BYTEREADER_INL_H__ | 170 #endif // UTIL_DEBUGINFO_BYTEREADER_INL_H__ |
| OLD | NEW |