LLVM  8.0.1
DWARFFormValue.cpp
Go to the documentation of this file.
1 //===- 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 
11 #include "llvm/ADT/ArrayRef.h"
12 #include "llvm/ADT/None.h"
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/Format.h"
21 #include "llvm/Support/WithColor.h"
23 #include <cinttypes>
24 #include <cstdint>
25 #include <limits>
26 
27 using namespace llvm;
28 using namespace dwarf;
29 
32  DWARFFormValue::FC_Address, // 0x01 DW_FORM_addr
33  DWARFFormValue::FC_Unknown, // 0x02 unused
34  DWARFFormValue::FC_Block, // 0x03 DW_FORM_block2
35  DWARFFormValue::FC_Block, // 0x04 DW_FORM_block4
36  DWARFFormValue::FC_Constant, // 0x05 DW_FORM_data2
37  // --- These can be FC_SectionOffset in DWARF3 and below:
38  DWARFFormValue::FC_Constant, // 0x06 DW_FORM_data4
39  DWARFFormValue::FC_Constant, // 0x07 DW_FORM_data8
40  // ---
41  DWARFFormValue::FC_String, // 0x08 DW_FORM_string
42  DWARFFormValue::FC_Block, // 0x09 DW_FORM_block
43  DWARFFormValue::FC_Block, // 0x0a DW_FORM_block1
44  DWARFFormValue::FC_Constant, // 0x0b DW_FORM_data1
45  DWARFFormValue::FC_Flag, // 0x0c DW_FORM_flag
46  DWARFFormValue::FC_Constant, // 0x0d DW_FORM_sdata
47  DWARFFormValue::FC_String, // 0x0e DW_FORM_strp
48  DWARFFormValue::FC_Constant, // 0x0f DW_FORM_udata
49  DWARFFormValue::FC_Reference, // 0x10 DW_FORM_ref_addr
50  DWARFFormValue::FC_Reference, // 0x11 DW_FORM_ref1
51  DWARFFormValue::FC_Reference, // 0x12 DW_FORM_ref2
52  DWARFFormValue::FC_Reference, // 0x13 DW_FORM_ref4
53  DWARFFormValue::FC_Reference, // 0x14 DW_FORM_ref8
54  DWARFFormValue::FC_Reference, // 0x15 DW_FORM_ref_udata
55  DWARFFormValue::FC_Indirect, // 0x16 DW_FORM_indirect
56  DWARFFormValue::FC_SectionOffset, // 0x17 DW_FORM_sec_offset
57  DWARFFormValue::FC_Exprloc, // 0x18 DW_FORM_exprloc
58  DWARFFormValue::FC_Flag, // 0x19 DW_FORM_flag_present
59  DWARFFormValue::FC_String, // 0x1a DW_FORM_strx
60  DWARFFormValue::FC_Address, // 0x1b DW_FORM_addrx
61  DWARFFormValue::FC_Reference, // 0x1c DW_FORM_ref_sup4
62  DWARFFormValue::FC_String, // 0x1d DW_FORM_strp_sup
63  DWARFFormValue::FC_Constant, // 0x1e DW_FORM_data16
64  DWARFFormValue::FC_String, // 0x1f DW_FORM_line_strp
65  DWARFFormValue::FC_Reference, // 0x20 DW_FORM_ref_sig8
66  DWARFFormValue::FC_Constant, // 0x21 DW_FORM_implicit_const
67  DWARFFormValue::FC_SectionOffset, // 0x22 DW_FORM_loclistx
68  DWARFFormValue::FC_SectionOffset, // 0x23 DW_FORM_rnglistx
69  DWARFFormValue::FC_Reference, // 0x24 DW_FORM_ref_sup8
70  DWARFFormValue::FC_String, // 0x25 DW_FORM_strx1
71  DWARFFormValue::FC_String, // 0x26 DW_FORM_strx2
72  DWARFFormValue::FC_String, // 0x27 DW_FORM_strx3
73  DWARFFormValue::FC_String, // 0x28 DW_FORM_strx4
74  DWARFFormValue::FC_Address, // 0x29 DW_FORM_addrx1
75  DWARFFormValue::FC_Address, // 0x2a DW_FORM_addrx2
76  DWARFFormValue::FC_Address, // 0x2b DW_FORM_addrx3
77  DWARFFormValue::FC_Address, // 0x2c DW_FORM_addrx4
78 
79 };
80 
82  uint32_t *OffsetPtr,
83  const dwarf::FormParams Params) {
84  bool Indirect = false;
85  do {
86  switch (Form) {
87  // Blocks of inlined data that have a length field and the data bytes
88  // inlined in the .debug_info.
89  case DW_FORM_exprloc:
90  case DW_FORM_block: {
91  uint64_t size = DebugInfoData.getULEB128(OffsetPtr);
92  *OffsetPtr += size;
93  return true;
94  }
95  case DW_FORM_block1: {
96  uint8_t size = DebugInfoData.getU8(OffsetPtr);
97  *OffsetPtr += size;
98  return true;
99  }
100  case DW_FORM_block2: {
101  uint16_t size = DebugInfoData.getU16(OffsetPtr);
102  *OffsetPtr += size;
103  return true;
104  }
105  case DW_FORM_block4: {
106  uint32_t size = DebugInfoData.getU32(OffsetPtr);
107  *OffsetPtr += size;
108  return true;
109  }
110 
111  // Inlined NULL terminated C-strings.
112  case DW_FORM_string:
113  DebugInfoData.getCStr(OffsetPtr);
114  return true;
115 
116  case DW_FORM_addr:
117  case DW_FORM_ref_addr:
118  case DW_FORM_flag_present:
119  case DW_FORM_data1:
120  case DW_FORM_data2:
121  case DW_FORM_data4:
122  case DW_FORM_data8:
123  case DW_FORM_data16:
124  case DW_FORM_flag:
125  case DW_FORM_ref1:
126  case DW_FORM_ref2:
127  case DW_FORM_ref4:
128  case DW_FORM_ref8:
129  case DW_FORM_ref_sig8:
130  case DW_FORM_ref_sup4:
131  case DW_FORM_ref_sup8:
132  case DW_FORM_strx1:
133  case DW_FORM_strx2:
134  case DW_FORM_strx4:
135  case DW_FORM_addrx1:
136  case DW_FORM_addrx2:
137  case DW_FORM_addrx4:
138  case DW_FORM_sec_offset:
139  case DW_FORM_strp:
140  case DW_FORM_strp_sup:
141  case DW_FORM_line_strp:
142  case DW_FORM_GNU_ref_alt:
143  case DW_FORM_GNU_strp_alt:
144  if (Optional<uint8_t> FixedSize =
145  dwarf::getFixedFormByteSize(Form, Params)) {
146  *OffsetPtr += *FixedSize;
147  return true;
148  }
149  return false;
150 
151  // signed or unsigned LEB 128 values.
152  case DW_FORM_sdata:
153  DebugInfoData.getSLEB128(OffsetPtr);
154  return true;
155 
156  case DW_FORM_udata:
157  case DW_FORM_ref_udata:
158  case DW_FORM_strx:
159  case DW_FORM_addrx:
160  case DW_FORM_loclistx:
161  case DW_FORM_rnglistx:
162  case DW_FORM_GNU_addr_index:
163  case DW_FORM_GNU_str_index:
164  DebugInfoData.getULEB128(OffsetPtr);
165  return true;
166 
167  case DW_FORM_indirect:
168  Indirect = true;
169  Form = static_cast<dwarf::Form>(DebugInfoData.getULEB128(OffsetPtr));
170  break;
171 
172  default:
173  return false;
174  }
175  } while (Indirect);
176  return true;
177 }
178 
180  // First, check DWARF5 form classes.
182  DWARF5FormClasses[Form] == FC)
183  return true;
184  // Check more forms from extensions and proposals.
185  switch (Form) {
186  case DW_FORM_GNU_ref_alt:
187  return (FC == FC_Reference);
188  case DW_FORM_GNU_addr_index:
189  return (FC == FC_Address);
190  case DW_FORM_GNU_str_index:
191  case DW_FORM_GNU_strp_alt:
192  return (FC == FC_String);
193  default:
194  break;
195  }
196  // In DWARF3 DW_FORM_data4 and DW_FORM_data8 served also as a section offset.
197  // Don't check for DWARF version here, as some producers may still do this
198  // by mistake. Also accept DW_FORM_[line_]strp since these are
199  // .debug_[line_]str section offsets.
200  return (Form == DW_FORM_data4 || Form == DW_FORM_data8 ||
201  Form == DW_FORM_strp || Form == DW_FORM_line_strp) &&
202  FC == FC_SectionOffset;
203 }
204 
206  uint32_t *OffsetPtr, dwarf::FormParams FP,
207  const DWARFContext *Ctx,
208  const DWARFUnit *CU) {
209  if (!Ctx && CU)
210  Ctx = &CU->getContext();
211  C = Ctx;
212  U = CU;
213  bool Indirect = false;
214  bool IsBlock = false;
215  Value.data = nullptr;
216  // Read the value for the form into value and follow and DW_FORM_indirect
217  // instances we run into
218  do {
219  Indirect = false;
220  switch (Form) {
221  case DW_FORM_addr:
222  case DW_FORM_ref_addr: {
223  uint16_t Size =
224  (Form == DW_FORM_addr) ? FP.AddrSize : FP.getRefAddrByteSize();
225  Value.uval = Data.getRelocatedValue(Size, OffsetPtr, &Value.SectionIndex);
226  break;
227  }
228  case DW_FORM_exprloc:
229  case DW_FORM_block:
230  Value.uval = Data.getULEB128(OffsetPtr);
231  IsBlock = true;
232  break;
233  case DW_FORM_block1:
234  Value.uval = Data.getU8(OffsetPtr);
235  IsBlock = true;
236  break;
237  case DW_FORM_block2:
238  Value.uval = Data.getU16(OffsetPtr);
239  IsBlock = true;
240  break;
241  case DW_FORM_block4:
242  Value.uval = Data.getU32(OffsetPtr);
243  IsBlock = true;
244  break;
245  case DW_FORM_data1:
246  case DW_FORM_ref1:
247  case DW_FORM_flag:
248  case DW_FORM_strx1:
249  case DW_FORM_addrx1:
250  Value.uval = Data.getU8(OffsetPtr);
251  break;
252  case DW_FORM_data2:
253  case DW_FORM_ref2:
254  case DW_FORM_strx2:
255  case DW_FORM_addrx2:
256  Value.uval = Data.getU16(OffsetPtr);
257  break;
258  case DW_FORM_strx3:
259  Value.uval = Data.getU24(OffsetPtr);
260  break;
261  case DW_FORM_data4:
262  case DW_FORM_ref4:
263  case DW_FORM_ref_sup4:
264  case DW_FORM_strx4:
265  case DW_FORM_addrx4:
266  Value.uval = Data.getRelocatedValue(4, OffsetPtr);
267  break;
268  case DW_FORM_data8:
269  case DW_FORM_ref8:
270  case DW_FORM_ref_sup8:
271  Value.uval = Data.getU64(OffsetPtr);
272  break;
273  case DW_FORM_data16:
274  // Treat this like a 16-byte block.
275  Value.uval = 16;
276  IsBlock = true;
277  break;
278  case DW_FORM_sdata:
279  Value.sval = Data.getSLEB128(OffsetPtr);
280  break;
281  case DW_FORM_udata:
282  case DW_FORM_ref_udata:
283  case DW_FORM_rnglistx:
284  Value.uval = Data.getULEB128(OffsetPtr);
285  break;
286  case DW_FORM_string:
287  Value.cstr = Data.getCStr(OffsetPtr);
288  break;
289  case DW_FORM_indirect:
290  Form = static_cast<dwarf::Form>(Data.getULEB128(OffsetPtr));
291  Indirect = true;
292  break;
293  case DW_FORM_strp:
294  case DW_FORM_sec_offset:
295  case DW_FORM_GNU_ref_alt:
296  case DW_FORM_GNU_strp_alt:
297  case DW_FORM_line_strp:
298  case DW_FORM_strp_sup: {
299  Value.uval =
300  Data.getRelocatedValue(FP.getDwarfOffsetByteSize(), OffsetPtr);
301  break;
302  }
303  case DW_FORM_flag_present:
304  Value.uval = 1;
305  break;
306  case DW_FORM_ref_sig8:
307  Value.uval = Data.getU64(OffsetPtr);
308  break;
309  case DW_FORM_GNU_addr_index:
310  case DW_FORM_GNU_str_index:
311  case DW_FORM_addrx:
312  case DW_FORM_strx:
313  Value.uval = Data.getULEB128(OffsetPtr);
314  break;
315  default:
316  // DWARFFormValue::skipValue() will have caught this and caused all
317  // DWARF DIEs to fail to be parsed, so this code is not be reachable.
318  llvm_unreachable("unsupported form");
319  }
320  } while (Indirect);
321 
322  if (IsBlock) {
323  StringRef Str = Data.getData().substr(*OffsetPtr, Value.uval);
324  Value.data = nullptr;
325  if (!Str.empty()) {
326  Value.data = reinterpret_cast<const uint8_t *>(Str.data());
327  *OffsetPtr += Value.uval;
328  }
329  }
330 
331  return true;
332 }
333 
335  DIDumpOptions DumpOpts,
336  SectionedAddress SA) const {
337  OS << format("0x%016" PRIx64, SA.Address);
338  dumpAddressSection(U->getContext().getDWARFObj(), OS, DumpOpts,
339  SA.SectionIndex);
340 }
341 
343  DIDumpOptions DumpOpts,
344  uint64_t SectionIndex) {
345  if (!DumpOpts.Verbose || SectionIndex == -1ULL)
346  return;
347  ArrayRef<SectionName> SectionNames = Obj.getSectionNames();
348  const auto &SecRef = SectionNames[SectionIndex];
349 
350  OS << " \"" << SecRef.Name << '\"';
351 
352  // Print section index if name is not unique.
353  if (!SecRef.IsNameUnique)
354  OS << format(" [%" PRIu64 "]", SectionIndex);
355 }
356 
357 void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
358  uint64_t UValue = Value.uval;
359  bool CURelativeOffset = false;
360  raw_ostream &AddrOS = DumpOpts.ShowAddresses
362  : nulls();
363  switch (Form) {
364  case DW_FORM_addr:
365  dumpSectionedAddress(AddrOS, DumpOpts, {Value.uval, Value.SectionIndex});
366  break;
367  case DW_FORM_addrx:
368  case DW_FORM_addrx1:
369  case DW_FORM_addrx2:
370  case DW_FORM_addrx3:
371  case DW_FORM_addrx4:
372  case DW_FORM_GNU_addr_index: {
373  Optional<SectionedAddress> A = U->getAddrOffsetSectionItem(UValue);
374  if (!A || DumpOpts.Verbose)
375  AddrOS << format("indexed (%8.8x) address = ", (uint32_t)UValue);
376  if (U == nullptr)
377  OS << "<invalid dwarf unit>";
378  else if (A)
379  dumpSectionedAddress(AddrOS, DumpOpts, *A);
380  else
381  OS << "<no .debug_addr section>";
382  break;
383  }
384  case DW_FORM_flag_present:
385  OS << "true";
386  break;
387  case DW_FORM_flag:
388  case DW_FORM_data1:
389  OS << format("0x%02x", (uint8_t)UValue);
390  break;
391  case DW_FORM_data2:
392  OS << format("0x%04x", (uint16_t)UValue);
393  break;
394  case DW_FORM_data4:
395  OS << format("0x%08x", (uint32_t)UValue);
396  break;
397  case DW_FORM_ref_sig8:
398  AddrOS << format("0x%016" PRIx64, UValue);
399  break;
400  case DW_FORM_data8:
401  OS << format("0x%016" PRIx64, UValue);
402  break;
403  case DW_FORM_data16:
404  OS << format_bytes(ArrayRef<uint8_t>(Value.data, 16), None, 16, 16);
405  break;
406  case DW_FORM_string:
407  OS << '"';
408  OS.write_escaped(Value.cstr);
409  OS << '"';
410  break;
411  case DW_FORM_exprloc:
412  case DW_FORM_block:
413  case DW_FORM_block1:
414  case DW_FORM_block2:
415  case DW_FORM_block4:
416  if (UValue > 0) {
417  switch (Form) {
418  case DW_FORM_exprloc:
419  case DW_FORM_block:
420  AddrOS << format("<0x%" PRIx64 "> ", UValue);
421  break;
422  case DW_FORM_block1:
423  AddrOS << format("<0x%2.2x> ", (uint8_t)UValue);
424  break;
425  case DW_FORM_block2:
426  AddrOS << format("<0x%4.4x> ", (uint16_t)UValue);
427  break;
428  case DW_FORM_block4:
429  AddrOS << format("<0x%8.8x> ", (uint32_t)UValue);
430  break;
431  default:
432  break;
433  }
434 
435  const uint8_t *DataPtr = Value.data;
436  if (DataPtr) {
437  // UValue contains size of block
438  const uint8_t *EndDataPtr = DataPtr + UValue;
439  while (DataPtr < EndDataPtr) {
440  AddrOS << format("%2.2x ", *DataPtr);
441  ++DataPtr;
442  }
443  } else
444  OS << "NULL";
445  }
446  break;
447 
448  case DW_FORM_sdata:
449  OS << Value.sval;
450  break;
451  case DW_FORM_udata:
452  OS << Value.uval;
453  break;
454  case DW_FORM_strp:
455  if (DumpOpts.Verbose)
456  OS << format(" .debug_str[0x%8.8x] = ", (uint32_t)UValue);
457  dumpString(OS);
458  break;
459  case DW_FORM_line_strp:
460  if (DumpOpts.Verbose)
461  OS << format(" .debug_line_str[0x%8.8x] = ", (uint32_t)UValue);
462  dumpString(OS);
463  break;
464  case DW_FORM_strx:
465  case DW_FORM_strx1:
466  case DW_FORM_strx2:
467  case DW_FORM_strx3:
468  case DW_FORM_strx4:
469  case DW_FORM_GNU_str_index:
470  if (DumpOpts.Verbose)
471  OS << format("indexed (%8.8x) string = ", (uint32_t)UValue);
472  dumpString(OS);
473  break;
474  case DW_FORM_GNU_strp_alt:
475  if (DumpOpts.Verbose)
476  OS << format("alt indirect string, offset: 0x%" PRIx64 "", UValue);
477  dumpString(OS);
478  break;
479  case DW_FORM_ref_addr:
480  AddrOS << format("0x%016" PRIx64, UValue);
481  break;
482  case DW_FORM_ref1:
483  CURelativeOffset = true;
484  if (DumpOpts.Verbose)
485  AddrOS << format("cu + 0x%2.2x", (uint8_t)UValue);
486  break;
487  case DW_FORM_ref2:
488  CURelativeOffset = true;
489  if (DumpOpts.Verbose)
490  AddrOS << format("cu + 0x%4.4x", (uint16_t)UValue);
491  break;
492  case DW_FORM_ref4:
493  CURelativeOffset = true;
494  if (DumpOpts.Verbose)
495  AddrOS << format("cu + 0x%4.4x", (uint32_t)UValue);
496  break;
497  case DW_FORM_ref8:
498  CURelativeOffset = true;
499  if (DumpOpts.Verbose)
500  AddrOS << format("cu + 0x%8.8" PRIx64, UValue);
501  break;
502  case DW_FORM_ref_udata:
503  CURelativeOffset = true;
504  if (DumpOpts.Verbose)
505  AddrOS << format("cu + 0x%" PRIx64, UValue);
506  break;
507  case DW_FORM_GNU_ref_alt:
508  AddrOS << format("<alt 0x%" PRIx64 ">", UValue);
509  break;
510 
511  // All DW_FORM_indirect attributes should be resolved prior to calling
512  // this function
513  case DW_FORM_indirect:
514  OS << "DW_FORM_indirect";
515  break;
516 
517  case DW_FORM_rnglistx:
518  OS << format("indexed (0x%x) rangelist = ", (uint32_t)UValue);
519  break;
520 
521  // Should be formatted to 64-bit for DWARF64.
522  case DW_FORM_sec_offset:
523  AddrOS << format("0x%08x", (uint32_t)UValue);
524  break;
525 
526  default:
527  OS << format("DW_FORM(0x%4.4x)", Form);
528  break;
529  }
530 
531  if (CURelativeOffset) {
532  if (DumpOpts.Verbose)
533  OS << " => {";
534  if (DumpOpts.ShowAddresses)
536  << format("0x%8.8" PRIx64, UValue + (U ? U->getOffset() : 0));
537  if (DumpOpts.Verbose)
538  OS << "}";
539  }
540 }
541 
542 void DWARFFormValue::dumpString(raw_ostream &OS) const {
543  Optional<const char *> DbgStr = getAsCString();
544  if (DbgStr.hasValue()) {
545  auto COS = WithColor(OS, HighlightColor::String);
546  COS.get() << '"';
547  COS.get().write_escaped(DbgStr.getValue());
548  COS.get() << '"';
549  }
550 }
551 
553  if (!isFormClass(FC_String))
554  return None;
555  if (Form == DW_FORM_string)
556  return Value.cstr;
557  // FIXME: Add support for DW_FORM_GNU_strp_alt
558  if (Form == DW_FORM_GNU_strp_alt || C == nullptr)
559  return None;
560  uint32_t Offset = Value.uval;
561  if (Form == DW_FORM_line_strp) {
562  // .debug_line_str is tracked in the Context.
563  if (const char *Str = C->getLineStringExtractor().getCStr(&Offset))
564  return Str;
565  return None;
566  }
567  if (Form == DW_FORM_GNU_str_index || Form == DW_FORM_strx ||
568  Form == DW_FORM_strx1 || Form == DW_FORM_strx2 || Form == DW_FORM_strx3 ||
569  Form == DW_FORM_strx4) {
570  if (!U)
571  return None;
572  Optional<uint64_t> StrOffset = U->getStringOffsetSectionItem(Offset);
573  if (!StrOffset)
574  return None;
575  Offset = *StrOffset;
576  }
577  // Prefer the Unit's string extractor, because for .dwo it will point to
578  // .debug_str.dwo, while the Context's extractor always uses .debug_str.
579  if (U) {
580  if (const char *Str = U->getStringExtractor().getCStr(&Offset))
581  return Str;
582  return None;
583  }
584  if (const char *Str = C->getStringExtractor().getCStr(&Offset))
585  return Str;
586  return None;
587 }
588 
590  if (auto SA = getAsSectionedAddress())
591  return SA->Address;
592  return None;
593 }
595  if (!isFormClass(FC_Address))
596  return None;
597  if (Form == DW_FORM_GNU_addr_index || Form == DW_FORM_addrx) {
598  uint32_t Index = Value.uval;
599  if (!U)
600  return None;
601  Optional<SectionedAddress> SA = U->getAddrOffsetSectionItem(Index);
602  if (!SA)
603  return None;
604  return SA;
605  }
606  return {{Value.uval, Value.SectionIndex}};
607 }
608 
610  if (!isFormClass(FC_Reference))
611  return None;
612  switch (Form) {
613  case DW_FORM_ref1:
614  case DW_FORM_ref2:
615  case DW_FORM_ref4:
616  case DW_FORM_ref8:
617  case DW_FORM_ref_udata:
618  if (!U)
619  return None;
620  return Value.uval + U->getOffset();
621  case DW_FORM_ref_addr:
622  case DW_FORM_ref_sig8:
623  case DW_FORM_GNU_ref_alt:
624  return Value.uval;
625  default:
626  return None;
627  }
628 }
629 
631  if (!isFormClass(FC_SectionOffset))
632  return None;
633  return Value.uval;
634 }
635 
637  if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) ||
638  Form == DW_FORM_sdata)
639  return None;
640  return Value.uval;
641 }
642 
644  if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) ||
645  (Form == DW_FORM_udata &&
646  uint64_t(std::numeric_limits<int64_t>::max()) < Value.uval))
647  return None;
648  switch (Form) {
649  case DW_FORM_data4:
650  return int32_t(Value.uval);
651  case DW_FORM_data2:
652  return int16_t(Value.uval);
653  case DW_FORM_data1:
654  return int8_t(Value.uval);
655  case DW_FORM_sdata:
656  case DW_FORM_data8:
657  default:
658  return Value.sval;
659  }
660 }
661 
663  if (!isFormClass(FC_Block) && !isFormClass(FC_Exprloc) &&
664  Form != DW_FORM_data16)
665  return None;
666  return makeArrayRef(Value.data, Value.uval);
667 }
668 
670  if (!isFormClass(FC_String) && Form == DW_FORM_string)
671  return None;
672  return Value.uval;
673 }
674 
676  if (!isFormClass(FC_Reference))
677  return None;
678  return Value.uval;
679 }
void dump(raw_ostream &OS, DIDumpOptions DumpOpts=DIDumpOptions()) const
const NoneType None
Definition: None.h:24
uint64_t CallInst * C
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...
Definition: Dwarf.h:499
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
uint64_t getULEB128(uint32_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
static const DWARFFormValue::FormClass DWARF5FormClasses[]
An RAII object that temporarily switches an output stream to a specific color.
Definition: WithColor.h:38
uint32_t getU24(uint32_t *offset_ptr) const
Extract a 24-bit unsigned value from *offset_ptr and return it in a uint32_t.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
uint8_t getRefAddrByteSize() const
The definition of the size of form DW_FORM_ref_addr depends on the version.
Definition: Dwarf.h:507
StringRef getData() const
Get the data pointed to by this extractor.
Definition: DataExtractor.h:55
uint16_t getU16(uint32_t *offset_ptr) const
Extract a uint16_t value from *offset_ptr.
bool isFormClass(FormClass FC) const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
Optional< SectionedAddress > getAsSectionedAddress() const
Optional< uint64_t > getAsReference() const
getAsFoo functions below return the extracted value as Foo if only DWARFFormValue has form class is s...
uint32_t getU32(uint32_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
Optional< ArrayRef< uint8_t > > getAsBlock() const
void dumpSectionedAddress(raw_ostream &OS, DIDumpOptions DumpOpts, SectionedAddress SA) const
const T & getValue() const LLVM_LVALUE_FUNCTION
Definition: Optional.h:161
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:598
int64_t getSLEB128(uint32_t *offset_ptr) const
Extract a signed LEB128 value from *offset_ptr.
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:159
raw_ostream & get()
Definition: WithColor.h:65
static void dumpAddressSection(const DWARFObject &Obj, raw_ostream &OS, DIDumpOptions DumpOpts, uint64_t SectionIndex)
Optional< uint64_t > getAsAddress() const
uint8_t getU8(uint32_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
Optional< uint64_t > getAsUnsignedConstant() const
bool skipValue(DataExtractor DebugInfoData, uint32_t *OffsetPtr, const dwarf::FormParams Params) const
Skip a form&#39;s value in DebugInfoData at the offset specified by OffsetPtr.
DWARFContext & getContext() const
Definition: DWARFUnit.h:271
Optional< uint64_t > getAsReferenceUVal() const
uint64_t getU64(uint32_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
uint64_t getRelocatedValue(uint32_t Size, uint32_t *Off, uint64_t *SectionIndex=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset...
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning &#39;\&#39;, &#39;&#39;, &#39; &#39;, &#39;"&#39;, and anything that doesn&#39;t satisfy llvm::isPrint into an escape...
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:1167
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:59
Optional< uint64_t > getAsCStringOffset() const
This file contains constants used for implementing Dwarf debug support.
bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr, dwarf::FormParams FormParams, const DWARFContext *Context=nullptr, const DWARFUnit *Unit=nullptr)
Extracts a value in Data at offset *OffsetPtr.
Optional< uint8_t > getFixedFormByteSize(dwarf::Form Form, FormParams Params)
Get the fixed byte size for a given form.
Definition: Dwarf.cpp:626
bool hasValue() const
Definition: Optional.h:165
Optional< const char * > getAsCString() const
const char * getCStr(uint32_t *offset_ptr) const
Extract a C string from *offset_ptr.
virtual ArrayRef< SectionName > getSectionNames() const
Definition: DWARFObject.h:33
uint32_t Size
Definition: Profile.cpp:47
Optional< int64_t > getAsSignedConstant() const
LLVM Value Representation.
Definition: Value.h:73
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
uint8_t getDwarfOffsetByteSize() const
The size of a reference is determined by the DWARF 32/64-bit format.
Definition: Dwarf.h:514
Optional< uint64_t > getAsSectionOffset() const