From 29bf331ec1c142de30cf9f4f277d9e121b1cd96a Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Thu, 10 Jul 2025 10:35:37 -0400 Subject: Improve DWARF local variable recovery --- plugins/dwarf/dwarf_import/src/functions.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'plugins/dwarf/dwarf_import/src/functions.rs') diff --git a/plugins/dwarf/dwarf_import/src/functions.rs b/plugins/dwarf/dwarf_import/src/functions.rs index 6277c6b5..49e16274 100644 --- a/plugins/dwarf/dwarf_import/src/functions.rs +++ b/plugins/dwarf/dwarf_import/src/functions.rs @@ -24,6 +24,12 @@ use gimli::{constants, AttributeValue, DebuggingInformationEntry, Dwarf, Operati use log::{debug, error}; use regex::Regex; +#[derive(PartialEq, Eq, Hash)] +pub enum FrameBase { + Register(gimli::Register), + CFA, +} + fn get_parameters( dwarf: &Dwarf, unit: &Unit, @@ -65,7 +71,7 @@ fn get_parameters( } else { result.push(None) } - } + }, constants::DW_TAG_unspecified_parameters => variable_arguments = true, _ => (), } @@ -136,17 +142,17 @@ pub(crate) fn parse_function_entry( return None; } - let use_cfa; + let frame_base; if let Ok(Some(AttributeValue::Exprloc(mut expression))) = entry.attr_value(constants::DW_AT_frame_base) { - use_cfa = match Operation::parse(&mut expression.0, unit.encoding()) { - Ok(Operation::Register { register: _ }) => false, // TODO: handle register-relative encodings later - Ok(Operation::CallFrameCFA) => true, - _ => false, + frame_base = match Operation::parse(&mut expression.0, unit.encoding()) { + Ok(Operation::Register { register: reg }) => Some(FrameBase::Register(reg)), + Ok(Operation::CallFrameCFA) => Some(FrameBase::CFA), + _ => None, // TODO: warn? }; } else { - use_cfa = false; + frame_base = None; } debug_info_builder.insert_function( @@ -156,7 +162,7 @@ pub(crate) fn parse_function_entry( address, ¶meters, variable_arguments, - use_cfa, + frame_base, ) } -- cgit v1.3.1