From 0dc909f1800296619053e067a1e3700665f4644c Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Fri, 5 Jul 2024 12:15:21 -0400 Subject: Fix crash when parsing enums from zig dwarf info --- rust/examples/dwarf/dwarf_import/src/helpers.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'rust/examples/dwarf/dwarf_import/src/helpers.rs') 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>( // Get an attribute value as a u64 if it can be coerced pub(crate) fn get_attr_as_u64>(attr: &Attribute) -> Option { - 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 } } -- cgit v1.3.1