Skip to content

Commit

Permalink
fix #61: implement DWARF4 line number headers
Browse files Browse the repository at this point in the history
  • Loading branch information
rainers committed May 8, 2020
1 parent e41e365 commit 4d80def
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/dwarflines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,35 @@ bool interpretDWARFLines(const PEImage& img, mspdb::Mod* mod)
DWARF_CompilationUnit* cu = (DWARF_CompilationUnit*)img.debug_info;
int ptrsize = cu ? cu->address_size : 4;

DWARF_LineNumberProgramHeader hdr3;
for(unsigned long off = 0; off < img.debug_line_length; )
{
DWARF_LineNumberProgramHeader* hdr = (DWARF_LineNumberProgramHeader*) (img.debug_line + off);
int length = hdr->unit_length;
DWARF_LineNumberProgramHeader* hdrver = (DWARF_LineNumberProgramHeader*) (img.debug_line + off);
int length = hdrver->unit_length;
if(length < 0)
break;
length += sizeof(length);

unsigned char* p = (unsigned char*) (hdr + 1);
unsigned char* end = (unsigned char*) hdr + length;
DWARF_LineNumberProgramHeader* hdr;
if (hdrver->version <= 3)
{
auto hdr2 = (DWARF2_LineNumberProgramHeader*)hdrver;
hdr3.default_is_stmt = hdr2->default_is_stmt;
hdr3.header_length = hdr2->header_length;
hdr3.line_base = hdr2->line_base;
hdr3.line_range = hdr2->line_range;
hdr3.minimum_instruction_length = hdr2->minimum_instruction_length;
hdr3.maximum_operations_per_instruction = 0xff;
hdr3.opcode_base = hdr2->opcode_base;
hdr3.unit_length = hdr2->unit_length;
hdr3.version = hdr2->version;
hdr = &hdr3;
}
else
hdr = hdrver;
int hdrlength = hdr->version <= 3 ? sizeof(DWARF2_LineNumberProgramHeader) : sizeof(DWARF_LineNumberProgramHeader);
unsigned char* p = (unsigned char*) hdrver + hdrlength;
unsigned char* end = (unsigned char*) hdrver + length;

std::vector<unsigned int> opcode_lengths;
opcode_lengths.resize(hdr->opcode_base);
Expand Down
16 changes: 16 additions & 0 deletions src/readDwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,22 @@ struct DWARF_InfoData
static const int maximum_operations_per_instruction = 1;

struct DWARF_LineNumberProgramHeader
{
unsigned int unit_length; // 12 byte in DWARF-64
unsigned short version;
unsigned int header_length; // 8 byte in DWARF-64
byte minimum_instruction_length;
byte maximum_operations_per_instruction; // not in DWARF 2/3
byte default_is_stmt;
signed char line_base;
byte line_range;
byte opcode_base;
//LEB128 standard_opcode_lengths[opcode_base];
// string include_directories[] // zero byte terminated
// DWARF_FileNames file_names[] // zero byte terminated
};

struct DWARF2_LineNumberProgramHeader
{
unsigned int unit_length; // 12 byte in DWARF-64
unsigned short version;
Expand Down

0 comments on commit 4d80def

Please sign in to comment.