blob: 2e16db9bab6b06e2db0288e32c2cfcc52d1a9c35 [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
Alexey Samsonov32a3e782013-04-09 14:09:42 +000021template <uint8_t AddrSize, uint8_t RefAddrSize>
22struct FixedFormSizes {
23 static const uint8_t sizes[];
24};
25
26template <uint8_t AddrSize, uint8_t RefAddrSize>
27const uint8_t FixedFormSizes<AddrSize, RefAddrSize>::sizes[] = {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000028 0, // 0x00 unused
Alexey Samsonov32a3e782013-04-09 14:09:42 +000029 AddrSize, // 0x01 DW_FORM_addr
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000030 0, // 0x02 unused
31 0, // 0x03 DW_FORM_block2
32 0, // 0x04 DW_FORM_block4
33 2, // 0x05 DW_FORM_data2
34 4, // 0x06 DW_FORM_data4
35 8, // 0x07 DW_FORM_data8
36 0, // 0x08 DW_FORM_string
37 0, // 0x09 DW_FORM_block
38 0, // 0x0a DW_FORM_block1
39 1, // 0x0b DW_FORM_data1
40 1, // 0x0c DW_FORM_flag
41 0, // 0x0d DW_FORM_sdata
42 4, // 0x0e DW_FORM_strp
43 0, // 0x0f DW_FORM_udata
Alexey Samsonov32a3e782013-04-09 14:09:42 +000044 RefAddrSize, // 0x10 DW_FORM_ref_addr
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000045 1, // 0x11 DW_FORM_ref1
46 2, // 0x12 DW_FORM_ref2
47 4, // 0x13 DW_FORM_ref4
48 8, // 0x14 DW_FORM_ref8
49 0, // 0x15 DW_FORM_ref_udata
50 0, // 0x16 DW_FORM_indirect
Eric Christopher3887a902012-08-24 01:14:23 +000051 4, // 0x17 DW_FORM_sec_offset
52 0, // 0x18 DW_FORM_exprloc
53 0, // 0x19 DW_FORM_flag_present
54 8, // 0x20 DW_FORM_ref_sig8
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000055};
56
Alexey Samsonov32a3e782013-04-09 14:09:42 +000057static uint8_t getRefAddrSize(uint8_t AddrSize, uint16_t Version) {
58 // FIXME: Support DWARF64.
59 return (Version == 2) ? AddrSize : 4;
60}
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000061
62const uint8_t *
Alexey Samsonov32a3e782013-04-09 14:09:42 +000063DWARFFormValue::getFixedFormSizes(uint8_t AddrSize, uint16_t Version) {
64 uint8_t RefAddrSize = getRefAddrSize(AddrSize, Version);
65 if (AddrSize == 4 && RefAddrSize == 4)
66 return FixedFormSizes<4, 4>::sizes;
67 if (AddrSize == 4 && RefAddrSize == 8)
68 return FixedFormSizes<4, 8>::sizes;
69 if (AddrSize == 8 && RefAddrSize == 4)
70 return FixedFormSizes<8, 4>::sizes;
71 if (AddrSize == 8 && RefAddrSize == 8)
72 return FixedFormSizes<8, 8>::sizes;
73 return 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000074}
75
76bool
77DWARFFormValue::extractValue(DataExtractor data, uint32_t *offset_ptr,
Benjamin Kramer89aedba2011-09-15 03:11:09 +000078 const DWARFCompileUnit *cu) {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000079 bool indirect = false;
80 bool is_block = false;
81 Value.data = NULL;
82 // Read the value for the form into value and follow and DW_FORM_indirect
83 // instances we run into
84 do {
Benjamin Kramer89aedba2011-09-15 03:11:09 +000085 indirect = false;
86 switch (Form) {
87 case DW_FORM_addr:
Eric Christopher806e03d2012-11-07 23:22:07 +000088 case DW_FORM_ref_addr: {
Alexey Samsonov32a3e782013-04-09 14:09:42 +000089 uint16_t AddrSize =
90 (Form == DW_FORM_addr)
91 ? cu->getAddressByteSize()
92 : getRefAddrSize(cu->getAddressByteSize(), cu->getVersion());
93 RelocAddrMap::const_iterator AI = cu->getRelocMap()->find(*offset_ptr);
Eric Christopher82de10a2013-01-02 23:52:13 +000094 if (AI != cu->getRelocMap()->end()) {
Eric Christopherd1726a42012-11-12 21:40:38 +000095 const std::pair<uint8_t, int64_t> &R = AI->second;
Alexey Samsonov32a3e782013-04-09 14:09:42 +000096 Value.uval = data.getUnsigned(offset_ptr, AddrSize) + R.second;
Eric Christopherd1726a42012-11-12 21:40:38 +000097 } else
Alexey Samsonov32a3e782013-04-09 14:09:42 +000098 Value.uval = data.getUnsigned(offset_ptr, AddrSize);
Benjamin Kramer89aedba2011-09-15 03:11:09 +000099 break;
Alexey Samsonov4c0ae902012-11-12 14:25:36 +0000100 }
Eric Christopher3887a902012-08-24 01:14:23 +0000101 case DW_FORM_exprloc:
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000102 case DW_FORM_block:
103 Value.uval = data.getULEB128(offset_ptr);
104 is_block = true;
105 break;
106 case DW_FORM_block1:
107 Value.uval = data.getU8(offset_ptr);
108 is_block = true;
109 break;
110 case DW_FORM_block2:
111 Value.uval = data.getU16(offset_ptr);
112 is_block = true;
113 break;
114 case DW_FORM_block4:
115 Value.uval = data.getU32(offset_ptr);
116 is_block = true;
117 break;
118 case DW_FORM_data1:
119 case DW_FORM_ref1:
120 case DW_FORM_flag:
121 Value.uval = data.getU8(offset_ptr);
122 break;
123 case DW_FORM_data2:
124 case DW_FORM_ref2:
125 Value.uval = data.getU16(offset_ptr);
126 break;
127 case DW_FORM_data4:
128 case DW_FORM_ref4:
129 Value.uval = data.getU32(offset_ptr);
130 break;
131 case DW_FORM_data8:
132 case DW_FORM_ref8:
133 Value.uval = data.getU64(offset_ptr);
134 break;
135 case DW_FORM_sdata:
136 Value.sval = data.getSLEB128(offset_ptr);
137 break;
Eric Christopher806e03d2012-11-07 23:22:07 +0000138 case DW_FORM_strp: {
Eric Christopherd1726a42012-11-12 21:40:38 +0000139 RelocAddrMap::const_iterator AI
Eric Christopher82de10a2013-01-02 23:52:13 +0000140 = cu->getRelocMap()->find(*offset_ptr);
141 if (AI != cu->getRelocMap()->end()) {
Eric Christopherd1726a42012-11-12 21:40:38 +0000142 const std::pair<uint8_t, int64_t> &R = AI->second;
Eric Christopher32b37682012-12-27 01:07:07 +0000143 Value.uval = data.getU32(offset_ptr) + R.second;
Eric Christopherd1726a42012-11-12 21:40:38 +0000144 } else
Eric Christopher806e03d2012-11-07 23:22:07 +0000145 Value.uval = data.getU32(offset_ptr);
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000146 break;
Eric Christopher806e03d2012-11-07 23:22:07 +0000147 }
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000148 case DW_FORM_udata:
149 case DW_FORM_ref_udata:
150 Value.uval = data.getULEB128(offset_ptr);
151 break;
152 case DW_FORM_string:
153 Value.cstr = data.getCStr(offset_ptr);
154 // Set the string value to also be the data for inlined cstr form
155 // values only so we can tell the differnence between DW_FORM_string
156 // and DW_FORM_strp form values
Roman Divacky59324292012-09-05 22:26:57 +0000157 Value.data = (const uint8_t*)Value.cstr;
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000158 break;
159 case DW_FORM_indirect:
160 Form = data.getULEB128(offset_ptr);
161 indirect = true;
162 break;
Eric Christopher9a9e73b2013-04-07 03:43:09 +0000163 case DW_FORM_sec_offset: {
Eric Christopherd96c72a2013-01-17 02:59:59 +0000164 // FIXME: This is 64-bit for DWARF64.
Eric Christopher9a9e73b2013-04-07 03:43:09 +0000165 RelocAddrMap::const_iterator AI
166 = cu->getRelocMap()->find(*offset_ptr);
167 if (AI != cu->getRelocMap()->end()) {
168 const std::pair<uint8_t, int64_t> &R = AI->second;
169 Value.uval = data.getU32(offset_ptr) + R.second;
170 } else
171 Value.uval = data.getU32(offset_ptr);
Eric Christopher3887a902012-08-24 01:14:23 +0000172 break;
Eric Christopher9a9e73b2013-04-07 03:43:09 +0000173 }
Eric Christopher3887a902012-08-24 01:14:23 +0000174 case DW_FORM_flag_present:
175 Value.uval = 1;
176 break;
177 case DW_FORM_ref_sig8:
178 Value.uval = data.getU64(offset_ptr);
179 break;
Eric Christopher205e60b2012-11-16 23:44:11 +0000180 case DW_FORM_GNU_addr_index:
181 Value.uval = data.getULEB128(offset_ptr);
182 break;
183 case DW_FORM_GNU_str_index:
184 Value.uval = data.getULEB128(offset_ptr);
185 break;
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000186 default:
187 return false;
188 }
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000189 } while (indirect);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000190
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000191 if (is_block) {
192 StringRef str = data.getData().substr(*offset_ptr, Value.uval);
193 Value.data = NULL;
194 if (!str.empty()) {
195 Value.data = reinterpret_cast<const uint8_t *>(str.data());
196 *offset_ptr += Value.uval;
197 }
198 }
199
200 return true;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000201}
202
203bool
204DWARFFormValue::skipValue(DataExtractor debug_info_data, uint32_t* offset_ptr,
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000205 const DWARFCompileUnit *cu) const {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000206 return DWARFFormValue::skipValue(Form, debug_info_data, offset_ptr, cu);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000207}
208
209bool
210DWARFFormValue::skipValue(uint16_t form, DataExtractor debug_info_data,
211 uint32_t *offset_ptr, const DWARFCompileUnit *cu) {
212 bool indirect = false;
213 do {
214 indirect = false;
215 switch (form) {
216 // Blocks if inlined data that have a length field and the data bytes
217 // inlined in the .debug_info
Eric Christopher3887a902012-08-24 01:14:23 +0000218 case DW_FORM_exprloc:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000219 case DW_FORM_block: {
220 uint64_t size = debug_info_data.getULEB128(offset_ptr);
221 *offset_ptr += size;
222 return true;
223 }
224 case DW_FORM_block1: {
225 uint8_t size = debug_info_data.getU8(offset_ptr);
226 *offset_ptr += size;
227 return true;
228 }
229 case DW_FORM_block2: {
230 uint16_t size = debug_info_data.getU16(offset_ptr);
231 *offset_ptr += size;
232 return true;
233 }
234 case DW_FORM_block4: {
235 uint32_t size = debug_info_data.getU32(offset_ptr);
236 *offset_ptr += size;
237 return true;
238 }
239
240 // Inlined NULL terminated C-strings
241 case DW_FORM_string:
242 debug_info_data.getCStr(offset_ptr);
243 return true;
244
245 // Compile unit address sized values
246 case DW_FORM_addr:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000247 *offset_ptr += cu->getAddressByteSize();
248 return true;
Alexey Samsonov32a3e782013-04-09 14:09:42 +0000249 case DW_FORM_ref_addr:
250 *offset_ptr += getRefAddrSize(cu->getAddressByteSize(), cu->getVersion());
251 return true;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000252
Eric Christopher3887a902012-08-24 01:14:23 +0000253 // 0 byte values - implied from the form.
254 case DW_FORM_flag_present:
255 return true;
Eric Christophere7285c72013-01-07 22:40:48 +0000256
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000257 // 1 byte values
258 case DW_FORM_data1:
259 case DW_FORM_flag:
260 case DW_FORM_ref1:
261 *offset_ptr += 1;
262 return true;
263
264 // 2 byte values
265 case DW_FORM_data2:
266 case DW_FORM_ref2:
267 *offset_ptr += 2;
268 return true;
269
270 // 4 byte values
271 case DW_FORM_strp:
272 case DW_FORM_data4:
273 case DW_FORM_ref4:
274 *offset_ptr += 4;
275 return true;
276
277 // 8 byte values
278 case DW_FORM_data8:
279 case DW_FORM_ref8:
Eric Christopher3887a902012-08-24 01:14:23 +0000280 case DW_FORM_ref_sig8:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000281 *offset_ptr += 8;
282 return true;
283
284 // signed or unsigned LEB 128 values
285 // case DW_FORM_APPLE_db_str:
286 case DW_FORM_sdata:
287 case DW_FORM_udata:
288 case DW_FORM_ref_udata:
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000289 case DW_FORM_GNU_str_index:
290 case DW_FORM_GNU_addr_index:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000291 debug_info_data.getULEB128(offset_ptr);
292 return true;
293
294 case DW_FORM_indirect:
295 indirect = true;
296 form = debug_info_data.getULEB128(offset_ptr);
297 break;
Eric Christopher3887a902012-08-24 01:14:23 +0000298
Eric Christopher446b88f2013-01-17 03:00:04 +0000299 // FIXME: 4 for DWARF32, 8 for DWARF64.
Eric Christopher3887a902012-08-24 01:14:23 +0000300 case DW_FORM_sec_offset:
Eric Christopher446b88f2013-01-17 03:00:04 +0000301 *offset_ptr += 4;
Eric Christopher3887a902012-08-24 01:14:23 +0000302 return true;
Eric Christophere7285c72013-01-07 22:40:48 +0000303
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000304 default:
305 return false;
306 }
307 } while (indirect);
308 return true;
309}
310
311void
Benjamin Kramer34f864f2011-09-15 16:57:13 +0000312DWARFFormValue::dump(raw_ostream &OS, const DWARFCompileUnit *cu) const {
Eric Christopher82de10a2013-01-02 23:52:13 +0000313 DataExtractor debug_str_data(cu->getStringSection(), true, 0);
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000314 DataExtractor debug_str_offset_data(cu->getStringOffsetSection(), true, 0);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000315 uint64_t uvalue = getUnsigned();
316 bool cu_relative_offset = false;
317
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000318 switch (Form) {
Benjamin Kramer5eccd362011-11-05 16:01:13 +0000319 case DW_FORM_addr: OS << format("0x%016" PRIx64, uvalue); break;
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000320 case DW_FORM_GNU_addr_index: {
321 StringRef AddrOffsetSec = cu->getAddrOffsetSection();
322 OS << format(" indexed (%8.8x) address = ", (uint32_t)uvalue);
323 if (AddrOffsetSec.size() != 0) {
324 DataExtractor DA(AddrOffsetSec, true, cu->getAddressByteSize());
325 OS << format("0x%016" PRIx64, getIndirectAddress(&DA, cu));
326 } else
327 OS << "<no .debug_addr section>";
328 break;
329 }
Eric Christopher3887a902012-08-24 01:14:23 +0000330 case DW_FORM_flag_present: OS << "true"; break;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000331 case DW_FORM_flag:
Benjamin Kramer5eccd362011-11-05 16:01:13 +0000332 case DW_FORM_data1: OS << format("0x%02x", (uint8_t)uvalue); break;
333 case DW_FORM_data2: OS << format("0x%04x", (uint16_t)uvalue); break;
334 case DW_FORM_data4: OS << format("0x%08x", (uint32_t)uvalue); break;
Eric Christopher3887a902012-08-24 01:14:23 +0000335 case DW_FORM_ref_sig8:
Benjamin Kramer5eccd362011-11-05 16:01:13 +0000336 case DW_FORM_data8: OS << format("0x%016" PRIx64, uvalue); break;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000337 case DW_FORM_string:
338 OS << '"';
339 OS.write_escaped(getAsCString(NULL));
340 OS << '"';
341 break;
Eric Christopher3887a902012-08-24 01:14:23 +0000342 case DW_FORM_exprloc:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000343 case DW_FORM_block:
344 case DW_FORM_block1:
345 case DW_FORM_block2:
346 case DW_FORM_block4:
347 if (uvalue > 0) {
348 switch (Form) {
Eric Christopher3887a902012-08-24 01:14:23 +0000349 case DW_FORM_exprloc:
Benjamin Kramer41a96492011-11-05 08:57:40 +0000350 case DW_FORM_block: OS << format("<0x%" PRIx64 "> ", uvalue); break;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000351 case DW_FORM_block1: OS << format("<0x%2.2x> ", (uint8_t)uvalue); break;
352 case DW_FORM_block2: OS << format("<0x%4.4x> ", (uint16_t)uvalue); break;
353 case DW_FORM_block4: OS << format("<0x%8.8x> ", (uint32_t)uvalue); break;
354 default: break;
355 }
356
357 const uint8_t* data_ptr = Value.data;
358 if (data_ptr) {
359 // uvalue contains size of block
360 const uint8_t* end_data_ptr = data_ptr + uvalue;
361 while (data_ptr < end_data_ptr) {
362 OS << format("%2.2x ", *data_ptr);
363 ++data_ptr;
364 }
365 }
366 else
367 OS << "NULL";
368 }
369 break;
370
371 case DW_FORM_sdata: OS << getSigned(); break;
372 case DW_FORM_udata: OS << getUnsigned(); break;
Benjamin Kramer34f864f2011-09-15 16:57:13 +0000373 case DW_FORM_strp: {
374 OS << format(" .debug_str[0x%8.8x] = ", (uint32_t)uvalue);
375 const char* dbg_str = getAsCString(&debug_str_data);
376 if (dbg_str) {
377 OS << '"';
378 OS.write_escaped(dbg_str);
379 OS << '"';
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000380 }
381 break;
Benjamin Kramer34f864f2011-09-15 16:57:13 +0000382 }
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000383 case DW_FORM_GNU_str_index: {
384 OS << format(" indexed (%8.8x) string = ", (uint32_t)uvalue);
385 const char *dbg_str = getIndirectCString(&debug_str_data,
386 &debug_str_offset_data);
387 if (dbg_str) {
388 OS << '"';
389 OS.write_escaped(dbg_str);
390 OS << '"';
391 }
392 break;
393 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000394 case DW_FORM_ref_addr:
Benjamin Kramer5eccd362011-11-05 16:01:13 +0000395 OS << format("0x%016" PRIx64, uvalue);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000396 break;
397 case DW_FORM_ref1:
398 cu_relative_offset = true;
399 OS << format("cu + 0x%2.2x", (uint8_t)uvalue);
400 break;
401 case DW_FORM_ref2:
402 cu_relative_offset = true;
403 OS << format("cu + 0x%4.4x", (uint16_t)uvalue);
404 break;
405 case DW_FORM_ref4:
406 cu_relative_offset = true;
407 OS << format("cu + 0x%4.4x", (uint32_t)uvalue);
408 break;
409 case DW_FORM_ref8:
410 cu_relative_offset = true;
Benjamin Kramer41a96492011-11-05 08:57:40 +0000411 OS << format("cu + 0x%8.8" PRIx64, uvalue);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000412 break;
413 case DW_FORM_ref_udata:
414 cu_relative_offset = true;
Benjamin Kramer41a96492011-11-05 08:57:40 +0000415 OS << format("cu + 0x%" PRIx64, uvalue);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000416 break;
417
418 // All DW_FORM_indirect attributes should be resolved prior to calling
419 // this function
420 case DW_FORM_indirect:
421 OS << "DW_FORM_indirect";
422 break;
Eric Christopher3887a902012-08-24 01:14:23 +0000423
Eric Christopher446b88f2013-01-17 03:00:04 +0000424 // Should be formatted to 64-bit for DWARF64.
Eric Christopher3887a902012-08-24 01:14:23 +0000425 case DW_FORM_sec_offset:
Eric Christopher446b88f2013-01-17 03:00:04 +0000426 OS << format("0x%08x", (uint32_t)uvalue);
Eric Christopher3887a902012-08-24 01:14:23 +0000427 break;
Eric Christophere7285c72013-01-07 22:40:48 +0000428
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000429 default:
430 OS << format("DW_FORM(0x%4.4x)", Form);
431 break;
432 }
433
434 if (cu_relative_offset)
Benjamin Kramere25a2bd2012-04-04 20:33:56 +0000435 OS << format(" => {0x%8.8" PRIx64 "}", uvalue + (cu ? cu->getOffset() : 0));
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000436}
437
438const char*
439DWARFFormValue::getAsCString(const DataExtractor *debug_str_data_ptr) const {
440 if (isInlinedCStr()) {
441 return Value.cstr;
442 } else if (debug_str_data_ptr) {
443 uint32_t offset = Value.uval;
444 return debug_str_data_ptr->getCStr(&offset);
445 }
446 return NULL;
447}
448
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000449const char*
450DWARFFormValue::getIndirectCString(const DataExtractor *DS,
451 const DataExtractor *DSO) const {
452 if (!DS || !DSO) return NULL;
453
454 uint32_t offset = Value.uval * 4;
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000455 uint32_t soffset = DSO->getU32(&offset);
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000456 return DS->getCStr(&soffset);
457}
458
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000459uint64_t
460DWARFFormValue::getIndirectAddress(const DataExtractor *DA,
461 const DWARFCompileUnit *cu) const {
462 if (!DA) return 0;
463
464 uint32_t offset = Value.uval * cu->getAddressByteSize();
465 return DA->getAddress(&offset);
466}
467
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000468uint64_t DWARFFormValue::getReference(const DWARFCompileUnit *cu) const {
469 uint64_t die_offset = Value.uval;
470 switch (Form) {
471 case DW_FORM_ref1:
472 case DW_FORM_ref2:
473 case DW_FORM_ref4:
474 case DW_FORM_ref8:
475 case DW_FORM_ref_udata:
476 die_offset += (cu ? cu->getOffset() : 0);
477 break;
478 default:
479 break;
480 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000481
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000482 return die_offset;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000483}
484
485bool
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000486DWARFFormValue::resolveCompileUnitReferences(const DWARFCompileUnit *cu) {
487 switch (Form) {
488 case DW_FORM_ref1:
489 case DW_FORM_ref2:
490 case DW_FORM_ref4:
491 case DW_FORM_ref8:
492 case DW_FORM_ref_udata:
493 Value.uval += cu->getOffset();
494 Form = DW_FORM_ref_addr;
495 return true;
496 default:
497 break;
498 }
499 return false;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000500}
501
502const uint8_t *DWARFFormValue::BlockData() const {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000503 if (!isInlinedCStr())
Benjamin Kramer89aedba2011-09-15 03:11:09 +0000504 return Value.data;
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000505 return NULL;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000506}
507
508bool DWARFFormValue::isBlockForm(uint16_t form) {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000509 switch (form) {
Eric Christopher3887a902012-08-24 01:14:23 +0000510 case DW_FORM_exprloc:
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000511 case DW_FORM_block:
512 case DW_FORM_block1:
513 case DW_FORM_block2:
514 case DW_FORM_block4:
515 return true;
516 }
517 return false;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000518}
519
520bool DWARFFormValue::isDataForm(uint16_t form) {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000521 switch (form) {
522 case DW_FORM_sdata:
523 case DW_FORM_udata:
524 case DW_FORM_data1:
525 case DW_FORM_data2:
526 case DW_FORM_data4:
527 case DW_FORM_data8:
528 return true;
529 }
530 return false;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000531}