Skip to content

Commit b3f2ef8

Browse files
committed
Update some rust impl Debug
If a function had a tag it would recurse cyclicly
1 parent 4551d1f commit b3f2ef8

File tree

8 files changed

+45
-17
lines changed

8 files changed

+45
-17
lines changed

rust/src/architecture.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ impl Drop for CoreArchitectureList {
13771377
}
13781378
}
13791379

1380-
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1380+
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
13811381
pub struct CoreArchitecture {
13821382
pub(crate) handle: *mut BNArchitecture,
13831383
}
@@ -1895,6 +1895,20 @@ impl Architecture for CoreArchitecture {
18951895
}
18961896
}
18971897

1898+
impl Debug for CoreArchitecture {
1899+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1900+
f.debug_struct("CoreArchitecture")
1901+
.field("name", &self.name())
1902+
.field("endianness", &self.endianness())
1903+
.field("address_size", &self.address_size())
1904+
.field("default_integer_size", &self.default_integer_size())
1905+
.field("instruction_alignment", &self.instruction_alignment())
1906+
.field("max_instr_len", &self.max_instr_len())
1907+
.field("opcode_display_len", &self.opcode_display_len())
1908+
.finish()
1909+
}
1910+
}
1911+
18981912
macro_rules! cc_func {
18991913
($get_name:ident, $get_api:ident, $set_name:ident, $set_api:ident) => {
19001914
fn $get_name(&self) -> Option<Ref<CoreCallingConvention>> {

rust/src/collaboration/remote.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl Remote {
192192
/// Connects to the Remote, loading metadata and optionally acquiring a token.
193193
///
194194
/// Use [Remote::connect_with_opts] if you cannot otherwise automatically connect using enterprise.
195-
///
195+
///
196196
/// WARNING: This is currently **not** thread safe, if you try and connect/disconnect to a remote on
197197
/// multiple threads you will be subject to race conditions. To avoid this wrap the [`Remote`] in
198198
/// a synchronization primitive, and pass that to your threads. Or don't try and connect on multiple threads.
@@ -238,7 +238,7 @@ impl Remote {
238238
}
239239

240240
/// Disconnects from the remote.
241-
///
241+
///
242242
/// WARNING: This is currently **not** thread safe, if you try and connect/disconnect to a remote on
243243
/// multiple threads you will be subject to race conditions. To avoid this wrap the [`Remote`] in
244244
/// a synchronization primitive, and pass that to your threads. Or don't try and connect on multiple threads.

rust/src/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ impl Debug for Function {
23752375
// TODO: I am sure there is more we should add to this.
23762376
f.debug_struct("Function")
23772377
.field("start", &self.start())
2378-
.field("arch", &self.arch())
2378+
.field("arch", &self.arch().name())
23792379
.field("platform", &self.platform())
23802380
.field("symbol", &self.symbol())
23812381
.field("is_auto", &self.is_auto())

rust/src/platform.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ impl Debug for Platform {
399399
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
400400
f.debug_struct("Platform")
401401
.field("name", &self.name())
402-
.field("arch", &self.arch())
402+
.field("arch", &self.arch().name())
403403
.finish()
404404
}
405405
}

rust/src/symbol.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//! Interfaces for the various kinds of symbols in a binary.
1616
1717
use std::fmt;
18+
use std::fmt::Debug;
1819
use std::hash::{Hash, Hasher};
1920
use std::ptr;
2021

@@ -286,16 +287,18 @@ impl Symbol {
286287
unsafe impl Send for Symbol {}
287288
unsafe impl Sync for Symbol {}
288289

289-
impl fmt::Debug for Symbol {
290+
impl Debug for Symbol {
290291
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
291-
write!(
292-
f,
293-
"<sym {:?} '{}' @ {:x} (handle: {:?})>",
294-
self.sym_type(),
295-
self.full_name(),
296-
self.address(),
297-
self.handle
298-
)
292+
f.debug_struct("Symbol")
293+
.field("type", &self.sym_type())
294+
.field("binding", &self.binding())
295+
.field("full_name", &self.full_name())
296+
.field("short_name", &self.short_name())
297+
.field("raw_name", &self.raw_name())
298+
.field("address", &self.address())
299+
.field("auto_defined", &self.auto_defined())
300+
.field("external", &self.external())
301+
.finish()
299302
}
300303
}
301304

rust/src/tags.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl ToOwned for TagType {
230230
unsafe impl Send for TagType {}
231231
unsafe impl Sync for TagType {}
232232

233-
#[derive(Debug, Clone, PartialEq)]
233+
#[derive(Clone, PartialEq)]
234234
pub struct TagReference {
235235
pub arch: CoreArchitecture,
236236
pub func: Ref<Function>,
@@ -253,6 +253,17 @@ impl From<&BNTagReference> for TagReference {
253253
}
254254
}
255255

256+
impl Debug for TagReference {
257+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
258+
f.debug_struct("TagReference")
259+
.field("addr", &self.addr)
260+
.field("auto_defined", &self.auto_defined)
261+
.field("reference_type", &self.reference_type)
262+
.field("tag", &self.tag)
263+
.finish()
264+
}
265+
}
266+
256267
impl CoreArrayProvider for TagReference {
257268
type Raw = BNTagReference;
258269
type Context = ();

rust/tests/binary_view.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use binaryninja::binary_view::{AnalysisState, BinaryViewBase, BinaryViewExt};
22
use binaryninja::headless::Session;
3+
use binaryninja::main_thread::execute_on_main_thread_and_wait;
34
use binaryninja::symbol::{SymbolBuilder, SymbolType};
45
use rstest::*;
56
use std::path::PathBuf;
6-
use binaryninja::main_thread::execute_on_main_thread_and_wait;
77

88
#[fixture]
99
#[once]

rust/tests/collaboration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use binaryninja::collaboration::{
55
use binaryninja::headless::Session;
66
use binaryninja::symbol::{SymbolBuilder, SymbolType};
77
use rstest::*;
8-
use std::path::PathBuf;
98
use serial_test::serial;
9+
use std::path::PathBuf;
1010

1111
#[fixture]
1212
#[once]

0 commit comments

Comments
 (0)