diff options
| author | Josh Ferrell <josh@vector35.com> | 2024-07-05 12:15:21 -0400 |
|---|---|---|
| committer | Josh Ferrell <josh@vector35.com> | 2024-07-05 12:20:33 -0400 |
| commit | 0dc909f1800296619053e067a1e3700665f4644c (patch) | |
| tree | 5851a0791c03e7e5fce55f8ba6da3910f0e6e988 /rust/examples | |
| parent | 98db31c6f2442aac6b3d6687e0200fa61acc8d3b (diff) | |
Fix crash when parsing enums from zig dwarf info
Diffstat (limited to 'rust/examples')
| -rw-r--r-- | rust/examples/dwarf/dwarf_import/src/die_handlers.rs | 21 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarf_import/src/helpers.rs | 18 |
2 files changed, 23 insertions, 16 deletions
diff --git a/rust/examples/dwarf/dwarf_import/src/die_handlers.rs b/rust/examples/dwarf/dwarf_import/src/die_handlers.rs index 24ef30fb..e6530dd2 100644 --- a/rust/examples/dwarf/dwarf_import/src/die_handlers.rs +++ b/rust/examples/dwarf/dwarf_import/src/die_handlers.rs @@ -108,16 +108,17 @@ pub(crate) fn handle_enum<R: Reader<Offset = usize>>( while let Ok(Some(child)) = children.next() { if child.entry().tag() == constants::DW_TAG_enumerator { let name = debug_info_builder_context.get_name(unit, child.entry())?; - let value = get_attr_as_u64( - &child - .entry() - .attr(constants::DW_AT_const_value) - .unwrap() - .unwrap(), - ) - .unwrap(); - - enumeration_builder.insert(name, value); + let attr = &child + .entry() + .attr(constants::DW_AT_const_value) + .unwrap() + .unwrap(); + if let Some(value) = get_attr_as_u64(attr) { + enumeration_builder.insert(name, value); + } else { + log::error!("Unhandled enum member value type - please report this"); + return None; + } } } diff --git a/rust/examples/dwarf/dwarf_import/src/helpers.rs b/rust/examples/dwarf/dwarf_import/src/helpers.rs index 14de90bf..09465d82 100644 --- a/rust/examples/dwarf/dwarf_import/src/helpers.rs +++ b/rust/examples/dwarf/dwarf_import/src/helpers.rs @@ -260,14 +260,20 @@ pub(crate) fn get_start_address<R: Reader<Offset = usize>>( // Get an attribute value as a u64 if it can be coerced pub(crate) fn get_attr_as_u64<R: Reader<Offset = usize>>(attr: &Attribute<R>) -> Option<u64> { - if let Some(value) = attr.u8_value() { - Some(value.into()) - } else if let Some(value) = attr.u16_value() { - Some(value.into()) - } else if let Some(value) = attr.udata_value() { + if let Some(value) = attr.udata_value() { Some(value) + } else if let Some(value) = attr.sdata_value() { + Some(value as u64) + } else if let Some(mut expr) = attr.exprloc_value() { + match expr.0.len() { + 1 => expr.0.read_u8().map(u64::from).ok(), + 2 => expr.0.read_u16().map(u64::from).ok(), + 4 => expr.0.read_u32().map(u64::from).ok(), + 8 => expr.0.read_u64().ok(), + _ => None + } } else { - attr.sdata_value().map(|value| value as u64) + None } } |
