blob: ea59c1d780d051b69aeb40064a3d0d33eb32e726 [file] [log] [blame]
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +00001//===-- DWARFFormValue.cpp ------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "DWARFFormValue.h"
11#include "DWARFCompileUnit.h"
Benjamin Kramer34f864f2011-09-15 16:57:13 +000012#include "DWARFContext.h"
Eric Christopher806e03d2012-11-07 23:22:07 +000013#include "llvm/Support/Debug.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000014#include "llvm/Support/Dwarf.h"
15#include "llvm/Support/Format.h"
16#include "llvm/Support/raw_ostream.h"
17#include <cassert>
18using namespace llvm;
19using namespace dwarf;
20
21static const uint8_t form_sizes_addr4[] = {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000022 0, // 0x00 unused
23 4, // 0x01 DW_FORM_addr
24 0, // 0x02 unused
25 0, // 0x03 DW_FORM_block2
26 0, // 0x04 DW_FORM_block4
27 2, // 0x05 DW_FORM_data2
28 4, // 0x06 DW_FORM_data4
29 8, // 0x07 DW_FORM_data8
30 0, // 0x08 DW_FORM_string
31 0, // 0x09 DW_FORM_block
32 0, // 0x0a DW_FORM_block1
33 1, // 0x0b DW_FORM_data1
34 1, // 0x0c DW_FORM_flag
35 0, // 0x0d DW_FORM_sdata
36 4, // 0x0e DW_FORM_strp
37 0, // 0x0f DW_FORM_udata
38 4, // 0x10 DW_FORM_ref_addr
39 1, // 0x11 DW_FORM_ref1
40 2, // 0x12 DW_FORM_ref2
41 4, // 0x13 DW_FORM_ref4
42 8, // 0x14 DW_FORM_ref8
43 0, // 0x15 DW_FORM_ref_udata
44 0, // 0x16 DW_FORM_indirect
Eric Christopher3887a902012-08-24 01:14:23 +000045 4, // 0x17 DW_FORM_sec_offset
46 0, // 0x18 DW_FORM_exprloc
47 0, // 0x19 DW_FORM_flag_present
48 8, // 0x20 DW_FORM_ref_sig8
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000049};
50
51static const uint8_t form_sizes_addr8[] = {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000052 0, // 0x00 unused
53 8, // 0x01 DW_FORM_addr
54 0, // 0x02 unused
55 0, // 0x03 DW_FORM_block2
56 0, // 0x04 DW_FORM_block4
57 2, // 0x05 DW_FORM_data2
58 4, // 0x06 DW_FORM_data4
59 8, // 0x07 DW_FORM_data8
60 0, // 0x08 DW_FORM_string
61 0, // 0x09 DW_FORM_block
62 0, // 0x0a DW_FORM_block1
63 1, // 0x0b DW_FORM_data1
64 1, // 0x0c DW_FORM_flag
65 0, // 0x0d DW_FORM_sdata
66 4, // 0x0e DW_FORM_strp
67 0, // 0x0f DW_FORM_udata
68 8, // 0x10 DW_FORM_ref_addr
69 1, // 0x11 DW_FORM_ref1
70 2, // 0x12 DW_FORM_ref2
71 4, // 0x13 DW_FORM_ref4
72 8, // 0x14 DW_FORM_ref8
73 0, // 0x15 DW_FORM_ref_udata
74 0, // 0x16 DW_FORM_indirect
Eric Christopher3887a902012-08-24 01:14:23 +000075 8, // 0x17 DW_FORM_sec_offset
76 0, // 0x18 DW_FORM_exprloc
77 0, // 0x19 DW_FORM_flag_present
78 8, // 0x20 DW_FORM_ref_sig8
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000079};
80
81const uint8_t *
82DWARFFormValue::getFixedFormSizesForAddressSize(uint8_t addr_size) {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000083 switch (addr_size) {
84 case 4: return form_sizes_addr4;
85 case 8: return form_sizes_addr8;
86 }
87 return NULL;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000088}
89
90bool
91DWARFFormValue::extractValue(DataExtractor data, uint32_t *offset_ptr,
Benjamin Kramer89aedba2011-09-15 03:11:09 +000092 const DWARFCompileUnit *cu) {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000093 bool indirect = false;
94 bool is_block = false;
95 Value.data = NULL;
96 // Read the value for the form into value and follow and DW_FORM_indirect
97 // instances we run into
98 do {
Benjamin Kramer89aedba2011-09-15 03:11:09 +000099 indirect = false;
100 switch (Form) {
101 case DW_FORM_addr:
Eric Christopher806e03d2012-11-07 23:22:07 +0000102 case DW_FORM_ref_addr: {
Eric Christopherd1726a42012-11-12 21:40:38 +0000103 RelocAddrMap::const_iterator AI
Eric Christopher82de10a2013-01-02 23:52:13 +0000104 = cu->getRelocMap()->find(*offset_ptr);
105 if (AI != cu->getRelocMap()->end()) {
Eric Christopherd1726a42012-11-12 21:40:38 +0000106 const std::pair<uint8_t, int64_t> &R = AI->second;
Eric Christopher32b37682012-12-27 01:07:07 +0000107 Value.uval = data.getUnsigned(offset_ptr, cu->getAddressByteSize()) +
108 R.second;
Eric Christopherd1726a42012-11-12 21:40:38 +0000109 } else
Eric Christopher806e03d2012-11-07 23:22:07 +0000110 Value.uval = data.getUnsigned(offset_ptr, cu->getAddressByteSize());
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000111 break;
Alexey Samsonov4c0ae902012-11-12 14:25:36 +0000112 }
Eric Christopher3887a902012-08-24 01:14:23 +0000113 case DW_FORM_exprloc:
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000114 case DW_FORM_block:
115 Value.uval = data.getULEB128(offset_ptr);
116 is_block = true;
117 break;
118 case DW_FORM_block1:
119 Value.uval = data.getU8(offset_ptr);
120 is_block = true;
121 break;
122 case DW_FORM_block2:
123 Value.uval = data.getU16(offset_ptr);
124 is_block = true;
125 break;
126 case DW_FORM_block4:
127 Value.uval = data.getU32(offset_ptr);
128 is_block = true;
129 break;
130 case DW_FORM_data1:
131 case DW_FORM_ref1:
132 case DW_FORM_flag:
133 Value.uval = data.getU8(offset_ptr);
134 break;
135 case DW_FORM_data2:
136 case DW_FORM_ref2:
137 Value.uval = data.getU16(offset_ptr);
138 break;
139 case DW_FORM_data4:
140 case DW_FORM_ref4:
141 Value.uval = data.getU32(offset_ptr);
142 break;
143 case DW_FORM_data8:
144 case DW_FORM_ref8:
145 Value.uval = data.getU64(offset_ptr);
146 break;
147 case DW_FORM_sdata:
148 Value.sval = data.getSLEB128(offset_ptr);
149 break;
Eric Christopher806e03d2012-11-07 23:22:07 +0000150 case DW_FORM_strp: {
Eric Christopherd1726a42012-11-12 21:40:38 +0000151 RelocAddrMap::const_iterator AI
Eric Christopher82de10a2013-01-02 23:52:13 +0000152 = cu->getRelocMap()->find(*offset_ptr);
153 if (AI != cu->getRelocMap()->end()) {
Eric Christopherd1726a42012-11-12 21:40:38 +0000154 const std::pair<uint8_t, int64_t> &R = AI->second;
Eric Christopher32b37682012-12-27 01:07:07 +0000155 Value.uval = data.getU32(offset_ptr) + R.second;
Eric Christopherd1726a42012-11-12 21:40:38 +0000156 } else
Eric Christopher806e03d2012-11-07 23:22:07 +0000157 Value.uval = data.getU32(offset_ptr);
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000158 break;
Eric Christopher806e03d2012-11-07 23:22:07 +0000159 }
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000160 case DW_FORM_udata:
161 case DW_FORM_ref_udata:
162 Value.uval = data.getULEB128(offset_ptr);
163 break;
164 case DW_FORM_string:
165 Value.cstr = data.getCStr(offset_ptr);
166 // Set the string value to also be the data for inlined cstr form
167 // values only so we can tell the differnence between DW_FORM_string
168 // and DW_FORM_strp form values
Roman Divacky59324292012-09-05 22:26:57 +0000169 Value.data = (const uint8_t*)Value.cstr;
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000170 break;
171 case DW_FORM_indirect:
172 Form = data.getULEB128(offset_ptr);
173 indirect = true;
174 break;
Eric Christopher3887a902012-08-24 01:14:23 +0000175 case DW_FORM_sec_offset:
Eric Christopherd96c72a2013-01-17 02:59:59 +0000176 // FIXME: This is 64-bit for DWARF64.
177 Value.uval = data.getU32(offset_ptr);
Eric Christopher3887a902012-08-24 01:14:23 +0000178 break;
179 case DW_FORM_flag_present:
180 Value.uval = 1;
181 break;
182 case DW_FORM_ref_sig8:
183 Value.uval = data.getU64(offset_ptr);
184 break;
Eric Christopher205e60b2012-11-16 23:44:11 +0000185 case DW_FORM_GNU_addr_index:
186 Value.uval = data.getULEB128(offset_ptr);
187 break;
188 case DW_FORM_GNU_str_index:
189 Value.uval = data.getULEB128(offset_ptr);
190 break;
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000191 default:
192 return false;
193 }
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000194 } while (indirect);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000195
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000196 if (is_block) {
197 StringRef str = data.getData().substr(*offset_ptr, Value.uval);
198 Value.data = NULL;
199 if (!str.empty()) {
200 Value.data = reinterpret_cast<const uint8_t *>(str.data());
201 *offset_ptr += Value.uval;
202 }
203 }
204
205 return true;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000206}
207
208bool
209DWARFFormValue::skipValue(DataExtractor debug_info_data, uint32_t* offset_ptr,
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000210 const DWARFCompileUnit *cu) const {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000211 return DWARFFormValue::skipValue(Form, debug_info_data, offset_ptr, cu);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000212}
213
214bool
215DWARFFormValue::skipValue(uint16_t form, DataExtractor debug_info_data,
216 uint32_t *offset_ptr, const DWARFCompileUnit *cu) {
217 bool indirect = false;
218 do {
219 indirect = false;
220 switch (form) {
221 // Blocks if inlined data that have a length field and the data bytes
222 // inlined in the .debug_info
Eric Christopher3887a902012-08-24 01:14:23 +0000223 case DW_FORM_exprloc:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000224 case DW_FORM_block: {
225 uint64_t size = debug_info_data.getULEB128(offset_ptr);
226 *offset_ptr += size;
227 return true;
228 }
229 case DW_FORM_block1: {
230 uint8_t size = debug_info_data.getU8(offset_ptr);
231 *offset_ptr += size;
232 return true;
233 }
234 case DW_FORM_block2: {
235 uint16_t size = debug_info_data.getU16(offset_ptr);
236 *offset_ptr += size;
237 return true;
238 }
239 case DW_FORM_block4: {
240 uint32_t size = debug_info_data.getU32(offset_ptr);
241 *offset_ptr += size;
242 return true;
243 }
244
245 // Inlined NULL terminated C-strings
246 case DW_FORM_string:
247 debug_info_data.getCStr(offset_ptr);
248 return true;
249
250 // Compile unit address sized values
251 case DW_FORM_addr:
252 case DW_FORM_ref_addr:
253 *offset_ptr += cu->getAddressByteSize();
254 return true;
255
Eric Christopher3887a902012-08-24 01:14:23 +0000256 // 0 byte values - implied from the form.
257 case DW_FORM_flag_present:
258 return true;
Eric Christophere7285c72013-01-07 22:40:48 +0000259
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000260 // 1 byte values
261 case DW_FORM_data1:
262 case DW_FORM_flag:
263 case DW_FORM_ref1:
264 *offset_ptr += 1;
265 return true;
266
267 // 2 byte values
268 case DW_FORM_data2:
269 case DW_FORM_ref2:
270 *offset_ptr += 2;
271 return true;
272
273 // 4 byte values
274 case DW_FORM_strp:
275 case DW_FORM_data4:
276 case DW_FORM_ref4:
277 *offset_ptr += 4;
278 return true;
279
280 // 8 byte values
281 case DW_FORM_data8:
282 case DW_FORM_ref8:
Eric Christopher3887a902012-08-24 01:14:23 +0000283 case DW_FORM_ref_sig8:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000284 *offset_ptr += 8;
285 return true;
286
287 // signed or unsigned LEB 128 values
288 // case DW_FORM_APPLE_db_str:
289 case DW_FORM_sdata:
290 case DW_FORM_udata:
291 case DW_FORM_ref_udata:
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000292 case DW_FORM_GNU_str_index:
293 case DW_FORM_GNU_addr_index:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000294 debug_info_data.getULEB128(offset_ptr);
295 return true;
296
297 case DW_FORM_indirect:
298 indirect = true;
299 form = debug_info_data.getULEB128(offset_ptr);
300 break;
Eric Christopher3887a902012-08-24 01:14:23 +0000301
302 // 4 for DWARF32, 8 for DWARF64.
303 case DW_FORM_sec_offset:
304 if (cu->getAddressByteSize() == 4)
305 *offset_ptr += 4;
306 else
307 *offset_ptr += 8;
308 return true;
Eric Christophere7285c72013-01-07 22:40:48 +0000309
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000310 default:
311 return false;
312 }
313 } while (indirect);
314 return true;
315}
316
317void
Benjamin Kramer34f864f2011-09-15 16:57:13 +0000318DWARFFormValue::dump(raw_ostream &OS, const DWARFCompileUnit *cu) const {
Eric Christopher82de10a2013-01-02 23:52:13 +0000319 DataExtractor debug_str_data(cu->getStringSection(), true, 0);
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000320 DataExtractor debug_str_offset_data(cu->getStringOffsetSection(), true, 0);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000321 uint64_t uvalue = getUnsigned();
322 bool cu_relative_offset = false;
323
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000324 switch (Form) {
Benjamin Kramer5eccd362011-11-05 16:01:13 +0000325 case DW_FORM_addr: OS << format("0x%016" PRIx64, uvalue); break;
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000326 case DW_FORM_GNU_addr_index: {
327 StringRef AddrOffsetSec = cu->getAddrOffsetSection();
328 OS << format(" indexed (%8.8x) address = ", (uint32_t)uvalue);
329 if (AddrOffsetSec.size() != 0) {
330 DataExtractor DA(AddrOffsetSec, true, cu->getAddressByteSize());
331 OS << format("0x%016" PRIx64, getIndirectAddress(&DA, cu));
332 } else
333 OS << "<no .debug_addr section>";
334 break;
335 }
Eric Christopher3887a902012-08-24 01:14:23 +0000336 case DW_FORM_flag_present: OS << "true"; break;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000337 case DW_FORM_flag:
Benjamin Kramer5eccd362011-11-05 16:01:13 +0000338 case DW_FORM_data1: OS << format("0x%02x", (uint8_t)uvalue); break;
339 case DW_FORM_data2: OS << format("0x%04x", (uint16_t)uvalue); break;
340 case DW_FORM_data4: OS << format("0x%08x", (uint32_t)uvalue); break;
Eric Christopher3887a902012-08-24 01:14:23 +0000341 case DW_FORM_ref_sig8:
Benjamin Kramer5eccd362011-11-05 16:01:13 +0000342 case DW_FORM_data8: OS << format("0x%016" PRIx64, uvalue); break;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000343 case DW_FORM_string:
344 OS << '"';
345 OS.write_escaped(getAsCString(NULL));
346 OS << '"';
347 break;
Eric Christopher3887a902012-08-24 01:14:23 +0000348 case DW_FORM_exprloc:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000349 case DW_FORM_block:
350 case DW_FORM_block1:
351 case DW_FORM_block2:
352 case DW_FORM_block4:
353 if (uvalue > 0) {
354 switch (Form) {
Eric Christopher3887a902012-08-24 01:14:23 +0000355 case DW_FORM_exprloc:
Benjamin Kramer41a96492011-11-05 08:57:40 +0000356 case DW_FORM_block: OS << format("<0x%" PRIx64 "> ", uvalue); break;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000357 case DW_FORM_block1: OS << format("<0x%2.2x> ", (uint8_t)uvalue); break;
358 case DW_FORM_block2: OS << format("<0x%4.4x> ", (uint16_t)uvalue); break;
359 case DW_FORM_block4: OS << format("<0x%8.8x> ", (uint32_t)uvalue); break;
360 default: break;
361 }
362
363 const uint8_t* data_ptr = Value.data;
364 if (data_ptr) {
365 // uvalue contains size of block
366 const uint8_t* end_data_ptr = data_ptr + uvalue;
367 while (data_ptr < end_data_ptr) {
368 OS << format("%2.2x ", *data_ptr);
369 ++data_ptr;
370 }
371 }
372 else
373 OS << "NULL";
374 }
375 break;
376
377 case DW_FORM_sdata: OS << getSigned(); break;
378 case DW_FORM_udata: OS << getUnsigned(); break;
Benjamin Kramer34f864f2011-09-15 16:57:13 +0000379 case DW_FORM_strp: {
380 OS << format(" .debug_str[0x%8.8x] = ", (uint32_t)uvalue);
381 const char* dbg_str = getAsCString(&debug_str_data);
382 if (dbg_str) {
383 OS << '"';
384 OS.write_escaped(dbg_str);
385 OS << '"';
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000386 }
387 break;
Benjamin Kramer34f864f2011-09-15 16:57:13 +0000388 }
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000389 case DW_FORM_GNU_str_index: {
390 OS << format(" indexed (%8.8x) string = ", (uint32_t)uvalue);
391 const char *dbg_str = getIndirectCString(&debug_str_data,
392 &debug_str_offset_data);
393 if (dbg_str) {
394 OS << '"';
395 OS.write_escaped(dbg_str);
396 OS << '"';
397 }
398 break;
399 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000400 case DW_FORM_ref_addr:
Benjamin Kramer5eccd362011-11-05 16:01:13 +0000401 OS << format("0x%016" PRIx64, uvalue);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000402 break;
403 case DW_FORM_ref1:
404 cu_relative_offset = true;
405 OS << format("cu + 0x%2.2x", (uint8_t)uvalue);
406 break;
407 case DW_FORM_ref2:
408 cu_relative_offset = true;
409 OS << format("cu + 0x%4.4x", (uint16_t)uvalue);
410 break;
411 case DW_FORM_ref4:
412 cu_relative_offset = true;
413 OS << format("cu + 0x%4.4x", (uint32_t)uvalue);
414 break;
415 case DW_FORM_ref8:
416 cu_relative_offset = true;
Benjamin Kramer41a96492011-11-05 08:57:40 +0000417 OS << format("cu + 0x%8.8" PRIx64, uvalue);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000418 break;
419 case DW_FORM_ref_udata:
420 cu_relative_offset = true;
Benjamin Kramer41a96492011-11-05 08:57:40 +0000421 OS << format("cu + 0x%" PRIx64, uvalue);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000422 break;
423
424 // All DW_FORM_indirect attributes should be resolved prior to calling
425 // this function
426 case DW_FORM_indirect:
427 OS << "DW_FORM_indirect";
428 break;
Eric Christopher3887a902012-08-24 01:14:23 +0000429
430 case DW_FORM_sec_offset:
431 if (cu->getAddressByteSize() == 4)
432 OS << format("0x%08x", (uint32_t)uvalue);
433 else
434 OS << format("0x%016" PRIx64, uvalue);
435 break;
Eric Christophere7285c72013-01-07 22:40:48 +0000436
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000437 default:
438 OS << format("DW_FORM(0x%4.4x)", Form);
439 break;
440 }
441
442 if (cu_relative_offset)
Benjamin Kramere25a2bd2012-04-04 20:33:56 +0000443 OS << format(" => {0x%8.8" PRIx64 "}", uvalue + (cu ? cu->getOffset() : 0));
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000444}
445
446const char*
447DWARFFormValue::getAsCString(const DataExtractor *debug_str_data_ptr) const {
448 if (isInlinedCStr()) {
449 return Value.cstr;
450 } else if (debug_str_data_ptr) {
451 uint32_t offset = Value.uval;
452 return debug_str_data_ptr->getCStr(&offset);
453 }
454 return NULL;
455}
456
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000457const char*
458DWARFFormValue::getIndirectCString(const DataExtractor *DS,
459 const DataExtractor *DSO) const {
460 if (!DS || !DSO) return NULL;
461
462 uint32_t offset = Value.uval * 4;
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000463 uint32_t soffset = DSO->getU32(&offset);
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000464 return DS->getCStr(&soffset);
465}
466
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000467uint64_t
468DWARFFormValue::getIndirectAddress(const DataExtractor *DA,
469 const DWARFCompileUnit *cu) const {
470 if (!DA) return 0;
471
472 uint32_t offset = Value.uval * cu->getAddressByteSize();
473 return DA->getAddress(&offset);
474}
475
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000476uint64_t DWARFFormValue::getReference(const DWARFCompileUnit *cu) const {
477 uint64_t die_offset = Value.uval;
478 switch (Form) {
479 case DW_FORM_ref1:
480 case DW_FORM_ref2:
481 case DW_FORM_ref4:
482 case DW_FORM_ref8:
483 case DW_FORM_ref_udata:
484 die_offset += (cu ? cu->getOffset() : 0);
485 break;
486 default:
487 break;
488 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000489
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000490 return die_offset;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000491}
492
493bool
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000494DWARFFormValue::resolveCompileUnitReferences(const DWARFCompileUnit *cu) {
495 switch (Form) {
496 case DW_FORM_ref1:
497 case DW_FORM_ref2:
498 case DW_FORM_ref4:
499 case DW_FORM_ref8:
500 case DW_FORM_ref_udata:
501 Value.uval += cu->getOffset();
502 Form = DW_FORM_ref_addr;
503 return true;
504 default:
505 break;
506 }
507 return false;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000508}
509
510const uint8_t *DWARFFormValue::BlockData() const {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000511 if (!isInlinedCStr())
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000512 return Value.data;
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000513 return NULL;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000514}
515
516bool DWARFFormValue::isBlockForm(uint16_t form) {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000517 switch (form) {
Eric Christopher3887a902012-08-24 01:14:23 +0000518 case DW_FORM_exprloc:
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000519 case DW_FORM_block:
520 case DW_FORM_block1:
521 case DW_FORM_block2:
522 case DW_FORM_block4:
523 return true;
524 }
525 return false;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000526}
527
528bool DWARFFormValue::isDataForm(uint16_t form) {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000529 switch (form) {
530 case DW_FORM_sdata:
531 case DW_FORM_udata:
532 case DW_FORM_data1:
533 case DW_FORM_data2:
534 case DW_FORM_data4:
535 case DW_FORM_data8:
536 return true;
537 }
538 return false;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000539}