Skip to content

Commit

Permalink
Update some rust impl Debug
Browse files Browse the repository at this point in the history
If a function had a tag it would recurse cyclicly
  • Loading branch information
emesare committed Jan 28, 2025
1 parent 4551d1f commit b3f2ef8
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 17 deletions.
16 changes: 15 additions & 1 deletion rust/src/architecture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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>> {
Expand Down
4 changes: 2 additions & 2 deletions rust/src/collaboration/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rust/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion rust/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
21 changes: 12 additions & 9 deletions rust/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
}
}

Expand Down
13 changes: 12 additions & 1 deletion rust/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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 = ();
Expand Down
2 changes: 1 addition & 1 deletion rust/tests/binary_view.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion rust/tests/collaboration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit b3f2ef8

Please sign in to comment.