diff options
| author | Mason Reed <mason@vector35.com> | 2025-01-27 19:06:18 -0500 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-01-27 19:07:19 -0500 |
| commit | b3f2ef82dd8fdc20887c09532c328356cf3552b6 (patch) | |
| tree | 35d33f72d16f5ec8f084b1785dd399c2a5cdd7a0 /rust | |
| parent | 4551d1f3f4c99d72437d5908fe2aaa0ac850bb1f (diff) | |
Update some rust impl Debug
If a function had a tag it would recurse cyclicly
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/src/architecture.rs | 16 | ||||
| -rw-r--r-- | rust/src/collaboration/remote.rs | 4 | ||||
| -rw-r--r-- | rust/src/function.rs | 2 | ||||
| -rw-r--r-- | rust/src/platform.rs | 2 | ||||
| -rw-r--r-- | rust/src/symbol.rs | 21 | ||||
| -rw-r--r-- | rust/src/tags.rs | 13 | ||||
| -rw-r--r-- | rust/tests/binary_view.rs | 2 | ||||
| -rw-r--r-- | rust/tests/collaboration.rs | 2 |
8 files changed, 45 insertions, 17 deletions
diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs index 09808b39..857a6e88 100644 --- a/rust/src/architecture.rs +++ b/rust/src/architecture.rs @@ -1377,7 +1377,7 @@ impl Drop for CoreArchitectureList { } } -#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[derive(Copy, Clone, Eq, PartialEq, Hash)] pub struct CoreArchitecture { pub(crate) handle: *mut BNArchitecture, } @@ -1895,6 +1895,20 @@ impl Architecture for CoreArchitecture { } } +impl Debug for CoreArchitecture { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.debug_struct("CoreArchitecture") + .field("name", &self.name()) + .field("endianness", &self.endianness()) + .field("address_size", &self.address_size()) + .field("default_integer_size", &self.default_integer_size()) + .field("instruction_alignment", &self.instruction_alignment()) + .field("max_instr_len", &self.max_instr_len()) + .field("opcode_display_len", &self.opcode_display_len()) + .finish() + } +} + macro_rules! cc_func { ($get_name:ident, $get_api:ident, $set_name:ident, $set_api:ident) => { fn $get_name(&self) -> Option<Ref<CoreCallingConvention>> { diff --git a/rust/src/collaboration/remote.rs b/rust/src/collaboration/remote.rs index 21f148e9..c1250403 100644 --- a/rust/src/collaboration/remote.rs +++ b/rust/src/collaboration/remote.rs @@ -192,7 +192,7 @@ impl Remote { /// Connects to the Remote, loading metadata and optionally acquiring a token. /// /// Use [Remote::connect_with_opts] if you cannot otherwise automatically connect using enterprise. - /// + /// /// WARNING: This is currently **not** thread safe, if you try and connect/disconnect to a remote on /// multiple threads you will be subject to race conditions. To avoid this wrap the [`Remote`] in /// a synchronization primitive, and pass that to your threads. Or don't try and connect on multiple threads. @@ -238,7 +238,7 @@ impl Remote { } /// Disconnects from the remote. - /// + /// /// WARNING: This is currently **not** thread safe, if you try and connect/disconnect to a remote on /// multiple threads you will be subject to race conditions. To avoid this wrap the [`Remote`] in /// a synchronization primitive, and pass that to your threads. Or don't try and connect on multiple threads. diff --git a/rust/src/function.rs b/rust/src/function.rs index b524edfb..d4eb1d53 100644 --- a/rust/src/function.rs +++ b/rust/src/function.rs @@ -2375,7 +2375,7 @@ impl Debug for Function { // TODO: I am sure there is more we should add to this. f.debug_struct("Function") .field("start", &self.start()) - .field("arch", &self.arch()) + .field("arch", &self.arch().name()) .field("platform", &self.platform()) .field("symbol", &self.symbol()) .field("is_auto", &self.is_auto()) diff --git a/rust/src/platform.rs b/rust/src/platform.rs index e732152c..cdbaf25d 100644 --- a/rust/src/platform.rs +++ b/rust/src/platform.rs @@ -399,7 +399,7 @@ impl Debug for Platform { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Platform") .field("name", &self.name()) - .field("arch", &self.arch()) + .field("arch", &self.arch().name()) .finish() } } diff --git a/rust/src/symbol.rs b/rust/src/symbol.rs index 21df31a7..9c29af17 100644 --- a/rust/src/symbol.rs +++ b/rust/src/symbol.rs @@ -15,6 +15,7 @@ //! Interfaces for the various kinds of symbols in a binary. use std::fmt; +use std::fmt::Debug; use std::hash::{Hash, Hasher}; use std::ptr; @@ -286,16 +287,18 @@ impl Symbol { unsafe impl Send for Symbol {} unsafe impl Sync for Symbol {} -impl fmt::Debug for Symbol { +impl Debug for Symbol { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "<sym {:?} '{}' @ {:x} (handle: {:?})>", - self.sym_type(), - self.full_name(), - self.address(), - self.handle - ) + f.debug_struct("Symbol") + .field("type", &self.sym_type()) + .field("binding", &self.binding()) + .field("full_name", &self.full_name()) + .field("short_name", &self.short_name()) + .field("raw_name", &self.raw_name()) + .field("address", &self.address()) + .field("auto_defined", &self.auto_defined()) + .field("external", &self.external()) + .finish() } } diff --git a/rust/src/tags.rs b/rust/src/tags.rs index b378f7ed..3fc50676 100644 --- a/rust/src/tags.rs +++ b/rust/src/tags.rs @@ -230,7 +230,7 @@ impl ToOwned for TagType { unsafe impl Send for TagType {} unsafe impl Sync for TagType {} -#[derive(Debug, Clone, PartialEq)] +#[derive(Clone, PartialEq)] pub struct TagReference { pub arch: CoreArchitecture, pub func: Ref<Function>, @@ -253,6 +253,17 @@ impl From<&BNTagReference> for TagReference { } } +impl Debug for TagReference { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.debug_struct("TagReference") + .field("addr", &self.addr) + .field("auto_defined", &self.auto_defined) + .field("reference_type", &self.reference_type) + .field("tag", &self.tag) + .finish() + } +} + impl CoreArrayProvider for TagReference { type Raw = BNTagReference; type Context = (); diff --git a/rust/tests/binary_view.rs b/rust/tests/binary_view.rs index 0ee10d87..6cb617c2 100644 --- a/rust/tests/binary_view.rs +++ b/rust/tests/binary_view.rs @@ -1,9 +1,9 @@ use binaryninja::binary_view::{AnalysisState, BinaryViewBase, BinaryViewExt}; use binaryninja::headless::Session; +use binaryninja::main_thread::execute_on_main_thread_and_wait; use binaryninja::symbol::{SymbolBuilder, SymbolType}; use rstest::*; use std::path::PathBuf; -use binaryninja::main_thread::execute_on_main_thread_and_wait; #[fixture] #[once] diff --git a/rust/tests/collaboration.rs b/rust/tests/collaboration.rs index a8c0d52c..19044a82 100644 --- a/rust/tests/collaboration.rs +++ b/rust/tests/collaboration.rs @@ -5,8 +5,8 @@ use binaryninja::collaboration::{ use binaryninja::headless::Session; use binaryninja::symbol::{SymbolBuilder, SymbolType}; use rstest::*; -use std::path::PathBuf; use serial_test::serial; +use std::path::PathBuf; #[fixture] #[once] |
