27 using namespace dwarf;
101 uint64_t *OffsetPtr) {
111 bool Indirect =
false;
116 case DW_FORM_exprloc:
117 case DW_FORM_block: {
122 case DW_FORM_block1: {
123 uint8_t
size = DebugInfoData.
getU8(OffsetPtr);
127 case DW_FORM_block2: {
132 case DW_FORM_block4: {
140 DebugInfoData.
getCStr(OffsetPtr);
144 case DW_FORM_ref_addr:
145 case DW_FORM_flag_present:
156 case DW_FORM_ref_sig8:
157 case DW_FORM_ref_sup4:
158 case DW_FORM_ref_sup8:
165 case DW_FORM_sec_offset:
167 case DW_FORM_strp_sup:
168 case DW_FORM_line_strp:
169 case DW_FORM_GNU_ref_alt:
170 case DW_FORM_GNU_strp_alt:
173 *OffsetPtr += *FixedSize;
184 case DW_FORM_ref_udata:
187 case DW_FORM_loclistx:
188 case DW_FORM_rnglistx:
189 case DW_FORM_GNU_addr_index:
190 case DW_FORM_GNU_str_index:
194 case DW_FORM_LLVM_addrx_offset:
199 case DW_FORM_indirect:
218 case DW_FORM_GNU_ref_alt:
219 return (
FC == FC_Reference);
220 case DW_FORM_GNU_addr_index:
221 return (
FC == FC_Address);
222 case DW_FORM_GNU_str_index:
223 case DW_FORM_GNU_strp_alt:
224 return (
FC == FC_String);
225 case DW_FORM_LLVM_addrx_offset:
226 return (
FC == FC_Address);
231 if (
FC == FC_SectionOffset) {
232 if (
Form == DW_FORM_strp ||
Form == DW_FORM_line_strp)
236 if (
Form == DW_FORM_data4 ||
Form == DW_FORM_data8)
237 return !U || U->getVersion() <= 3;
248 Ctx = &
CU->getContext();
252 bool Indirect =
false;
253 bool IsBlock =
false;
254 Value.data =
nullptr;
262 case DW_FORM_ref_addr: {
264 (
Form == DW_FORM_addr) ? FP.AddrSize : FP.getRefAddrByteSize();
266 Data.getRelocatedValue(
Size, OffsetPtr, &
Value.SectionIndex, &Err);
269 case DW_FORM_exprloc:
271 Value.uval =
Data.getULEB128(OffsetPtr, &Err);
275 Value.uval =
Data.getU8(OffsetPtr, &Err);
279 Value.uval =
Data.getU16(OffsetPtr, &Err);
283 Value.uval =
Data.getU32(OffsetPtr, &Err);
291 Value.uval =
Data.getU8(OffsetPtr, &Err);
297 Value.uval =
Data.getU16(OffsetPtr, &Err);
300 Value.uval =
Data.getU24(OffsetPtr, &Err);
304 case DW_FORM_ref_sup4:
307 Value.uval =
Data.getRelocatedValue(4, OffsetPtr,
nullptr, &Err);
311 case DW_FORM_ref_sup8:
312 Value.uval =
Data.getRelocatedValue(8, OffsetPtr,
nullptr, &Err);
320 Value.sval =
Data.getSLEB128(OffsetPtr, &Err);
323 case DW_FORM_ref_udata:
324 case DW_FORM_rnglistx:
325 case DW_FORM_loclistx:
326 case DW_FORM_GNU_addr_index:
327 case DW_FORM_GNU_str_index:
330 Value.uval =
Data.getULEB128(OffsetPtr, &Err);
332 case DW_FORM_LLVM_addrx_offset:
333 Value.uval =
Data.getULEB128(OffsetPtr, &Err) << 32;
334 Value.uval =
Data.getU32(OffsetPtr, &Err);
337 Value.cstr =
Data.getCStr(OffsetPtr, &Err);
339 case DW_FORM_indirect:
344 case DW_FORM_sec_offset:
345 case DW_FORM_GNU_ref_alt:
346 case DW_FORM_GNU_strp_alt:
347 case DW_FORM_line_strp:
348 case DW_FORM_strp_sup: {
349 Value.uval =
Data.getRelocatedValue(FP.getDwarfOffsetByteSize(),
350 OffsetPtr,
nullptr, &Err);
353 case DW_FORM_flag_present:
356 case DW_FORM_ref_sig8:
357 Value.uval =
Data.getU64(OffsetPtr, &Err);
364 }
while (Indirect && !Err);
367 Value.data =
Data.getBytes(OffsetPtr,
Value.uval, &Err).bytes_begin();
374 uint8_t HexDigits = AddressSize * 2;
375 OS <<
format(
"0x%*.*" PRIx64, HexDigits, HexDigits,
Address);
381 dumpAddress(OS, U->getAddressByteSize(), SA.
Address);
382 dumpAddressSection(U->getContext().getDWARFObj(), OS, DumpOpts,
388 uint64_t SectionIndex) {
389 if (!DumpOpts.
Verbose || SectionIndex == -1ULL)
392 const auto &SecRef = SectionNames[SectionIndex];
394 OS <<
" \"" << SecRef.Name <<
'\"';
397 if (!SecRef.IsNameUnique)
398 OS <<
format(
" [%" PRIu64
"]", SectionIndex);
402 uint64_t UValue =
Value.uval;
403 bool CURelativeOffset =
false;
410 dumpSectionedAddress(AddrOS, DumpOpts, {
Value.uval,
Value.SectionIndex});
417 case DW_FORM_GNU_addr_index: {
419 OS <<
"<invalid dwarf unit>";
426 dumpSectionedAddress(AddrOS, DumpOpts, *A);
428 OS <<
"<unresolved>";
431 case DW_FORM_LLVM_addrx_offset: {
433 OS <<
"<invalid dwarf unit>";
443 dumpSectionedAddress(AddrOS, DumpOpts, *A);
445 OS <<
"<unresolved>";
448 case DW_FORM_flag_present:
453 OS <<
format(
"0x%02x", (uint8_t)UValue);
461 case DW_FORM_ref_sig8:
462 AddrOS <<
format(
"0x%016" PRIx64, UValue);
465 OS <<
format(
"0x%016" PRIx64, UValue);
468 OS << format_bytes(ArrayRef<uint8_t>(
Value.data, 16),
None, 16, 16);
475 case DW_FORM_exprloc:
482 case DW_FORM_exprloc:
484 AddrOS <<
format(
"<0x%" PRIx64
"> ", UValue);
487 AddrOS <<
format(
"<0x%2.2x> ", (uint8_t)UValue);
499 const uint8_t *DataPtr =
Value.data;
502 const uint8_t *EndDataPtr = DataPtr + UValue;
503 while (DataPtr < EndDataPtr) {
504 AddrOS <<
format(
"%2.2x ", *DataPtr);
520 OS <<
format(
" .debug_str[0x%0*" PRIx64
"] = ", OffsetDumpWidth, UValue);
523 case DW_FORM_line_strp:
525 OS <<
format(
" .debug_line_str[0x%0*" PRIx64
"] = ", OffsetDumpWidth,
534 case DW_FORM_GNU_str_index:
539 case DW_FORM_GNU_strp_alt:
541 OS <<
format(
"alt indirect string, offset: 0x%" PRIx64
"", UValue);
544 case DW_FORM_ref_addr:
545 AddrOS <<
format(
"0x%016" PRIx64, UValue);
548 CURelativeOffset =
true;
550 AddrOS <<
format(
"cu + 0x%2.2x", (uint8_t)UValue);
553 CURelativeOffset =
true;
558 CURelativeOffset =
true;
563 CURelativeOffset =
true;
565 AddrOS <<
format(
"cu + 0x%8.8" PRIx64, UValue);
567 case DW_FORM_ref_udata:
568 CURelativeOffset =
true;
570 AddrOS <<
format(
"cu + 0x%" PRIx64, UValue);
572 case DW_FORM_GNU_ref_alt:
573 AddrOS <<
format(
"<alt 0x%" PRIx64
">", UValue);
578 case DW_FORM_indirect:
579 OS <<
"DW_FORM_indirect";
582 case DW_FORM_rnglistx:
586 case DW_FORM_loclistx:
590 case DW_FORM_sec_offset:
591 AddrOS <<
format(
"0x%0*" PRIx64, OffsetDumpWidth, UValue);
599 if (CURelativeOffset) {
604 <<
format(
"0x%8.8" PRIx64, UValue + (U ? U->getOffset() : 0));
610 void DWARFFormValue::dumpString(
raw_ostream &OS)
const {
615 COS.get().write_escaped(DbgStr.
getValue());
621 if (!isFormClass(FC_String))
623 if (
Form == DW_FORM_string)
626 if (
Form == DW_FORM_GNU_strp_alt ||
C ==
nullptr)
629 if (
Form == DW_FORM_line_strp) {
631 if (
const char *Str =
C->getLineStringExtractor().getCStr(&
Offset))
635 if (
Form == DW_FORM_GNU_str_index ||
Form == DW_FORM_strx ||
636 Form == DW_FORM_strx1 ||
Form == DW_FORM_strx2 ||
Form == DW_FORM_strx3 ||
637 Form == DW_FORM_strx4) {
648 if (
const char *Str = U->getStringExtractor().getCStr(&
Offset))
652 if (
const char *Str =
C->getStringExtractor().getCStr(&
Offset))
658 if (
auto SA = getAsSectionedAddress())
665 if (!isFormClass(FC_Address))
667 bool AddrOffset =
Form == dwarf::DW_FORM_LLVM_addrx_offset;
668 if (
Form == DW_FORM_GNU_addr_index ||
Form == DW_FORM_addrx || AddrOffset) {
684 if (
auto R = getAsRelativeReference())
685 return R->Unit ? R->Unit->getOffset() + R->Offset : R->Offset;
690 if (!isFormClass(FC_Reference))
697 case DW_FORM_ref_udata:
701 case DW_FORM_ref_addr:
702 case DW_FORM_ref_sig8:
703 case DW_FORM_GNU_ref_alt:
711 if (!isFormClass(FC_SectionOffset))
717 if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) ||
718 Form == DW_FORM_sdata)
724 if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) ||
725 (
Form == DW_FORM_udata &&
730 return int32_t(
Value.uval);
732 return int16_t(
Value.uval);
734 return int8_t(
Value.uval);
743 if (!isFormClass(FC_Block) && !isFormClass(FC_Exprloc) &&
744 Form != DW_FORM_data16)
750 if (!isFormClass(FC_String) &&
Form == DW_FORM_string)
756 if (!isFormClass(FC_Reference))