summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2022-07-19 18:27:50 -0400
committerGlenn Smith <glenn@vector35.com>2022-09-29 21:02:24 -0400
commit0725c6fbd58b3d40ffefdb319121a29ba4168517 (patch)
tree43321b54b45dd16154bc104886b5e3ef08017b75 /rust/src
parent460656be13999759eb1eeb5bd9a868b34c0aea22 (diff)
Make DebugInfo::parse failable
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/debuginfo.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs
index 08453b2d..7ce2c485 100644
--- a/rust/src/debuginfo.rs
+++ b/rust/src/debuginfo.rs
@@ -136,19 +136,17 @@ impl DebugInfoParser {
&self,
view: &BinaryView,
existing_debug_info: Option<&DebugInfo>,
- ) -> Ref<DebugInfo> {
- match existing_debug_info {
+ ) -> Option<Ref<DebugInfo>> {
+ let info: *mut BNDebugInfo = match existing_debug_info {
Some(debug_info) => unsafe {
- DebugInfo::from_raw(BNParseDebugInfo(
- self.handle,
- view.handle,
- debug_info.handle,
- ))
- },
- None => unsafe {
- DebugInfo::from_raw(BNParseDebugInfo(self.handle, view.handle, ptr::null_mut()))
+ BNParseDebugInfo(self.handle, view.handle, debug_info.handle)
},
+ None => unsafe { BNParseDebugInfo(self.handle, view.handle, ptr::null_mut()) },
+ };
+ if info.is_null() {
+ return None;
}
+ return Some(unsafe { DebugInfo::from_raw(info) });
}
// Registers a DebugInfoParser. See `binaryninja::debuginfo::DebugInfoParser` for more details.
@@ -173,7 +171,8 @@ impl DebugInfoParser {
ctxt: *mut c_void,
debug_info: *mut BNDebugInfo,
view: *mut BNBinaryView,
- ) where
+ ) -> bool
+ where
C: CustomDebugInfoParser,
{
ffi_wrap!("CustomDebugInfoParser::parse_info", unsafe {
@@ -181,7 +180,7 @@ impl DebugInfoParser {
let view = BinaryView::from_raw(view);
let mut debug_info = DebugInfo::from_raw(debug_info);
- cmd.parse_info(&mut debug_info, &view);
+ cmd.parse_info(&mut debug_info, &view)
})
}
@@ -868,5 +867,5 @@ impl ToOwned for DebugInfo {
/// Implement this trait to implement a debug info parser. See `DebugInfoParser` for more details.
pub trait CustomDebugInfoParser: 'static + Sync {
fn is_valid(&self, view: &BinaryView) -> bool;
- fn parse_info(&self, debug_info: &mut DebugInfo, view: &BinaryView);
+ fn parse_info(&self, debug_info: &mut DebugInfo, view: &BinaryView) -> bool;
}