Skip to content

Commit

Permalink
fix(debuginfo): Calculate line record sizes for DWARF (#220)
Browse files Browse the repository at this point in the history
Calculates line record sizes for DWARF by comparing with the previous
row emitted from the line number program. Additionally, the sequence end
point is used to calculate the length for the last row/record.
  • Loading branch information
jan-auer authored Apr 20, 2020
1 parent 9130d84 commit 2c4e532
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 9 additions & 3 deletions debuginfo/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,15 @@ pub struct LineInfo<'data> {

impl fmt::Debug for LineInfo<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("LineInfo")
.field("address", &format_args!("{:#x}", self.address))
.field("file", &self.file)
let mut s = f.debug_struct("LineInfo");
s.field("address", &format_args!("{:#x}", self.address));

match self.size {
Some(size) => s.field("size", &format_args!("{:#x}", size)),
None => s.field("size", &self.size),
};

s.field("file", &self.file)
.field("line", &self.line)
.finish()
}
Expand Down
11 changes: 10 additions & 1 deletion debuginfo/src/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ struct DwarfRow {
address: u64,
file_index: u64,
line: Option<u64>,
size: Option<u64>,
}

/// A sequence in the DWARF line program.
Expand All @@ -202,6 +203,13 @@ impl<'d, 'a> DwarfLineProgram<'d> {

while let Ok(Some((_, &program_row))) = state_machine.next_row() {
let address = program_row.address();

if let Some(last_row) = sequence_rows.last_mut() {
if address >= last_row.address {
last_row.size = Some(address - last_row.address);
}
}

if program_row.end_sequence() {
// Theoretically, there could be multiple DW_LNE_end_sequence in a row. We're not
// interested in empty sequences, so we can skip them completely.
Expand Down Expand Up @@ -242,6 +250,7 @@ impl<'d, 'a> DwarfLineProgram<'d> {
address,
file_index,
line,
size: None,
});
}
prev_address = address;
Expand Down Expand Up @@ -557,7 +566,7 @@ impl<'d, 'a> DwarfUnit<'d, 'a> {
last = Some((row.file_index, line));
lines.push(LineInfo {
address: row.address - self.inner.info.load_address,
size: None,
size: row.size,
file,
line,
});
Expand Down

0 comments on commit 2c4e532

Please sign in to comment.