diff --git a/debuginfo/src/base.rs b/debuginfo/src/base.rs index 096d02da7..bccbeba43 100644 --- a/debuginfo/src/base.rs +++ b/debuginfo/src/base.rs @@ -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() } diff --git a/debuginfo/src/dwarf.rs b/debuginfo/src/dwarf.rs index 7178c1ef8..465b2d37f 100644 --- a/debuginfo/src/dwarf.rs +++ b/debuginfo/src/dwarf.rs @@ -176,6 +176,7 @@ struct DwarfRow { address: u64, file_index: u64, line: Option, + size: Option, } /// A sequence in the DWARF line program. @@ -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. @@ -242,6 +250,7 @@ impl<'d, 'a> DwarfLineProgram<'d> { address, file_index, line, + size: None, }); } prev_address = address; @@ -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, });