llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: Hemang Gadhavi (HemangGadhavi) <details> <summary>Changes</summary> This PR introduces support for the DWARF64 format, enabling handling of 64-bit DWARF sections as defined by the DWARF specification. The update includes adjustments to header parsing and modification of form values to accommodate 64-bit offsets and values. --- Full diff: https://github.com/llvm/llvm-project/pull/145645.diff 3 Files Affected: - (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp (+24-9) - (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp (+1-14) - (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h (+1) ``````````diff diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp index fd3d45cef4c5e..1a712c3c769af 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp @@ -77,7 +77,10 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, case DW_FORM_strp: case DW_FORM_line_strp: case DW_FORM_sec_offset: - m_value.uval = data.GetMaxU64(offset_ptr, 4); + if (m_unit->GetFormat() == DwarfFormat::DWARF32) + m_value.uval = data.GetMaxU64(offset_ptr, 4); + else if (m_unit->GetFormat() == DwarfFormat::DWARF64) + m_value.uval = data.GetMaxU64(offset_ptr, 8); break; case DW_FORM_addrx1: case DW_FORM_strx1: @@ -121,8 +124,12 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, assert(m_unit); if (m_unit->GetVersion() <= 2) ref_addr_size = m_unit->GetAddressByteSize(); - else - ref_addr_size = 4; + else { + if (m_unit->GetFormat() == DwarfFormat::DWARF32) + ref_addr_size = 4; + else if (m_unit->GetFormat() == DwarfFormat::DWARF64) + ref_addr_size = 8; + } m_value.uval = data.GetMaxU64(offset_ptr, ref_addr_size); break; case DW_FORM_indirect: @@ -165,7 +172,7 @@ static FormSize g_form_sizes[] = { {1, 1}, // 0x0b DW_FORM_data1 {1, 1}, // 0x0c DW_FORM_flag {0, 0}, // 0x0d DW_FORM_sdata - {1, 4}, // 0x0e DW_FORM_strp + {0, 0}, // 0x0e DW_FORM_strp (4 bytes for DWARF32, 8 bytes for DWARF64) {0, 0}, // 0x0f DW_FORM_udata {0, 0}, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes // for DWARF32, 8 bytes for DWARF32 in DWARF 3 and later @@ -175,7 +182,8 @@ static FormSize g_form_sizes[] = { {1, 8}, // 0x14 DW_FORM_ref8 {0, 0}, // 0x15 DW_FORM_ref_udata {0, 0}, // 0x16 DW_FORM_indirect - {1, 4}, // 0x17 DW_FORM_sec_offset + {0, + 0}, // 0x17 DW_FORM_sec_offset (4 bytes for DWARF32, 8 bytes for DWARF64) {0, 0}, // 0x18 DW_FORM_exprloc {1, 0}, // 0x19 DW_FORM_flag_present {0, 0}, // 0x1a DW_FORM_strx (ULEB128) @@ -183,7 +191,7 @@ static FormSize g_form_sizes[] = { {1, 4}, // 0x1c DW_FORM_ref_sup4 {0, 0}, // 0x1d DW_FORM_strp_sup (4 bytes for DWARF32, 8 bytes for DWARF64) {1, 16}, // 0x1e DW_FORM_data16 - {1, 4}, // 0x1f DW_FORM_line_strp + {0, 0}, // 0x1f DW_FORM_line_strp (4 bytes for DWARF32, 8 bytes for DWARF64) {1, 8}, // 0x20 DW_FORM_ref_sig8 }; @@ -251,8 +259,12 @@ bool DWARFFormValue::SkipValue(dw_form_t form, // get this wrong if (unit->GetVersion() <= 2) ref_addr_size = unit->GetAddressByteSize(); - else - ref_addr_size = 4; + else { + if (unit->GetFormat() == DwarfFormat::DWARF32) + ref_addr_size = 4; + else if (unit->GetFormat() == DwarfFormat::DWARF64) + ref_addr_size = 8; + } *offset_ptr += ref_addr_size; return true; @@ -288,7 +300,10 @@ bool DWARFFormValue::SkipValue(dw_form_t form, case DW_FORM_sec_offset: case DW_FORM_strp: case DW_FORM_line_strp: - *offset_ptr += 4; + if (unit->GetFormat() == DwarfFormat::DWARF32) + *offset_ptr += 4; + else if (unit->GetFormat() == DwarfFormat::DWARF64) + *offset_ptr += 8; return true; // 4 byte values diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp index ffd6f1dd52aff..f216ab13e8936 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -1073,20 +1073,7 @@ const lldb_private::DWARFDataExtractor &DWARFUnit::GetData() const { : m_dwarf.GetDWARFContext().getOrLoadDebugInfoData(); } -uint32_t DWARFUnit::GetHeaderByteSize() const { - switch (m_header.getUnitType()) { - case llvm::dwarf::DW_UT_compile: - case llvm::dwarf::DW_UT_partial: - return GetVersion() < 5 ? 11 : 12; - case llvm::dwarf::DW_UT_skeleton: - case llvm::dwarf::DW_UT_split_compile: - return 20; - case llvm::dwarf::DW_UT_type: - case llvm::dwarf::DW_UT_split_type: - return GetVersion() < 5 ? 23 : 24; - } - llvm_unreachable("invalid UnitType."); -} +uint32_t DWARFUnit::GetHeaderByteSize() const { return m_header.getSize(); } std::optional<uint64_t> DWARFUnit::GetStringOffsetSectionItem(uint32_t index) const { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h index c05bba36ed74b..9f53d7dcdef53 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h @@ -119,6 +119,7 @@ class DWARFUnit : public DWARFExpression::Delegate, public UserID { // Size of the CU data incl. header but without initial length. dw_offset_t GetLength() const { return m_header.getLength(); } uint16_t GetVersion() const override { return m_header.getVersion(); } + llvm::dwarf::DwarfFormat GetFormat() const { return m_header.getFormat(); } const llvm::DWARFAbbreviationDeclarationSet *GetAbbreviations() const; dw_offset_t GetAbbrevOffset() const; uint8_t GetAddressByteSize() const override { `````````` </details> https://github.com/llvm/llvm-project/pull/145645 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits