https://github.com/HemangGadhavi updated 
https://github.com/llvm/llvm-project/pull/145645

>From 547716f930b16cd66b5aa6ce3a59aaf6167ece01 Mon Sep 17 00:00:00 2001
From: HemangGadhavi <hemang.gadh...@ibm.com>
Date: Wed, 25 Jun 2025 02:06:05 -0400
Subject: [PATCH] [lldb][DWARF64] Enable support for DWARF64 format handling

---
 .../SymbolFile/DWARF/DWARFFormValue.cpp       | 59 ++++++++++++-------
 .../Plugins/SymbolFile/DWARF/DWARFUnit.cpp    | 15 +----
 .../Plugins/SymbolFile/DWARF/DWARFUnit.h      |  1 +
 3 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
index fd3d45cef4c5e..693d3faf537d7 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,26 +172,27 @@ 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
-    {1, 1},  // 0x11 DW_FORM_ref1
-    {1, 2},  // 0x12 DW_FORM_ref2
-    {1, 4},  // 0x13 DW_FORM_ref4
-    {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},  // 0x18 DW_FORM_exprloc
-    {1, 0},  // 0x19 DW_FORM_flag_present
-    {0, 0},  // 0x1a DW_FORM_strx (ULEB128)
-    {0, 0},  // 0x1b DW_FORM_addrx (ULEB128)
-    {1, 4},  // 0x1c DW_FORM_ref_sup4
-    {0, 0},  // 0x1d DW_FORM_strp_sup (4 bytes for DWARF32, 8 bytes for 
DWARF64)
+    {1, 1}, // 0x11 DW_FORM_ref1
+    {1, 2}, // 0x12 DW_FORM_ref2
+    {1, 4}, // 0x13 DW_FORM_ref4
+    {1, 8}, // 0x14 DW_FORM_ref8
+    {0, 0}, // 0x15 DW_FORM_ref_udata
+    {0, 0}, // 0x16 DW_FORM_indirect
+    {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)
+    {0, 0}, // 0x1b DW_FORM_addrx (ULEB128)
+    {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
-    {1, 8},  // 0x20 DW_FORM_ref_sig8
+    {0, 0}, // 0x1f DW_FORM_line_strp (4 bytes for DWARF32, 8 bytes for 
DWARF64)
+    {1, 8}, // 0x20 DW_FORM_ref_sig8
 };
 
 std::optional<uint8_t> DWARFFormValue::GetFixedSize(dw_form_t form,
@@ -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 {

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to