Skip to content

Commit 4cfe5b8

Browse files
committed
The .dwarf_str_offsets table has a DWARF header in DWARF5.
... so parse it out to find where the offsets themselves start (and to deal with 8-byte indexes, should they ever present themselves.)
1 parent 07435a1 commit 4cfe5b8

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

dwarf_unit.cc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,24 @@ Unit::strx(size_t idx) {
2121
throw Exception() << "no string offsets table, but have strx form";
2222
// Get the root die, and the string offset base.
2323
auto base = intmax_t(root().attribute(DW_AT_str_offsets_base));
24-
auto len = dwarfLen;
25-
DWARFReader r(dwarf->debugStrOffsets.io(), base + len * idx);
26-
return dwarf->debugStrings.io()->readString(r.getuint(len));
24+
size_t seclen, entrysize;
25+
Elf::Off tableStart;
26+
27+
if (version >= 5) {
28+
DWARFReader r(dwarf->debugStrOffsets.io());
29+
// Version 5 has a header
30+
std::tie( seclen, entrysize ) = r.getlength();
31+
[[maybe_unused]] auto version = r.getu16();
32+
[[maybe_unused]] auto padding = r.getu16();
33+
tableStart = r.getOffset();
34+
} else {
35+
// Old versions of this table just had 4-byte string offsets, I think.
36+
seclen = std::numeric_limits<Elf::Off>::max();
37+
entrysize = 4;
38+
tableStart = 0;
39+
}
40+
DWARFReader r(dwarf->debugStrOffsets.io(), tableStart + base + entrysize * idx);
41+
return dwarf->debugStrings.io()->readString(r.getuint(entrysize));
2742
}
2843

2944
uintmax_t

0 commit comments

Comments
 (0)