From 316c6c2e23ce3b4b95ed379e08b0edad9ec39037 Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Wed, 10 Nov 2021 12:22:21 +1000 Subject: [PATCH] dwarfdump: improve handling of file index 0 - display the file path if the first `DW_LNS_set_file` uses index 0 - display the file path if `DW_AT_decl_file` uses index 0 for DWARF 5 - don't duplicate the compilation dir for index 0 --- examples/dwarfdump.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/dwarfdump.rs b/examples/dwarfdump.rs index 64b23330..a3c4e258 100644 --- a/examples/dwarfdump.rs +++ b/examples/dwarfdump.rs @@ -1585,21 +1585,21 @@ fn dump_type_signature(w: &mut W, signature: gimli::DebugTypeSignature fn dump_file_index( w: &mut W, - file: u64, + file_index: u64, unit: &gimli::Unit, dwarf: &gimli::Dwarf, ) -> Result<()> { - if file == 0 { + if file_index == 0 && unit.header.version() <= 4 { return Ok(()); } let header = match unit.line_program { Some(ref program) => program.header(), None => return Ok(()), }; - let file = match header.file(file) { - Some(header) => header, + let file = match header.file(file_index) { + Some(file) => file, None => { - writeln!(w, "Unable to get header for file {}", file)?; + writeln!(w, "Unable to get header for file {}", file_index)?; return Ok(()); } }; @@ -1607,7 +1607,7 @@ fn dump_file_index( if let Some(directory) = file.directory(header) { let directory = dwarf.attr_string(unit, directory)?; let directory = directory.to_string_lossy()?; - if !directory.starts_with('/') { + if file_index != 0 && !directory.starts_with('/') { if let Some(ref comp_dir) = unit.comp_dir { write!(w, "{}/", comp_dir.to_string_lossy()?,)?; } @@ -2238,7 +2238,7 @@ fn dump_line_program( writeln!(w, " [lno,col]")?; } let mut rows = program.rows(); - let mut file_index = 0; + let mut file_index = u64::MAX; while let Some((header, row)) = rows.next_row()? { let line = match row.line() { Some(line) => line.get(),