Skip to content

Commit cd18c9c

Browse files
committed
Fix unit test failure and refactored a bit.
1 parent a112bb1 commit cd18c9c

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ void DWARFUnit::ExtractDIEsRWLocked() {
348348
void 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

10871094
std::optional<uint64_t>
10881095
DWARFUnit::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

10941101
llvm::Expected<llvm::DWARFAddressRangesVector>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class DWARFUnit : public DWARFExpression::Delegate, public UserID {
364364
dw_offset_t m_line_table_offset = DW_INVALID_OFFSET;
365365

366366
dw_offset_t m_str_offsets_base = 0; // Value of DW_AT_str_offsets_base.
367-
dw_offset_t m_str_offsets_size = 4; // Size in bytes of the string offsets.
367+
dw_offset_t m_str_offset_size = 4; // Size in bytes of a string offset.
368368

369369
std::optional<llvm::DWARFDebugRnglistTable> m_rnglist_table;
370370
bool m_rnglist_table_done = false;

0 commit comments

Comments
 (0)