Skip to content

Commit a85d648

Browse files
committed
[lldb][DWARF64] Enable support for DWARF64 format handling
1 parent 1c35fe4 commit a85d648

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data,
7777
case DW_FORM_strp:
7878
case DW_FORM_line_strp:
7979
case DW_FORM_sec_offset:
80-
m_value.uval = data.GetMaxU64(offset_ptr, 4);
80+
if (m_unit->GetFormat() == DwarfFormat::DWARF32)
81+
m_value.uval = data.GetMaxU64(offset_ptr, 4);
82+
else if (m_unit->GetFormat() == DwarfFormat::DWARF64)
83+
m_value.uval = data.GetMaxU64(offset_ptr, 8);
8184
break;
8285
case DW_FORM_addrx1:
8386
case DW_FORM_strx1:
@@ -121,8 +124,12 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data,
121124
assert(m_unit);
122125
if (m_unit->GetVersion() <= 2)
123126
ref_addr_size = m_unit->GetAddressByteSize();
124-
else
125-
ref_addr_size = 4;
127+
else {
128+
if (m_unit->GetFormat() == DwarfFormat::DWARF32)
129+
ref_addr_size = 4;
130+
else if (m_unit->GetFormat() == DwarfFormat::DWARF64)
131+
ref_addr_size = 8;
132+
}
126133
m_value.uval = data.GetMaxU64(offset_ptr, ref_addr_size);
127134
break;
128135
case DW_FORM_indirect:
@@ -165,26 +172,27 @@ static FormSize g_form_sizes[] = {
165172
{1, 1}, // 0x0b DW_FORM_data1
166173
{1, 1}, // 0x0c DW_FORM_flag
167174
{0, 0}, // 0x0d DW_FORM_sdata
168-
{1, 4}, // 0x0e DW_FORM_strp
175+
{0, 0}, // 0x0e DW_FORM_strp (4 bytes for DWARF32, 8 bytes for DWARF64)
169176
{0, 0}, // 0x0f DW_FORM_udata
170177
{0, 0}, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes
171178
// for DWARF32, 8 bytes for DWARF32 in DWARF 3 and later
172-
{1, 1}, // 0x11 DW_FORM_ref1
173-
{1, 2}, // 0x12 DW_FORM_ref2
174-
{1, 4}, // 0x13 DW_FORM_ref4
175-
{1, 8}, // 0x14 DW_FORM_ref8
176-
{0, 0}, // 0x15 DW_FORM_ref_udata
177-
{0, 0}, // 0x16 DW_FORM_indirect
178-
{1, 4}, // 0x17 DW_FORM_sec_offset
179+
{1, 1}, // 0x11 DW_FORM_ref1
180+
{1, 2}, // 0x12 DW_FORM_ref2
181+
{1, 4}, // 0x13 DW_FORM_ref4
182+
{1, 8}, // 0x14 DW_FORM_ref8
183+
{0, 0}, // 0x15 DW_FORM_ref_udata
184+
{0, 0}, // 0x16 DW_FORM_indirect
185+
{0,
186+
0}, // 0x17 DW_FORM_sec_offset (4 bytes for DWARF32, 8 bytes for DWARF64)
179187
{0, 0}, // 0x18 DW_FORM_exprloc
180188
{1, 0}, // 0x19 DW_FORM_flag_present
181189
{0, 0}, // 0x1a DW_FORM_strx (ULEB128)
182190
{0, 0}, // 0x1b DW_FORM_addrx (ULEB128)
183191
{1, 4}, // 0x1c DW_FORM_ref_sup4
184192
{0, 0}, // 0x1d DW_FORM_strp_sup (4 bytes for DWARF32, 8 bytes for DWARF64)
185193
{1, 16}, // 0x1e DW_FORM_data16
186-
{1, 4}, // 0x1f DW_FORM_line_strp
187-
{1, 8}, // 0x20 DW_FORM_ref_sig8
194+
{0, 0}, // 0x1f DW_FORM_line_strp (4 bytes for DWARF32, 8 bytes for DWARF64)
195+
{1, 8}, // 0x20 DW_FORM_ref_sig8
188196
};
189197

190198
std::optional<uint8_t> DWARFFormValue::GetFixedSize(dw_form_t form,
@@ -251,8 +259,12 @@ bool DWARFFormValue::SkipValue(dw_form_t form,
251259
// get this wrong
252260
if (unit->GetVersion() <= 2)
253261
ref_addr_size = unit->GetAddressByteSize();
254-
else
255-
ref_addr_size = 4;
262+
else {
263+
if (unit->GetFormat() == DwarfFormat::DWARF32)
264+
ref_addr_size = 4;
265+
else if (unit->GetFormat() == DwarfFormat::DWARF64)
266+
ref_addr_size = 8;
267+
}
256268
*offset_ptr += ref_addr_size;
257269
return true;
258270

@@ -288,7 +300,10 @@ bool DWARFFormValue::SkipValue(dw_form_t form,
288300
case DW_FORM_sec_offset:
289301
case DW_FORM_strp:
290302
case DW_FORM_line_strp:
291-
*offset_ptr += 4;
303+
if (unit->GetFormat() == DwarfFormat::DWARF32)
304+
*offset_ptr += 4;
305+
else if (unit->GetFormat() == DwarfFormat::DWARF64)
306+
*offset_ptr += 8;
292307
return true;
293308

294309
// 4 byte values

lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,20 +1073,7 @@ const lldb_private::DWARFDataExtractor &DWARFUnit::GetData() const {
10731073
: m_dwarf.GetDWARFContext().getOrLoadDebugInfoData();
10741074
}
10751075

1076-
uint32_t DWARFUnit::GetHeaderByteSize() const {
1077-
switch (m_header.getUnitType()) {
1078-
case llvm::dwarf::DW_UT_compile:
1079-
case llvm::dwarf::DW_UT_partial:
1080-
return GetVersion() < 5 ? 11 : 12;
1081-
case llvm::dwarf::DW_UT_skeleton:
1082-
case llvm::dwarf::DW_UT_split_compile:
1083-
return 20;
1084-
case llvm::dwarf::DW_UT_type:
1085-
case llvm::dwarf::DW_UT_split_type:
1086-
return GetVersion() < 5 ? 23 : 24;
1087-
}
1088-
llvm_unreachable("invalid UnitType.");
1089-
}
1076+
uint32_t DWARFUnit::GetHeaderByteSize() const { return m_header.getSize(); }
10901077

10911078
std::optional<uint64_t>
10921079
DWARFUnit::GetStringOffsetSectionItem(uint32_t index) const {

lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class DWARFUnit : public DWARFExpression::Delegate, public UserID {
119119
// Size of the CU data incl. header but without initial length.
120120
dw_offset_t GetLength() const { return m_header.getLength(); }
121121
uint16_t GetVersion() const override { return m_header.getVersion(); }
122+
llvm::dwarf::DwarfFormat GetFormat() const { return m_header.getFormat(); }
122123
const llvm::DWARFAbbreviationDeclarationSet *GetAbbreviations() const;
123124
dw_offset_t GetAbbrevOffset() const;
124125
uint8_t GetAddressByteSize() const override {

0 commit comments

Comments
 (0)