Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: src/common/dwarf/bytereader.cc

Issue 1605153004: unittests: fix -Wnarrowing build errors (Closed) Base URL: https://chromium.googlesource.com/breakpad/breakpad.git@master
Patch Set: back to stdint.h Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/common/dwarf/bytereader.h ('k') | src/common/dwarf/bytereader-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 Google Inc. All Rights Reserved. 1 // Copyright (c) 2010 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
11 // in the documentation and/or other materials provided with the 11 // in the documentation and/or other materials provided with the
12 // distribution. 12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its 13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from 14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission. 15 // this software without specific prior written permission.
16 // 16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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 #include <assert.h> 29 #include <assert.h>
30 #include <stdint.h>
30 #include <stdlib.h> 31 #include <stdlib.h>
31 32
32 #include "common/dwarf/bytereader-inl.h" 33 #include "common/dwarf/bytereader-inl.h"
33 #include "common/dwarf/bytereader.h" 34 #include "common/dwarf/bytereader.h"
34 35
35 namespace dwarf2reader { 36 namespace dwarf2reader {
36 37
37 ByteReader::ByteReader(enum Endianness endian) 38 ByteReader::ByteReader(enum Endianness endian)
38 :offset_reader_(NULL), address_reader_(NULL), endian_(endian), 39 :offset_reader_(NULL), address_reader_(NULL), endian_(endian),
39 address_size_(0), offset_size_(0), 40 address_size_(0), offset_size_(0),
(...skipping 15 matching lines...) Expand all
55 void ByteReader::SetAddressSize(uint8 size) { 56 void ByteReader::SetAddressSize(uint8 size) {
56 address_size_ = size; 57 address_size_ = size;
57 assert(size == 4 || size == 8); 58 assert(size == 4 || size == 8);
58 if (size == 4) { 59 if (size == 4) {
59 this->address_reader_ = &ByteReader::ReadFourBytes; 60 this->address_reader_ = &ByteReader::ReadFourBytes;
60 } else { 61 } else {
61 this->address_reader_ = &ByteReader::ReadEightBytes; 62 this->address_reader_ = &ByteReader::ReadEightBytes;
62 } 63 }
63 } 64 }
64 65
65 uint64 ByteReader::ReadInitialLength(const char* start, size_t* len) { 66 uint64 ByteReader::ReadInitialLength(const uint8_t *start, size_t* len) {
66 const uint64 initial_length = ReadFourBytes(start); 67 const uint64 initial_length = ReadFourBytes(start);
67 start += 4; 68 start += 4;
68 69
69 // In DWARF2/3, if the initial length is all 1 bits, then the offset 70 // In DWARF2/3, if the initial length is all 1 bits, then the offset
70 // size is 8 and we need to read the next 8 bytes for the real length. 71 // size is 8 and we need to read the next 8 bytes for the real length.
71 if (initial_length == 0xffffffff) { 72 if (initial_length == 0xffffffff) {
72 SetOffsetSize(8); 73 SetOffsetSize(8);
73 *len = 12; 74 *len = 12;
74 return ReadOffset(start); 75 return ReadOffset(start);
75 } else { 76 } else {
(...skipping 17 matching lines...) Expand all
93 switch (encoding & 0x70) { 94 switch (encoding & 0x70) {
94 case DW_EH_PE_absptr: return true; 95 case DW_EH_PE_absptr: return true;
95 case DW_EH_PE_pcrel: return have_section_base_; 96 case DW_EH_PE_pcrel: return have_section_base_;
96 case DW_EH_PE_textrel: return have_text_base_; 97 case DW_EH_PE_textrel: return have_text_base_;
97 case DW_EH_PE_datarel: return have_data_base_; 98 case DW_EH_PE_datarel: return have_data_base_;
98 case DW_EH_PE_funcrel: return have_function_base_; 99 case DW_EH_PE_funcrel: return have_function_base_;
99 default: return false; 100 default: return false;
100 } 101 }
101 } 102 }
102 103
103 uint64 ByteReader::ReadEncodedPointer(const char *buffer, 104 uint64 ByteReader::ReadEncodedPointer(const uint8_t *buffer,
104 DwarfPointerEncoding encoding, 105 DwarfPointerEncoding encoding,
105 size_t *len) const { 106 size_t *len) const {
106 // UsableEncoding doesn't approve of DW_EH_PE_omit, so we shouldn't 107 // UsableEncoding doesn't approve of DW_EH_PE_omit, so we shouldn't
107 // see it here. 108 // see it here.
108 assert(encoding != DW_EH_PE_omit); 109 assert(encoding != DW_EH_PE_omit);
109 110
110 // The Linux Standards Base 4.0 does not make this clear, but the 111 // The Linux Standards Base 4.0 does not make this clear, but the
111 // GNU tools (gcc/unwind-pe.h; readelf/dwarf.c; gdb/dwarf2-frame.c) 112 // GNU tools (gcc/unwind-pe.h; readelf/dwarf.c; gdb/dwarf2-frame.c)
112 // agree that aligned pointers are always absolute, machine-sized, 113 // agree that aligned pointers are always absolute, machine-sized,
113 // machine-signed pointers. 114 // machine-signed pointers.
114 if (encoding == DW_EH_PE_aligned) { 115 if (encoding == DW_EH_PE_aligned) {
115 assert(have_section_base_); 116 assert(have_section_base_);
116 117
117 // We don't need to align BUFFER in *our* address space. Rather, we 118 // We don't need to align BUFFER in *our* address space. Rather, we
118 // need to find the next position in our buffer that would be aligned 119 // need to find the next position in our buffer that would be aligned
119 // when the .eh_frame section the buffer contains is loaded into the 120 // when the .eh_frame section the buffer contains is loaded into the
120 // program's memory. So align assuming that buffer_base_ gets loaded at 121 // program's memory. So align assuming that buffer_base_ gets loaded at
121 // address section_base_, where section_base_ itself may or may not be 122 // address section_base_, where section_base_ itself may or may not be
122 // aligned. 123 // aligned.
123 124
124 // First, find the offset to START from the closest prior aligned 125 // First, find the offset to START from the closest prior aligned
125 // address. 126 // address.
126 uint64 skew = section_base_ & (AddressSize() - 1); 127 uint64 skew = section_base_ & (AddressSize() - 1);
127 // Now find the offset from that aligned address to buffer. 128 // Now find the offset from that aligned address to buffer.
128 uint64 offset = skew + (buffer - buffer_base_); 129 uint64 offset = skew + (buffer - buffer_base_);
129 // Round up to the next boundary. 130 // Round up to the next boundary.
130 uint64 aligned = (offset + AddressSize() - 1) & -AddressSize(); 131 uint64 aligned = (offset + AddressSize() - 1) & -AddressSize();
131 // Convert back to a pointer. 132 // Convert back to a pointer.
132 const char *aligned_buffer = buffer_base_ + (aligned - skew); 133 const uint8_t *aligned_buffer = buffer_base_ + (aligned - skew);
133 // Finally, store the length and actually fetch the pointer. 134 // Finally, store the length and actually fetch the pointer.
134 *len = aligned_buffer - buffer + AddressSize(); 135 *len = aligned_buffer - buffer + AddressSize();
135 return ReadAddress(aligned_buffer); 136 return ReadAddress(aligned_buffer);
136 } 137 }
137 138
138 // Extract the value first, ignoring whether it's a pointer or an 139 // Extract the value first, ignoring whether it's a pointer or an
139 // offset relative to some base. 140 // offset relative to some base.
140 uint64 offset; 141 uint64 offset;
141 switch (encoding & 0x0f) { 142 switch (encoding & 0x0f) {
142 case DW_EH_PE_absptr: 143 case DW_EH_PE_absptr:
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // Remove inappropriate upper bits. 237 // Remove inappropriate upper bits.
237 if (AddressSize() == 4) 238 if (AddressSize() == 4)
238 pointer = pointer & 0xffffffff; 239 pointer = pointer & 0xffffffff;
239 else 240 else
240 assert(AddressSize() == sizeof(uint64)); 241 assert(AddressSize() == sizeof(uint64));
241 242
242 return pointer; 243 return pointer;
243 } 244 }
244 245
245 } // namespace dwarf2reader 246 } // namespace dwarf2reader
OLDNEW
« no previous file with comments | « src/common/dwarf/bytereader.h ('k') | src/common/dwarf/bytereader-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698