@@ -348,6 +348,10 @@ void DWARFUnit::ExtractDIEsRWLocked() {
348348void DWARFUnit::SetDwoStrOffsetsBase () {
349349 lldb::offset_t baseOffset = 0 ;
350350
351+ // Size of offset for .debug_str_offsets is same as DWARF offset byte size
352+ // of the DWARFUnit as a default. We might override this if below if needed.
353+ m_str_offset_size = m_header.getDwarfOffsetByteSize ();
354+
351355 if (const llvm::DWARFUnitIndex::Entry *entry = m_header.getIndexEntry ()) {
352356 if (const auto *contribution =
353357 entry->getContribution (llvm::DW_SECT_STR_OFFSETS))
@@ -362,7 +366,7 @@ void DWARFUnit::SetDwoStrOffsetsBase() {
362366 uint64_t length = strOffsets.GetU32 (&baseOffset);
363367 if (length == llvm::dwarf::DW_LENGTH_DWARF64) {
364368 length = strOffsets.GetU64 (&baseOffset);
365- m_str_offsets_size = 8 ;
369+ m_str_offset_size = 8 ;
366370 }
367371
368372 // Check version.
@@ -371,13 +375,7 @@ void DWARFUnit::SetDwoStrOffsetsBase() {
371375
372376 // Skip padding.
373377 baseOffset += 2 ;
374- } else {
375- // Size of offset for .debug_str_offsets is same as DWARF offset byte size
376- // of the DWARFUnit for DWARF version 4 and earlier.
377- m_str_offsets_size = m_header.getDwarfOffsetByteSize ();
378378 }
379-
380-
381379 SetStrOffsetsBase (baseOffset);
382380}
383381
@@ -416,7 +414,16 @@ void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) {
416414 SetRangesBase (form_value.Unsigned ());
417415 break ;
418416 case DW_AT_str_offsets_base:
417+ // When we have a DW_AT_str_offsets_base attribute, it points us to the
418+ // first string offset for this DWARFUnit which is after the string
419+ // offsets table header. In this case we use the DWARF32/DWARF64 of the
420+ // DWARFUnit to determine the string offset byte size. DWO files do not
421+ // use this attribute and they point to the start of the string offsets
422+ // table header which can be used to determine the DWARF32/DWARF64 status
423+ // of the string table. See SetDwoStrOffsetsBase() for now it figures out
424+ // the m_str_offset_size value that should be used.
419425 SetStrOffsetsBase (form_value.Unsigned ());
426+ m_str_offset_size = m_header.getDwarfOffsetByteSize ();
420427 break ;
421428 case DW_AT_low_pc:
422429 SetBaseAddress (form_value.Address ());
@@ -1086,9 +1093,9 @@ uint32_t DWARFUnit::GetHeaderByteSize() const { return m_header.getSize(); }
10861093
10871094std::optional<uint64_t >
10881095DWARFUnit::GetStringOffsetSectionItem (uint32_t index) const {
1089- lldb::offset_t offset = GetStrOffsetsBase () + index * m_str_offsets_size ;
1096+ lldb::offset_t offset = GetStrOffsetsBase () + index * m_str_offset_size ;
10901097 return m_dwarf.GetDWARFContext ().getOrLoadStrOffsetsData ().GetMaxU64 (
1091- &offset, m_str_offsets_size );
1098+ &offset, m_str_offset_size );
10921099}
10931100
10941101llvm::Expected<llvm::DWARFAddressRangesVector>
0 commit comments