summaryrefslogtreecommitdiff
path: root/plugins/dwarf
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-11-16 20:22:37 -0500
committerMason Reed <mason@vector35.com>2025-11-16 20:22:37 -0500
commit33d04c64f4dd6577345dac14b564539ca37b3fee (patch)
tree52f4ac96cbf0a784b76104ad71724f95d22ae43f /plugins/dwarf
parent96bf5db56b14ed95e265aa02cc496a9e52d5172d (diff)
[DWARF] Fix crash in dwarf export with detached NTR vtable data variable
Fixes https://github.com/Vector35/binaryninja-api/issues/7646 Also cleaned up and added some more context to the `NamedTypeReference::target` function.
Diffstat (limited to 'plugins/dwarf')
-rw-r--r--plugins/dwarf/dwarf_export/src/lib.rs53
1 files changed, 31 insertions, 22 deletions
diff --git a/plugins/dwarf/dwarf_export/src/lib.rs b/plugins/dwarf/dwarf_export/src/lib.rs
index d1ac45ab..333ce83b 100644
--- a/plugins/dwarf/dwarf_export/src/lib.rs
+++ b/plugins/dwarf/dwarf_export/src/lib.rs
@@ -17,7 +17,7 @@ use gimli::{
UnitEntryId,
},
};
-use log::{error, info, LevelFilter};
+use log::{error, info, warn, LevelFilter};
use object::{write, Architecture, BinaryFormat, SectionKind};
use std::fs;
use std::path::{Path, PathBuf};
@@ -123,26 +123,35 @@ fn export_type(
for base_struct in ty_struct.base_structures() {
let inheritance_uid = dwarf.unit.add(structure_die_uid, gimli::DW_TAG_inheritance);
- let base_struct_uid = export_type(
- base_struct.ty.name().to_string(),
- base_struct.ty.target(bv).unwrap().as_ref(),
- bv,
- defined_types,
- dwarf,
- )
- .unwrap();
- dwarf
- .unit
- .get_mut(inheritance_uid)
- .set(gimli::DW_AT_type, AttributeValue::UnitRef(base_struct_uid));
- dwarf.unit.get_mut(inheritance_uid).set(
- gimli::DW_AT_data_member_location,
- AttributeValue::Data8(base_struct.offset),
- );
- dwarf.unit.get_mut(inheritance_uid).set(
- gimli::DW_AT_accessibility,
- AttributeValue::Accessibility(gimli::DW_ACCESS_public),
- );
+ if let Some(target_ty) = base_struct.ty.target(bv) {
+ let base_struct_uid = export_type(
+ base_struct.ty.name().to_string(),
+ &target_ty,
+ bv,
+ defined_types,
+ dwarf,
+ );
+
+ match base_struct_uid {
+ Some(uid) => {
+ dwarf
+ .unit
+ .get_mut(inheritance_uid)
+ .set(gimli::DW_AT_type, AttributeValue::UnitRef(uid));
+ dwarf.unit.get_mut(inheritance_uid).set(
+ gimli::DW_AT_data_member_location,
+ AttributeValue::Data8(base_struct.offset),
+ );
+ dwarf.unit.get_mut(inheritance_uid).set(
+ gimli::DW_AT_accessibility,
+ AttributeValue::Accessibility(gimli::DW_ACCESS_public),
+ );
+ }
+ None => {
+ log::warn!("Could not export base struct `{}`", base_struct.ty.name());
+ }
+ }
+ }
}
dwarf.unit.get_mut(structure_die_uid).set(
@@ -365,7 +374,7 @@ fn export_type(
Some(typedef_die_uid)
}
} else {
- error!("Could not get target of typedef `{}`", ntr.name());
+ warn!("Could not get target of typedef `{}`", ntr.name());
None
}
}