Skip to content

Commit 93aa1a8

Browse files
committed
[Rust] WIP: Replace log with tracing
- Added more documentation - Replaced global named logger for plugins, fixing the issue when the CU has multiple (e.g. statically linked demo) - Simplified some misc code This is a breaking change, but I believe there is no better time to make it, we cannot continue to use the `log` crate, it is too limited for our needs.
1 parent 6138978 commit 93aa1a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1028
-758
lines changed

Cargo.lock

Lines changed: 46 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

arch/msp430/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ license = "Apache-2.0"
88
[dependencies]
99
binaryninja.workspace = true
1010
binaryninjacore-sys.workspace = true
11-
log = "0.4"
1211
msp430-asm = "^0.2"
1312

1413
[lib]

arch/msp430/src/architecture.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use binaryninja::{
88
UnusedIntrinsic, UnusedRegisterStack,
99
},
1010
disassembly::{InstructionTextToken, InstructionTextTokenKind},
11-
Endianness,
11+
tracing, Endianness,
1212
};
1313

1414
use msp430_asm::{
@@ -21,7 +21,6 @@ use binaryninja::architecture::{
2121
};
2222
use binaryninja::low_level_il::expression::ValueExpr;
2323
use binaryninja::low_level_il::{LowLevelILMutableExpression, LowLevelILMutableFunction};
24-
use log::error;
2524

2625
const MIN_MNEMONIC: usize = 9;
2726

@@ -321,7 +320,7 @@ impl Architecture for Msp430 {
321320
match id.try_into() {
322321
Ok(flag) => Some(flag),
323322
Err(_) => {
324-
error!("invalid flag id {}", id);
323+
tracing::error!("invalid flag id {}", id);
325324
None
326325
}
327326
}
@@ -331,7 +330,7 @@ impl Architecture for Msp430 {
331330
match id.try_into() {
332331
Ok(flag_write) => Some(flag_write),
333332
Err(_) => {
334-
error!("invalid flag write id {}", id);
333+
tracing::error!("invalid flag write id {}", id);
335334
None
336335
}
337336
}

arch/msp430/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
extern crate binaryninja;
2-
extern crate log;
3-
extern crate msp430_asm;
4-
51
use binaryninja::{
62
add_optional_plugin_dependency,
73
architecture::ArchitectureExt,
84
calling_convention,
95
custom_binary_view::{BinaryViewType, BinaryViewTypeExt},
106
Endianness,
117
};
12-
use log::LevelFilter;
138

149
mod architecture;
1510
mod flag;
1611
mod lift;
1712
mod register;
1813

1914
use architecture::Msp430;
20-
use binaryninja::logger::Logger;
2115

2216
#[no_mangle]
2317
#[allow(non_snake_case)]
2418
pub extern "C" fn CorePluginInit() -> bool {
25-
Logger::new("MSP430").with_level(LevelFilter::Info).init();
19+
binaryninja::tracing_init!("MSP430");
20+
2621
let arch =
2722
binaryninja::architecture::register_architecture("msp430", |custom_handle, handle| {
2823
Msp430::new(handle, custom_handle)

arch/msp430/src/lift.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::architecture::offset_to_absolute;
22
use crate::flag::{Flag, FlagWrite};
33
use crate::register::Register;
44

5-
use binaryninja::{architecture::FlagCondition, low_level_il::lifting::LowLevelILLabel};
5+
use binaryninja::{architecture::FlagCondition, low_level_il::lifting::LowLevelILLabel, tracing};
66

77
use msp430_asm::emulate::Emulated;
88
use msp430_asm::instruction::Instruction;
@@ -13,7 +13,6 @@ use msp430_asm::two_operand::TwoOperand;
1313

1414
use binaryninja::low_level_il::expression::ValueExpr;
1515
use binaryninja::low_level_il::{LowLevelILMutableExpression, LowLevelILMutableFunction};
16-
use log::info;
1716

1817
macro_rules! auto_increment {
1918
($src:expr, $il:ident) => {
@@ -550,7 +549,7 @@ pub(crate) fn lift_instruction(inst: &Instruction, addr: u64, il: &LowLevelILMut
550549
il.set_reg(size, Register::try_from(*r as u32).unwrap(), il.pop(2))
551550
.append();
552551
} else {
553-
info!("pop: invalid destination operand");
552+
tracing::info!("pop: invalid destination operand");
554553
}
555554
}
556555
Instruction::Ret(_) => {

arch/riscv/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ license = "Apache-2.0"
99
binaryninja.workspace = true
1010
binaryninjacore-sys.workspace = true
1111
riscv-dis = { path = "disasm" }
12-
log = "0.4"
1312
rayon = { version = "1.0", optional = true }
1413

1514
[features]

0 commit comments

Comments
 (0)