Skip to content

Commit

Permalink
Updated with patches from antoyo and suggested changes from aclements. (
Browse files Browse the repository at this point in the history
#79)

Add basic support for DWARF v5

Also fixes a few other minor issues.

Co-authored-by: Noah Lev <camelidcamel@gmail.com>
  • Loading branch information
emeryberger and camelid committed Mar 11, 2024
1 parent 946dde5 commit e017276
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions dwarf/cursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ cursor::skip_initial_length()
}
}

void
cursor::skip_unit_type()
{
pos += sizeof(sbyte);
}

section_offset
cursor::offset()
{
Expand Down
19 changes: 15 additions & 4 deletions dwarf/dwarf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,23 @@ compilation_unit::compilation_unit(const dwarf &file, section_offset offset)
cursor sub(subsec);
sub.skip_initial_length();
uhalf version = sub.fixed<uhalf>();
if (version < 2 || version > 4)
(void)version;
if (version > 5)
throw format_error("unknown compilation unit version " + std::to_string(version));
// .debug_abbrev-relative offset of this unit's abbrevs
section_offset debug_abbrev_offset = sub.offset();
ubyte address_size = sub.fixed<ubyte>();
subsec->addr_size = address_size;
section_offset debug_abbrev_offset;
if(version >= 5)
{
sub.skip_unit_type();
ubyte address_size = sub.fixed<ubyte>();
subsec->addr_size = address_size;
debug_abbrev_offset = sub.offset();
}
else {
debug_abbrev_offset = sub.offset();
ubyte address_size = sub.fixed<ubyte>();
subsec->addr_size = address_size;
}

m = make_shared<impl>(file, offset, subsec, debug_abbrev_offset,
sub.get_section_offset());
Expand Down
1 change: 1 addition & 0 deletions dwarf/internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ struct cursor
}

void skip_initial_length();
void skip_unit_type();
void skip_form(DW_FORM form);

cursor &operator+=(section_offset offset)
Expand Down
2 changes: 1 addition & 1 deletion dwarf/line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ line_table::line_table(const shared_ptr<section> &sec, section_offset offset,
m->program_offset = cur.get_section_offset() + header_length;
m->minimum_instruction_length = cur.fixed<ubyte>();
m->maximum_operations_per_instruction = 1;
if (version == 4)
if (version >= 4)
m->maximum_operations_per_instruction = cur.fixed<ubyte>();
if (m->maximum_operations_per_instruction == 0)
throw format_error("maximum_operations_per_instruction cannot"
Expand Down
2 changes: 1 addition & 1 deletion elf/data.hh
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ struct Sym<Elf64, Order>
return (stb)(info >> 4);
}

void set_binding(stb v) const
void set_binding(stb v)
{
info = (info & 0xF) | ((unsigned char)v << 4);
}
Expand Down

1 comment on commit e017276

@anatol
Copy link

@anatol anatol commented on e017276 Jun 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe time for a new tag?

Please sign in to comment.