Skip to content

Commit

Permalink
dwarfdump: improve handling of file index 0
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
philipc committed Nov 10, 2021
1 parent fdd7ee4 commit 316c6c2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions examples/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1585,29 +1585,29 @@ fn dump_type_signature<W: Write>(w: &mut W, signature: gimli::DebugTypeSignature

fn dump_file_index<R: Reader, W: Write>(
w: &mut W,
file: u64,
file_index: u64,
unit: &gimli::Unit<R>,
dwarf: &gimli::Dwarf<R>,
) -> 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(());
}
};
write!(w, " ")?;
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()?,)?;
}
Expand Down Expand Up @@ -2238,7 +2238,7 @@ fn dump_line_program<R: Reader, W: Write>(
writeln!(w, "<pc> [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(),
Expand Down

0 comments on commit 316c6c2

Please sign in to comment.