diff --git a/src/main.rs b/src/main.rs index f911a380f77aa2a6cc580a708181fed69f0cf488..79354139e66dd176a66bb5e891b4f6bb667d2b97 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ // Based on the gimli 0.16.1 dwarfdump.rs example use anyhow::{anyhow, Error, Result}; use fallible_iterator::{convert, FallibleIterator}; -use gimli::{Endianity, Reader}; +use gimli::{AttributeValue, Endianity, Reader}; use object::Object; use serde::ser::SerializeMap; use serde::{Serialize, Serializer}; @@ -81,17 +81,29 @@ fn list_entries<R: Reader>( .map::<Result<String>, _>(|s| Ok(s.to_string()?.into_owned())) .transpose()? .ok_or_else(|| anyhow!("Missing DW_AT_comp_dir"))?; - let comp_name = entry + + let at_name = entry .attr(gimli::DW_AT_name)? - .and_then(|attr| attr.string_value(debug_str)) - .map::<Result<String>, _>(|s| Ok(s.to_string()?.into_owned())) - .transpose()? .ok_or_else(|| anyhow!("Missing DW_AT_name"))?; - v.push(Unit { - comp_dir, - comp_name, - }); + if let Some(r) = at_name.string_value(debug_str) { + let comp_name = r.to_string()?; + if comp_name == "<artificial>" { + eprintln!("Warning: Artificial name in compile unit, probably DWARF debug information has been generated with LTO") + } else { + v.push(Unit { + comp_dir, + comp_name: comp_name.into_owned(), + }); + } + } else { + match at_name.raw_value() { + AttributeValue::DebugStrRefSup(_) => { + eprintln!("Warning: compilation unit name in supplemental file") + } + _ => eprintln!("Warning: compilation unit has unexpected name type"), + } + } } } Ok(v)