blob: 5ccd42925cd333f2c6b40ec0b4a264793e909644 [file] [log] [blame]
Eugene Zelenkoe94042c2017-02-27 23:43:14 +00001//===- DWARFFormValue.cpp -------------------------------------------------===//
Benjamin Krameraa2f78f2011-09-13 19:42:23 +00002//
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
Paul Robinsonae2e6f372017-05-03 21:53:21 +000010#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
Adrian Prantl0c36a752015-01-06 16:50:25 +000011#include "SyntaxHighlighting.h"
Alexey Samsonov48cbda52013-10-28 23:01:48 +000012#include "llvm/ADT/ArrayRef.h"
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000013#include "llvm/ADT/None.h"
14#include "llvm/ADT/Optional.h"
Alexey Samsonov48cbda52013-10-28 23:01:48 +000015#include "llvm/ADT/StringRef.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000016#include "llvm/BinaryFormat/Dwarf.h"
Zachary Turner82af9432015-01-30 18:07:45 +000017#include "llvm/DebugInfo/DWARF/DWARFContext.h"
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000018#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
19#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000020#include "llvm/Support/ErrorHandling.h"
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000021#include "llvm/Support/Format.h"
22#include "llvm/Support/raw_ostream.h"
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000023#include <cinttypes>
24#include <cstdint>
Matt Arsenault45cbfa52015-10-21 21:10:12 +000025#include <limits>
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000026
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000027using namespace llvm;
28using namespace dwarf;
Adrian Prantl0c36a752015-01-06 16:50:25 +000029using namespace syntax;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000030
Paul Robinson01158442018-01-25 23:06:36 +000031static const DWARFFormValue::FormClass DWARF5FormClasses[] = {
Paul Robinsonae2e6f372017-05-03 21:53:21 +000032 DWARFFormValue::FC_Unknown, // 0x0
33 DWARFFormValue::FC_Address, // 0x01 DW_FORM_addr
34 DWARFFormValue::FC_Unknown, // 0x02 unused
35 DWARFFormValue::FC_Block, // 0x03 DW_FORM_block2
36 DWARFFormValue::FC_Block, // 0x04 DW_FORM_block4
37 DWARFFormValue::FC_Constant, // 0x05 DW_FORM_data2
38 // --- These can be FC_SectionOffset in DWARF3 and below:
39 DWARFFormValue::FC_Constant, // 0x06 DW_FORM_data4
40 DWARFFormValue::FC_Constant, // 0x07 DW_FORM_data8
41 // ---
42 DWARFFormValue::FC_String, // 0x08 DW_FORM_string
43 DWARFFormValue::FC_Block, // 0x09 DW_FORM_block
44 DWARFFormValue::FC_Block, // 0x0a DW_FORM_block1
45 DWARFFormValue::FC_Constant, // 0x0b DW_FORM_data1
46 DWARFFormValue::FC_Flag, // 0x0c DW_FORM_flag
47 DWARFFormValue::FC_Constant, // 0x0d DW_FORM_sdata
48 DWARFFormValue::FC_String, // 0x0e DW_FORM_strp
49 DWARFFormValue::FC_Constant, // 0x0f DW_FORM_udata
50 DWARFFormValue::FC_Reference, // 0x10 DW_FORM_ref_addr
51 DWARFFormValue::FC_Reference, // 0x11 DW_FORM_ref1
52 DWARFFormValue::FC_Reference, // 0x12 DW_FORM_ref2
53 DWARFFormValue::FC_Reference, // 0x13 DW_FORM_ref4
54 DWARFFormValue::FC_Reference, // 0x14 DW_FORM_ref8
55 DWARFFormValue::FC_Reference, // 0x15 DW_FORM_ref_udata
56 DWARFFormValue::FC_Indirect, // 0x16 DW_FORM_indirect
57 DWARFFormValue::FC_SectionOffset, // 0x17 DW_FORM_sec_offset
58 DWARFFormValue::FC_Exprloc, // 0x18 DW_FORM_exprloc
59 DWARFFormValue::FC_Flag, // 0x19 DW_FORM_flag_present
Paul Robinson01158442018-01-25 23:06:36 +000060 DWARFFormValue::FC_String, // 0x1a DW_FORM_strx
61 DWARFFormValue::FC_Address, // 0x1b DW_FORM_addrx
62 DWARFFormValue::FC_Reference, // 0x1c DW_FORM_ref_sup4
63 DWARFFormValue::FC_String, // 0x1d DW_FORM_strp_sup
64 DWARFFormValue::FC_Constant, // 0x1e DW_FORM_data16
65 DWARFFormValue::FC_String, // 0x1f DW_FORM_line_strp
66 DWARFFormValue::FC_Reference, // 0x20 DW_FORM_ref_sig8
67 DWARFFormValue::FC_Constant, // 0x21 DW_FORM_implicit_const
68 DWARFFormValue::FC_SectionOffset, // 0x22 DW_FORM_loclistx
69 DWARFFormValue::FC_SectionOffset, // 0x23 DW_FORM_rnglistx
70 DWARFFormValue::FC_Reference, // 0x24 DW_FORM_ref_sup8
71 DWARFFormValue::FC_String, // 0x25 DW_FORM_strx1
72 DWARFFormValue::FC_String, // 0x26 DW_FORM_strx2
73 DWARFFormValue::FC_String, // 0x27 DW_FORM_strx3
74 DWARFFormValue::FC_String, // 0x28 DW_FORM_strx4
75 DWARFFormValue::FC_Address, // 0x29 DW_FORM_addrx1
76 DWARFFormValue::FC_Address, // 0x2a DW_FORM_addrx2
77 DWARFFormValue::FC_Address, // 0x2b DW_FORM_addrx3
78 DWARFFormValue::FC_Address, // 0x2c DW_FORM_addrx4
79
Alexey Samsonov48cbda52013-10-28 23:01:48 +000080};
81
Paul Robinson75c068c2017-06-26 18:43:01 +000082Optional<uint8_t>
83DWARFFormValue::getFixedByteSize(dwarf::Form Form,
Paul Robinson36e85a82017-06-26 19:52:32 +000084 const DWARFFormParams Params) {
Greg Clayton82f12b12016-11-11 16:21:37 +000085 switch (Form) {
Paul Robinsonae2e6f372017-05-03 21:53:21 +000086 case DW_FORM_addr:
Jonas Devliegherecbf651f2018-01-05 10:03:02 +000087 if (Params)
88 return Params.AddrSize;
89 return None;
Greg Clayton82f12b12016-11-11 16:21:37 +000090
Paul Robinsonae2e6f372017-05-03 21:53:21 +000091 case DW_FORM_block: // ULEB128 length L followed by L bytes.
92 case DW_FORM_block1: // 1 byte length L followed by L bytes.
93 case DW_FORM_block2: // 2 byte length L followed by L bytes.
94 case DW_FORM_block4: // 4 byte length L followed by L bytes.
95 case DW_FORM_string: // C-string with null terminator.
96 case DW_FORM_sdata: // SLEB128.
97 case DW_FORM_udata: // ULEB128.
98 case DW_FORM_ref_udata: // ULEB128.
99 case DW_FORM_indirect: // ULEB128.
100 case DW_FORM_exprloc: // ULEB128 length L followed by L bytes.
101 case DW_FORM_strx: // ULEB128.
102 case DW_FORM_addrx: // ULEB128.
103 case DW_FORM_loclistx: // ULEB128.
104 case DW_FORM_rnglistx: // ULEB128.
105 case DW_FORM_GNU_addr_index: // ULEB128.
106 case DW_FORM_GNU_str_index: // ULEB128.
107 return None;
Greg Clayton82f12b12016-11-11 16:21:37 +0000108
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000109 case DW_FORM_ref_addr:
Jonas Devliegherecbf651f2018-01-05 10:03:02 +0000110 if (Params)
111 return Params.getRefAddrByteSize();
112 return None;
Greg Clayton82f12b12016-11-11 16:21:37 +0000113
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000114 case DW_FORM_flag:
115 case DW_FORM_data1:
116 case DW_FORM_ref1:
117 case DW_FORM_strx1:
118 case DW_FORM_addrx1:
119 return 1;
Greg Clayton82f12b12016-11-11 16:21:37 +0000120
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000121 case DW_FORM_data2:
122 case DW_FORM_ref2:
123 case DW_FORM_strx2:
124 case DW_FORM_addrx2:
125 return 2;
Greg Clayton82f12b12016-11-11 16:21:37 +0000126
Wolfgang Pieb258927e2017-06-21 19:37:44 +0000127 case DW_FORM_strx3:
128 return 3;
129
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000130 case DW_FORM_data4:
131 case DW_FORM_ref4:
132 case DW_FORM_ref_sup4:
133 case DW_FORM_strx4:
134 case DW_FORM_addrx4:
135 return 4;
Greg Clayton82f12b12016-11-11 16:21:37 +0000136
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000137 case DW_FORM_strp:
138 case DW_FORM_GNU_ref_alt:
139 case DW_FORM_GNU_strp_alt:
140 case DW_FORM_line_strp:
141 case DW_FORM_sec_offset:
142 case DW_FORM_strp_sup:
Jonas Devliegherecbf651f2018-01-05 10:03:02 +0000143 if (Params)
144 return Params.getDwarfOffsetByteSize();
145 return None;
Greg Clayton82f12b12016-11-11 16:21:37 +0000146
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000147 case DW_FORM_data8:
148 case DW_FORM_ref8:
149 case DW_FORM_ref_sig8:
150 case DW_FORM_ref_sup8:
151 return 8;
Greg Clayton82f12b12016-11-11 16:21:37 +0000152
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000153 case DW_FORM_flag_present:
154 return 0;
Greg Clayton82f12b12016-11-11 16:21:37 +0000155
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000156 case DW_FORM_data16:
157 return 16;
Greg Clayton82f12b12016-11-11 16:21:37 +0000158
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000159 case DW_FORM_implicit_const:
160 // The implicit value is stored in the abbreviation as a SLEB128, and
161 // there no data in debug info.
162 return 0;
Greg Clayton82f12b12016-11-11 16:21:37 +0000163
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000164 default:
165 llvm_unreachable("Handle this form in this switch statement");
Greg Clayton82f12b12016-11-11 16:21:37 +0000166 }
167 return None;
168}
169
Paul Robinson75c068c2017-06-26 18:43:01 +0000170bool DWARFFormValue::skipValue(dwarf::Form Form, DataExtractor DebugInfoData,
171 uint32_t *OffsetPtr,
Paul Robinson36e85a82017-06-26 19:52:32 +0000172 const DWARFFormParams Params) {
Greg Clayton82f12b12016-11-11 16:21:37 +0000173 bool Indirect = false;
174 do {
175 switch (Form) {
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000176 // Blocks of inlined data that have a length field and the data bytes
177 // inlined in the .debug_info.
178 case DW_FORM_exprloc:
179 case DW_FORM_block: {
180 uint64_t size = DebugInfoData.getULEB128(OffsetPtr);
181 *OffsetPtr += size;
182 return true;
183 }
184 case DW_FORM_block1: {
185 uint8_t size = DebugInfoData.getU8(OffsetPtr);
186 *OffsetPtr += size;
187 return true;
188 }
189 case DW_FORM_block2: {
190 uint16_t size = DebugInfoData.getU16(OffsetPtr);
191 *OffsetPtr += size;
192 return true;
193 }
194 case DW_FORM_block4: {
195 uint32_t size = DebugInfoData.getU32(OffsetPtr);
196 *OffsetPtr += size;
197 return true;
198 }
199
200 // Inlined NULL terminated C-strings.
201 case DW_FORM_string:
202 DebugInfoData.getCStr(OffsetPtr);
203 return true;
204
205 case DW_FORM_addr:
206 case DW_FORM_ref_addr:
207 case DW_FORM_flag_present:
208 case DW_FORM_data1:
209 case DW_FORM_data2:
210 case DW_FORM_data4:
211 case DW_FORM_data8:
Paul Robinsona06f8dc2017-12-18 19:08:35 +0000212 case DW_FORM_data16:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000213 case DW_FORM_flag:
214 case DW_FORM_ref1:
215 case DW_FORM_ref2:
216 case DW_FORM_ref4:
217 case DW_FORM_ref8:
218 case DW_FORM_ref_sig8:
219 case DW_FORM_ref_sup4:
220 case DW_FORM_ref_sup8:
221 case DW_FORM_strx1:
222 case DW_FORM_strx2:
223 case DW_FORM_strx4:
224 case DW_FORM_addrx1:
225 case DW_FORM_addrx2:
226 case DW_FORM_addrx4:
227 case DW_FORM_sec_offset:
228 case DW_FORM_strp:
229 case DW_FORM_strp_sup:
230 case DW_FORM_line_strp:
231 case DW_FORM_GNU_ref_alt:
232 case DW_FORM_GNU_strp_alt:
Paul Robinson75c068c2017-06-26 18:43:01 +0000233 if (Optional<uint8_t> FixedSize =
234 DWARFFormValue::getFixedByteSize(Form, Params)) {
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000235 *OffsetPtr += *FixedSize;
Greg Clayton82f12b12016-11-11 16:21:37 +0000236 return true;
237 }
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000238 return false;
Greg Clayton82f12b12016-11-11 16:21:37 +0000239
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000240 // signed or unsigned LEB 128 values.
241 case DW_FORM_sdata:
242 DebugInfoData.getSLEB128(OffsetPtr);
243 return true;
Greg Clayton82f12b12016-11-11 16:21:37 +0000244
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000245 case DW_FORM_udata:
246 case DW_FORM_ref_udata:
247 case DW_FORM_strx:
248 case DW_FORM_addrx:
249 case DW_FORM_loclistx:
250 case DW_FORM_rnglistx:
251 case DW_FORM_GNU_addr_index:
252 case DW_FORM_GNU_str_index:
253 DebugInfoData.getULEB128(OffsetPtr);
254 return true;
Greg Clayton82f12b12016-11-11 16:21:37 +0000255
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000256 case DW_FORM_indirect:
257 Indirect = true;
258 Form = static_cast<dwarf::Form>(DebugInfoData.getULEB128(OffsetPtr));
259 break;
Greg Clayton82f12b12016-11-11 16:21:37 +0000260
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000261 default:
262 return false;
Greg Clayton82f12b12016-11-11 16:21:37 +0000263 }
264 } while (Indirect);
265 return true;
266}
267
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000268bool DWARFFormValue::isFormClass(DWARFFormValue::FormClass FC) const {
Paul Robinson01158442018-01-25 23:06:36 +0000269 // First, check DWARF5 form classes.
270 if (Form < makeArrayRef(DWARF5FormClasses).size() &&
271 DWARF5FormClasses[Form] == FC)
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000272 return true;
Paul Robinson01158442018-01-25 23:06:36 +0000273 // Check more forms from extensions and proposals.
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000274 switch (Form) {
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000275 case DW_FORM_GNU_ref_alt:
Alexey Samsonovcbd806a2013-10-29 16:32:19 +0000276 return (FC == FC_Reference);
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000277 case DW_FORM_GNU_addr_index:
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000278 return (FC == FC_Address);
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000279 case DW_FORM_GNU_str_index:
280 case DW_FORM_GNU_strp_alt:
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000281 return (FC == FC_String);
Greg Clayton6c273762016-10-27 16:32:04 +0000282 default:
283 break;
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000284 }
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000285 // In DWARF3 DW_FORM_data4 and DW_FORM_data8 served also as a section offset.
286 // Don't check for DWARF version here, as some producers may still do this
Paul Robinson0a227092018-02-05 20:43:15 +0000287 // by mistake. Also accept DW_FORM_[line_]strp since these are
288 // .debug_[line_]str section offsets.
Greg Clayton48432cf2017-05-01 22:07:02 +0000289 return (Form == DW_FORM_data4 || Form == DW_FORM_data8 ||
Paul Robinson0a227092018-02-05 20:43:15 +0000290 Form == DW_FORM_strp || Form == DW_FORM_line_strp) &&
Benjamin Kramer68a29562015-05-25 13:28:03 +0000291 FC == FC_SectionOffset;
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000292}
293
Paul Robinson17536b92017-06-29 16:52:08 +0000294bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
Paul Robinsone5400f82017-11-07 19:57:12 +0000295 uint32_t *OffsetPtr, DWARFFormParams FP,
Paul Robinsonbf750c82018-01-29 20:57:43 +0000296 const DWARFContext *Ctx,
Paul Robinsone5400f82017-11-07 19:57:12 +0000297 const DWARFUnit *CU) {
Paul Robinsonbf750c82018-01-29 20:57:43 +0000298 if (!Ctx && CU)
299 Ctx = &CU->getContext();
300 C = Ctx;
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000301 U = CU;
302 bool Indirect = false;
303 bool IsBlock = false;
Craig Topper2617dcc2014-04-15 06:32:26 +0000304 Value.data = nullptr;
Benjamin Kramereaa74332011-09-13 21:47:32 +0000305 // Read the value for the form into value and follow and DW_FORM_indirect
306 // instances we run into
307 do {
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000308 Indirect = false;
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000309 switch (Form) {
310 case DW_FORM_addr:
Eric Christopher7c678de2012-11-07 23:22:07 +0000311 case DW_FORM_ref_addr: {
Paul Robinsone5400f82017-11-07 19:57:12 +0000312 uint16_t Size =
313 (Form == DW_FORM_addr) ? FP.AddrSize : FP.getRefAddrByteSize();
Paul Robinson17536b92017-06-29 16:52:08 +0000314 Value.uval = Data.getRelocatedValue(Size, OffsetPtr, &Value.SectionIndex);
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000315 break;
Alexey Samsonov9cb13d52012-11-12 14:25:36 +0000316 }
Eric Christopherd999bb72012-08-24 01:14:23 +0000317 case DW_FORM_exprloc:
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000318 case DW_FORM_block:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000319 Value.uval = Data.getULEB128(OffsetPtr);
320 IsBlock = true;
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000321 break;
322 case DW_FORM_block1:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000323 Value.uval = Data.getU8(OffsetPtr);
324 IsBlock = true;
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000325 break;
326 case DW_FORM_block2:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000327 Value.uval = Data.getU16(OffsetPtr);
328 IsBlock = true;
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000329 break;
330 case DW_FORM_block4:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000331 Value.uval = Data.getU32(OffsetPtr);
332 IsBlock = true;
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000333 break;
334 case DW_FORM_data1:
335 case DW_FORM_ref1:
336 case DW_FORM_flag:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000337 case DW_FORM_strx1:
338 case DW_FORM_addrx1:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000339 Value.uval = Data.getU8(OffsetPtr);
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000340 break;
341 case DW_FORM_data2:
342 case DW_FORM_ref2:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000343 case DW_FORM_strx2:
344 case DW_FORM_addrx2:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000345 Value.uval = Data.getU16(OffsetPtr);
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000346 break;
Wolfgang Pieb258927e2017-06-21 19:37:44 +0000347 case DW_FORM_strx3:
348 Value.uval = Data.getU24(OffsetPtr);
349 break;
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000350 case DW_FORM_data4:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000351 case DW_FORM_ref4:
352 case DW_FORM_ref_sup4:
353 case DW_FORM_strx4:
Paul Robinson17536b92017-06-29 16:52:08 +0000354 case DW_FORM_addrx4:
355 Value.uval = Data.getRelocatedValue(4, OffsetPtr);
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000356 break;
357 case DW_FORM_data8:
358 case DW_FORM_ref8:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000359 case DW_FORM_ref_sup8:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000360 Value.uval = Data.getU64(OffsetPtr);
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000361 break;
Paul Robinsona06f8dc2017-12-18 19:08:35 +0000362 case DW_FORM_data16:
363 // Treat this like a 16-byte block.
364 Value.uval = 16;
365 IsBlock = true;
366 break;
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000367 case DW_FORM_sdata:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000368 Value.sval = Data.getSLEB128(OffsetPtr);
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000369 break;
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000370 case DW_FORM_udata:
371 case DW_FORM_ref_udata:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000372 Value.uval = Data.getULEB128(OffsetPtr);
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000373 break;
374 case DW_FORM_string:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000375 Value.cstr = Data.getCStr(OffsetPtr);
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000376 break;
377 case DW_FORM_indirect:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000378 Form = static_cast<dwarf::Form>(Data.getULEB128(OffsetPtr));
379 Indirect = true;
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000380 break;
Greg Clayton04c19282016-11-11 17:38:14 +0000381 case DW_FORM_strp:
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000382 case DW_FORM_sec_offset:
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000383 case DW_FORM_GNU_ref_alt:
Greg Clayton82f12b12016-11-11 16:21:37 +0000384 case DW_FORM_GNU_strp_alt:
385 case DW_FORM_line_strp:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000386 case DW_FORM_strp_sup: {
Paul Robinson17536b92017-06-29 16:52:08 +0000387 Value.uval =
Paul Robinsone5400f82017-11-07 19:57:12 +0000388 Data.getRelocatedValue(FP.getDwarfOffsetByteSize(), OffsetPtr);
Eric Christopherd999bb72012-08-24 01:14:23 +0000389 break;
Eric Christopher55863be2013-04-07 03:43:09 +0000390 }
Eric Christopherd999bb72012-08-24 01:14:23 +0000391 case DW_FORM_flag_present:
392 Value.uval = 1;
393 break;
394 case DW_FORM_ref_sig8:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000395 Value.uval = Data.getU64(OffsetPtr);
Eric Christopherd999bb72012-08-24 01:14:23 +0000396 break;
Eric Christopher59c53c22012-11-16 23:44:11 +0000397 case DW_FORM_GNU_addr_index:
Eric Christopher59c53c22012-11-16 23:44:11 +0000398 case DW_FORM_GNU_str_index:
Wolfgang Pieb77d3e932017-06-06 01:22:34 +0000399 case DW_FORM_strx:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000400 Value.uval = Data.getULEB128(OffsetPtr);
Eric Christopher59c53c22012-11-16 23:44:11 +0000401 break;
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000402 default:
Greg Clayton0e62ee72017-01-13 00:13:42 +0000403 // DWARFFormValue::skipValue() will have caught this and caused all
404 // DWARF DIEs to fail to be parsed, so this code is not be reachable.
405 llvm_unreachable("unsupported form");
Benjamin Kramer123bfbb2011-09-15 03:11:09 +0000406 }
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000407 } while (Indirect);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000408
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000409 if (IsBlock) {
410 StringRef Str = Data.getData().substr(*OffsetPtr, Value.uval);
Craig Topper2617dcc2014-04-15 06:32:26 +0000411 Value.data = nullptr;
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000412 if (!Str.empty()) {
413 Value.data = reinterpret_cast<const uint8_t *>(Str.data());
414 *OffsetPtr += Value.uval;
Benjamin Kramereaa74332011-09-13 21:47:32 +0000415 }
416 }
417
418 return true;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000419}
420
Jonas Devliegherea2faf7b2017-08-18 21:35:44 +0000421void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000422 uint64_t UValue = Value.uval;
423 bool CURelativeOffset = false;
Adrian Prantl01fb31c2017-12-08 23:32:47 +0000424 raw_ostream &AddrOS =
425 DumpOpts.ShowAddresses ? WithColor(OS, syntax::Address).get() : nulls();
Benjamin Kramereaa74332011-09-13 21:47:32 +0000426 switch (Form) {
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000427 case DW_FORM_addr:
Adrian Prantl01fb31c2017-12-08 23:32:47 +0000428 AddrOS << format("0x%016" PRIx64, UValue);
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000429 break;
Eric Christopher962c9082013-01-15 23:56:56 +0000430 case DW_FORM_GNU_addr_index: {
Adrian Prantl01fb31c2017-12-08 23:32:47 +0000431 AddrOS << format(" indexed (%8.8x) address = ", (uint32_t)UValue);
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000432 uint64_t Address;
Greg Claytoncddab272016-10-31 16:46:02 +0000433 if (U == nullptr)
434 OS << "<invalid dwarf unit>";
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000435 else if (U->getAddrOffsetSectionItem(UValue, Address))
Adrian Prantl01fb31c2017-12-08 23:32:47 +0000436 AddrOS << format("0x%016" PRIx64, Address);
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000437 else
Eric Christopher962c9082013-01-15 23:56:56 +0000438 OS << "<no .debug_addr section>";
439 break;
440 }
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000441 case DW_FORM_flag_present:
442 OS << "true";
443 break;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000444 case DW_FORM_flag:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000445 case DW_FORM_data1:
446 OS << format("0x%02x", (uint8_t)UValue);
447 break;
448 case DW_FORM_data2:
449 OS << format("0x%04x", (uint16_t)UValue);
450 break;
451 case DW_FORM_data4:
452 OS << format("0x%08x", (uint32_t)UValue);
453 break;
Eric Christopherd999bb72012-08-24 01:14:23 +0000454 case DW_FORM_ref_sig8:
Adrian Prantl01fb31c2017-12-08 23:32:47 +0000455 AddrOS << format("0x%016" PRIx64, UValue);
456 break;
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000457 case DW_FORM_data8:
458 OS << format("0x%016" PRIx64, UValue);
459 break;
Paul Robinsona06f8dc2017-12-18 19:08:35 +0000460 case DW_FORM_data16:
461 OS << format_bytes(ArrayRef<uint8_t>(Value.data, 16), None, 16, 16);
462 break;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000463 case DW_FORM_string:
464 OS << '"';
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000465 OS.write_escaped(Value.cstr);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000466 OS << '"';
467 break;
Eric Christopherd999bb72012-08-24 01:14:23 +0000468 case DW_FORM_exprloc:
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000469 case DW_FORM_block:
470 case DW_FORM_block1:
471 case DW_FORM_block2:
472 case DW_FORM_block4:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000473 if (UValue > 0) {
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000474 switch (Form) {
Eric Christopherd999bb72012-08-24 01:14:23 +0000475 case DW_FORM_exprloc:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000476 case DW_FORM_block:
477 OS << format("<0x%" PRIx64 "> ", UValue);
478 break;
479 case DW_FORM_block1:
480 OS << format("<0x%2.2x> ", (uint8_t)UValue);
481 break;
482 case DW_FORM_block2:
483 OS << format("<0x%4.4x> ", (uint16_t)UValue);
484 break;
485 case DW_FORM_block4:
486 OS << format("<0x%8.8x> ", (uint32_t)UValue);
487 break;
488 default:
489 break;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000490 }
491
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000492 const uint8_t *DataPtr = Value.data;
493 if (DataPtr) {
494 // UValue contains size of block
495 const uint8_t *EndDataPtr = DataPtr + UValue;
496 while (DataPtr < EndDataPtr) {
497 OS << format("%2.2x ", *DataPtr);
498 ++DataPtr;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000499 }
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000500 } else
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000501 OS << "NULL";
502 }
503 break;
504
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000505 case DW_FORM_sdata:
506 OS << Value.sval;
507 break;
508 case DW_FORM_udata:
509 OS << Value.uval;
510 break;
Eugene Zelenkoe94042c2017-02-27 23:43:14 +0000511 case DW_FORM_strp:
Jonas Devlieghere27476ce2017-09-13 09:43:05 +0000512 if (DumpOpts.Verbose)
Jonas Devliegherea2faf7b2017-08-18 21:35:44 +0000513 OS << format(" .debug_str[0x%8.8x] = ", (uint32_t)UValue);
Greg Claytoncddab272016-10-31 16:46:02 +0000514 dumpString(OS);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000515 break;
Paul Robinson0a227092018-02-05 20:43:15 +0000516 case DW_FORM_line_strp:
517 if (DumpOpts.Verbose)
518 OS << format(" .debug_line_str[0x%8.8x] = ", (uint32_t)UValue);
519 dumpString(OS);
520 break;
Wolfgang Pieb77d3e932017-06-06 01:22:34 +0000521 case DW_FORM_strx:
Wolfgang Pieb258927e2017-06-21 19:37:44 +0000522 case DW_FORM_strx1:
523 case DW_FORM_strx2:
524 case DW_FORM_strx3:
525 case DW_FORM_strx4:
Eugene Zelenkoe94042c2017-02-27 23:43:14 +0000526 case DW_FORM_GNU_str_index:
Adrian Prantl01fb31c2017-12-08 23:32:47 +0000527 if (DumpOpts.Verbose)
528 OS << format(" indexed (%8.8x) string = ", (uint32_t)UValue);
Greg Claytoncddab272016-10-31 16:46:02 +0000529 dumpString(OS);
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000530 break;
Eugene Zelenkoe94042c2017-02-27 23:43:14 +0000531 case DW_FORM_GNU_strp_alt:
Adrian Prantl01fb31c2017-12-08 23:32:47 +0000532 if (DumpOpts.Verbose)
533 OS << format("alt indirect string, offset: 0x%" PRIx64 "", UValue);
Greg Claytoncddab272016-10-31 16:46:02 +0000534 dumpString(OS);
Eric Christopher2cbd5762013-01-07 19:32:41 +0000535 break;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000536 case DW_FORM_ref_addr:
Adrian Prantl01fb31c2017-12-08 23:32:47 +0000537 AddrOS << format("0x%016" PRIx64, UValue);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000538 break;
539 case DW_FORM_ref1:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000540 CURelativeOffset = true;
Jonas Devliegherebf8596f2018-03-07 16:28:53 +0000541 if (DumpOpts.Verbose)
542 AddrOS << format("cu + 0x%2.2x", (uint8_t)UValue);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000543 break;
544 case DW_FORM_ref2:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000545 CURelativeOffset = true;
Jonas Devliegherebf8596f2018-03-07 16:28:53 +0000546 if (DumpOpts.Verbose)
547 AddrOS << format("cu + 0x%4.4x", (uint16_t)UValue);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000548 break;
549 case DW_FORM_ref4:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000550 CURelativeOffset = true;
Jonas Devliegherebf8596f2018-03-07 16:28:53 +0000551 if (DumpOpts.Verbose)
552 AddrOS << format("cu + 0x%4.4x", (uint32_t)UValue);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000553 break;
554 case DW_FORM_ref8:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000555 CURelativeOffset = true;
Jonas Devliegherebf8596f2018-03-07 16:28:53 +0000556 if (DumpOpts.Verbose)
557 AddrOS << format("cu + 0x%8.8" PRIx64, UValue);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000558 break;
559 case DW_FORM_ref_udata:
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000560 CURelativeOffset = true;
Jonas Devliegherebf8596f2018-03-07 16:28:53 +0000561 if (DumpOpts.Verbose)
562 AddrOS << format("cu + 0x%" PRIx64, UValue);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000563 break;
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000564 case DW_FORM_GNU_ref_alt:
Adrian Prantl01fb31c2017-12-08 23:32:47 +0000565 AddrOS << format("<alt 0x%" PRIx64 ">", UValue);
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000566 break;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000567
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000568 // All DW_FORM_indirect attributes should be resolved prior to calling
569 // this function
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000570 case DW_FORM_indirect:
571 OS << "DW_FORM_indirect";
572 break;
Eric Christopherd999bb72012-08-24 01:14:23 +0000573
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000574 // Should be formatted to 64-bit for DWARF64.
Eric Christopherd999bb72012-08-24 01:14:23 +0000575 case DW_FORM_sec_offset:
Adrian Prantl01fb31c2017-12-08 23:32:47 +0000576 AddrOS << format("0x%08x", (uint32_t)UValue);
Eric Christopherd999bb72012-08-24 01:14:23 +0000577 break;
Eric Christopherb2120fd2013-01-07 22:40:48 +0000578
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000579 default:
580 OS << format("DW_FORM(0x%4.4x)", Form);
581 break;
582 }
583
Jonas Devliegherebf8596f2018-03-07 16:28:53 +0000584 if (CURelativeOffset) {
585 if (DumpOpts.Verbose)
586 OS << " => {";
Adrian Prantl0c36a752015-01-06 16:50:25 +0000587 WithColor(OS, syntax::Address).get()
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000588 << format("0x%8.8" PRIx64, UValue + (U ? U->getOffset() : 0));
Jonas Devliegherebf8596f2018-03-07 16:28:53 +0000589 if (DumpOpts.Verbose)
590 OS << "}";
Adrian Prantl0c36a752015-01-06 16:50:25 +0000591 }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000592}
593
Greg Claytoncddab272016-10-31 16:46:02 +0000594void DWARFFormValue::dumpString(raw_ostream &OS) const {
595 Optional<const char *> DbgStr = getAsCString();
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000596 if (DbgStr.hasValue()) {
Adrian Prantl520789e2018-02-12 21:11:23 +0000597 auto COS = WithColor(OS, syntax::String);
598 COS.get() << '"';
599 COS.get().write_escaped(DbgStr.getValue());
600 COS.get() << '"';
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000601 }
602}
603
Greg Claytoncddab272016-10-31 16:46:02 +0000604Optional<const char *> DWARFFormValue::getAsCString() const {
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000605 if (!isFormClass(FC_String))
606 return None;
607 if (Form == DW_FORM_string)
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000608 return Value.cstr;
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000609 // FIXME: Add support for DW_FORM_GNU_strp_alt
Paul Robinsonbf750c82018-01-29 20:57:43 +0000610 if (Form == DW_FORM_GNU_strp_alt || C == nullptr)
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000611 return None;
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000612 uint32_t Offset = Value.uval;
Paul Robinsonb6aa01c2018-01-25 22:02:36 +0000613 if (Form == DW_FORM_line_strp) {
Paul Robinsonbf750c82018-01-29 20:57:43 +0000614 // .debug_line_str is tracked in the Context.
615 if (const char *Str = C->getLineStringExtractor().getCStr(&Offset))
Paul Robinsonb6aa01c2018-01-25 22:02:36 +0000616 return Str;
617 return None;
618 }
Wolfgang Pieb258927e2017-06-21 19:37:44 +0000619 if (Form == DW_FORM_GNU_str_index || Form == DW_FORM_strx ||
620 Form == DW_FORM_strx1 || Form == DW_FORM_strx2 || Form == DW_FORM_strx3 ||
621 Form == DW_FORM_strx4) {
Wolfgang Pieb77d3e932017-06-06 01:22:34 +0000622 uint64_t StrOffset;
Paul Robinsonbf750c82018-01-29 20:57:43 +0000623 if (!U || !U->getStringOffsetSectionItem(Offset, StrOffset))
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000624 return None;
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000625 Offset = StrOffset;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000626 }
Paul Robinsonbf750c82018-01-29 20:57:43 +0000627 // Prefer the Unit's string extractor, because for .dwo it will point to
628 // .debug_str.dwo, while the Context's extractor always uses .debug_str.
629 if (U) {
630 if (const char *Str = U->getStringExtractor().getCStr(&Offset))
631 return Str;
632 return None;
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000633 }
Paul Robinsonbf750c82018-01-29 20:57:43 +0000634 if (const char *Str = C->getStringExtractor().getCStr(&Offset))
635 return Str;
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000636 return None;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000637}
638
Greg Claytoncddab272016-10-31 16:46:02 +0000639Optional<uint64_t> DWARFFormValue::getAsAddress() const {
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000640 if (!isFormClass(FC_Address))
641 return None;
Alexey Samsonov742e6b82013-10-18 07:13:32 +0000642 if (Form == DW_FORM_GNU_addr_index) {
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000643 uint32_t Index = Value.uval;
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000644 uint64_t Result;
Craig Topper2617dcc2014-04-15 06:32:26 +0000645 if (!U || !U->getAddrOffsetSectionItem(Index, Result))
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000646 return None;
647 return Result;
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000648 }
649 return Value.uval;
Eric Christopher962c9082013-01-15 23:56:56 +0000650}
651
Greg Claytoncddab272016-10-31 16:46:02 +0000652Optional<uint64_t> DWARFFormValue::getAsReference() const {
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000653 if (!isFormClass(FC_Reference))
654 return None;
Benjamin Kramereaa74332011-09-13 21:47:32 +0000655 switch (Form) {
656 case DW_FORM_ref1:
657 case DW_FORM_ref2:
658 case DW_FORM_ref4:
659 case DW_FORM_ref8:
660 case DW_FORM_ref_udata:
Craig Topper2617dcc2014-04-15 06:32:26 +0000661 if (!U)
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000662 return None;
663 return Value.uval + U->getOffset();
664 case DW_FORM_ref_addr:
Greg Clayton82f12b12016-11-11 16:21:37 +0000665 case DW_FORM_ref_sig8:
666 case DW_FORM_GNU_ref_alt:
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000667 return Value.uval;
Benjamin Kramereaa74332011-09-13 21:47:32 +0000668 default:
Alexey Samsonovbf19a572015-05-19 20:29:28 +0000669 return None;
Benjamin Kramereaa74332011-09-13 21:47:32 +0000670 }
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000671}
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000672
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000673Optional<uint64_t> DWARFFormValue::getAsSectionOffset() const {
674 if (!isFormClass(FC_SectionOffset))
675 return None;
676 return Value.uval;
677}
678
679Optional<uint64_t> DWARFFormValue::getAsUnsignedConstant() const {
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000680 if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) ||
681 Form == DW_FORM_sdata)
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000682 return None;
683 return Value.uval;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000684}
Frederic Rissf3549a22014-09-04 06:14:35 +0000685
Frederic Riss77f850e2015-03-04 22:07:41 +0000686Optional<int64_t> DWARFFormValue::getAsSignedConstant() const {
687 if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) ||
Paul Robinsonae2e6f372017-05-03 21:53:21 +0000688 (Form == DW_FORM_udata &&
689 uint64_t(std::numeric_limits<int64_t>::max()) < Value.uval))
Frederic Riss77f850e2015-03-04 22:07:41 +0000690 return None;
691 switch (Form) {
692 case DW_FORM_data4:
693 return int32_t(Value.uval);
694 case DW_FORM_data2:
695 return int16_t(Value.uval);
696 case DW_FORM_data1:
697 return int8_t(Value.uval);
698 case DW_FORM_sdata:
699 case DW_FORM_data8:
700 default:
701 return Value.sval;
702 }
703}
704
Frederic Risseab17772014-09-04 06:35:09 +0000705Optional<ArrayRef<uint8_t>> DWARFFormValue::getAsBlock() const {
Paul Robinsona06f8dc2017-12-18 19:08:35 +0000706 if (!isFormClass(FC_Block) && !isFormClass(FC_Exprloc) &&
707 Form != DW_FORM_data16)
Frederic Rissf3549a22014-09-04 06:14:35 +0000708 return None;
Craig Topper0013be12015-09-21 05:32:41 +0000709 return makeArrayRef(Value.data, Value.uval);
Frederic Rissf3549a22014-09-04 06:14:35 +0000710}
711
Chris Bienemane0e451d2016-12-22 22:44:27 +0000712Optional<uint64_t> DWARFFormValue::getAsCStringOffset() const {
713 if (!isFormClass(FC_String) && Form == DW_FORM_string)
714 return None;
715 return Value.uval;
716}
717
718Optional<uint64_t> DWARFFormValue::getAsReferenceUVal() const {
719 if (!isFormClass(FC_Reference))
720 return None;
721 return Value.uval;
722}