@@ -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
190198std::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
0 commit comments