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

Side by Side Diff: obsolete/breakpad/common/dwarf/cfi_assembler.cc

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2010, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
31
32 // cfi_assembler.cc: Implementation of google_breakpad::CFISection class.
33 // See cfi_assembler.h for details.
34
35 #include <cassert>
36 #include <stdlib.h>
37
38 #include "common/dwarf/cfi_assembler.h"
39
40 namespace google_breakpad {
41
42 using dwarf2reader::DwarfPointerEncoding;
43
44 CFISection &CFISection::CIEHeader(u_int64_t code_alignment_factor,
45 int data_alignment_factor,
46 unsigned return_address_register,
47 u_int8_t version,
48 const string &augmentation,
49 bool dwarf64) {
50 assert(!entry_length_);
51 entry_length_ = new PendingLength();
52 in_fde_ = false;
53
54 if (dwarf64) {
55 D32(0xffffffff);
56 D64(entry_length_->length);
57 entry_length_->start = Here();
58 // Write the CIE distinguished value. In .debug_frame sections, it's
59 // ~0; in .eh_frame sections, it's zero.
60 D64(eh_frame_ ? 0 : ~(u_int64_t)0);
61 } else {
62 D32(entry_length_->length);
63 entry_length_->start = Here();
64 // Write the CIE distinguished value. In .debug_frame sections, it's
65 // ~0; in .eh_frame sections, it's zero.
66 D32(eh_frame_ ? 0 : ~(u_int32_t)0);
67 }
68 D8(version);
69 AppendCString(augmentation);
70 ULEB128(code_alignment_factor);
71 LEB128(data_alignment_factor);
72 if (version == 1)
73 D8(return_address_register);
74 else
75 ULEB128(return_address_register);
76 return *this;
77 }
78
79 CFISection &CFISection::FDEHeader(Label cie_pointer,
80 u_int64_t initial_location,
81 u_int64_t address_range,
82 bool dwarf64) {
83 assert(!entry_length_);
84 entry_length_ = new PendingLength();
85 in_fde_ = true;
86 fde_start_address_ = initial_location;
87
88 if (dwarf64) {
89 D32(0xffffffff);
90 D64(entry_length_->length);
91 entry_length_->start = Here();
92 if (eh_frame_)
93 D64(Here() - cie_pointer);
94 else
95 D64(cie_pointer);
96 } else {
97 D32(entry_length_->length);
98 entry_length_->start = Here();
99 if (eh_frame_)
100 D32(Here() - cie_pointer);
101 else
102 D32(cie_pointer);
103 }
104 EncodedPointer(initial_location);
105 // The FDE length in an .eh_frame section uses the same encoding as the
106 // initial location, but ignores the base address (selected by the upper
107 // nybble of the encoding), as it's a length, not an address that can be
108 // made relative.
109 EncodedPointer(address_range,
110 DwarfPointerEncoding(pointer_encoding_ & 0x0f));
111 return *this;
112 }
113
114 CFISection &CFISection::FinishEntry() {
115 assert(entry_length_);
116 Align(address_size_, dwarf2reader::DW_CFA_nop);
117 entry_length_->length = Here() - entry_length_->start;
118 delete entry_length_;
119 entry_length_ = NULL;
120 in_fde_ = false;
121 return *this;
122 }
123
124 CFISection &CFISection::EncodedPointer(u_int64_t address,
125 DwarfPointerEncoding encoding,
126 const EncodedPointerBases &bases) {
127 // Omitted data is extremely easy to emit.
128 if (encoding == dwarf2reader::DW_EH_PE_omit)
129 return *this;
130
131 // If (encoding & dwarf2reader::DW_EH_PE_indirect) != 0, then we assume
132 // that ADDRESS is the address at which the pointer is stored --- in
133 // other words, that bit has no effect on how we write the pointer.
134 encoding = DwarfPointerEncoding(encoding & ~dwarf2reader::DW_EH_PE_indirect);
135
136 // Find the base address to which this pointer is relative. The upper
137 // nybble of the encoding specifies this.
138 u_int64_t base;
139 switch (encoding & 0xf0) {
140 case dwarf2reader::DW_EH_PE_absptr: base = 0; break;
141 case dwarf2reader::DW_EH_PE_pcrel: base = bases.cfi + Size(); break;
142 case dwarf2reader::DW_EH_PE_textrel: base = bases.text; break;
143 case dwarf2reader::DW_EH_PE_datarel: base = bases.data; break;
144 case dwarf2reader::DW_EH_PE_funcrel: base = fde_start_address_; break;
145 case dwarf2reader::DW_EH_PE_aligned: base = 0; break;
146 default: abort();
147 };
148
149 // Make ADDRESS relative. Yes, this is appropriate even for "absptr"
150 // values; see gcc/unwind-pe.h.
151 address -= base;
152
153 // Align the pointer, if required.
154 if ((encoding & 0xf0) == dwarf2reader::DW_EH_PE_aligned)
155 Align(AddressSize());
156
157 // Append ADDRESS to this section in the appropriate form. For the
158 // fixed-width forms, we don't need to differentiate between signed and
159 // unsigned encodings, because ADDRESS has already been extended to 64
160 // bits before it was passed to us.
161 switch (encoding & 0x0f) {
162 case dwarf2reader::DW_EH_PE_absptr:
163 Address(address);
164 break;
165
166 case dwarf2reader::DW_EH_PE_uleb128:
167 ULEB128(address);
168 break;
169
170 case dwarf2reader::DW_EH_PE_sleb128:
171 LEB128(address);
172 break;
173
174 case dwarf2reader::DW_EH_PE_udata2:
175 case dwarf2reader::DW_EH_PE_sdata2:
176 D16(address);
177 break;
178
179 case dwarf2reader::DW_EH_PE_udata4:
180 case dwarf2reader::DW_EH_PE_sdata4:
181 D32(address);
182 break;
183
184 case dwarf2reader::DW_EH_PE_udata8:
185 case dwarf2reader::DW_EH_PE_sdata8:
186 D64(address);
187 break;
188
189 default:
190 abort();
191 }
192
193 return *this;
194 };
195
196 } // namespace google_breakpad
OLDNEW
« no previous file with comments | « obsolete/breakpad/common/dwarf/cfi_assembler.h ('k') | obsolete/breakpad/common/dwarf/dwarf2diehandler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698