From 02e103c63fb58b9a24ff8d9d4984ac0b5b75cdc8 Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Mon, 10 Jul 2023 13:37:01 -0400 Subject: Dwarf import : Resolve multiple data variable definitions for the same location; Resolves Vector35/dwarf_import#19 --- .../examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'rust/examples') diff --git a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs index 0cb9ede2..2403c879 100644 --- a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs +++ b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs @@ -23,6 +23,7 @@ use binaryninja::{ use gimli::{DebuggingInformationEntry, Reader, Unit}; +use log::error; use std::{ collections::{hash_map::Values, HashMap}, ffi::CString, @@ -163,10 +164,20 @@ impl DebugInfoBuilder { } pub fn add_data_variable(&mut self, address: u64, name: Option, type_uid: TypeUID) { - assert!(self - .data_variables - .insert(address, (name, type_uid)) - .is_none()); + if let Some((_existing_name, existing_type_uid)) = + self.data_variables.insert(address, (name, type_uid)) + { + let existing_type = self.get_type(existing_type_uid).unwrap().1; + let new_type = self.get_type(type_uid).unwrap().1; + + if existing_type_uid != type_uid || existing_type != new_type { + error!("DWARF info contains duplicate data variable definition. Overwriting data variable at 0x{:08x} (`{}`) with `{}`", + address, + self.get_type(existing_type_uid).unwrap().1, + self.get_type(type_uid).unwrap().1 + ); + } + } } pub fn set_name(&mut self, die_uid: TypeUID, name: CString) { -- cgit v1.3.1