summaryrefslogtreecommitdiff
path: root/plugins/svd
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-12-17 21:23:46 -0500
committerMason Reed <35282038+emesare@users.noreply.github.com>2026-01-11 10:36:01 -0800
commit168a3fd34824adc9c6a606cd144219701f15cccf (patch)
tree9bbac31ece5ea6ab6627998d995a77f7f7e2f8e6 /plugins/svd
parentca91bc1933976c62d24248f0f7c35af38451ff11 (diff)
[Rust] 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.
Diffstat (limited to 'plugins/svd')
-rw-r--r--plugins/svd/Cargo.toml1
-rw-r--r--plugins/svd/demo/Cargo.toml1
-rw-r--r--plugins/svd/src/lib.rs19
-rw-r--r--plugins/svd/src/mapper.rs7
4 files changed, 13 insertions, 15 deletions
diff --git a/plugins/svd/Cargo.toml b/plugins/svd/Cargo.toml
index e25c410b..cd368585 100644
--- a/plugins/svd/Cargo.toml
+++ b/plugins/svd/Cargo.toml
@@ -11,7 +11,6 @@ crate-type = ["cdylib", "lib"]
binaryninja.workspace = true
binaryninjacore-sys.workspace = true
svd-parser = { version = "0.14.8", features = ["expand"] }
-log = "0.4"
serde_json = "1.0"
[dev-dependencies]
diff --git a/plugins/svd/demo/Cargo.toml b/plugins/svd/demo/Cargo.toml
index 0dffba6e..811f7d08 100644
--- a/plugins/svd/demo/Cargo.toml
+++ b/plugins/svd/demo/Cargo.toml
@@ -12,7 +12,6 @@ path = "../src/lib.rs"
binaryninja = { workspace = true, features = ["demo"]}
binaryninjacore-sys.workspace = true
svd-parser = { version = "0.14.8", features = ["expand"] }
-log = "0.4"
serde_json = "1.0"
[dev-dependencies]
diff --git a/plugins/svd/src/lib.rs b/plugins/svd/src/lib.rs
index 3a069056..396a9447 100644
--- a/plugins/svd/src/lib.rs
+++ b/plugins/svd/src/lib.rs
@@ -6,9 +6,8 @@ use crate::settings::LoadSettings;
use binaryninja::binary_view::{BinaryView, BinaryViewBase, BinaryViewExt};
use binaryninja::command::Command;
use binaryninja::interaction::{Form, FormInputField};
-use binaryninja::logger::Logger;
+use binaryninja::tracing;
use binaryninja::workflow::{activity, Activity, AnalysisContext, Workflow};
-use log::LevelFilter;
use std::path::PathBuf;
use svd_parser::ValidateLevel;
@@ -120,7 +119,7 @@ impl Command for LoadSVDFile {
let file_content = match std::fs::read_to_string(&file_path) {
Ok(content) => content,
Err(e) => {
- log::error!("Failed to read file: {:?}", e);
+ tracing::error!("Failed to read file: {:?}", e);
return;
}
};
@@ -137,7 +136,7 @@ impl Command for LoadSVDFile {
view.update_analysis();
}
Err(e) => {
- log::error!("Failed to parse SVD file: {:?}", e);
+ tracing::error!("Failed to parse SVD file: {:?}", e);
}
}
}
@@ -152,7 +151,7 @@ impl Command for LoadSVDFile {
#[cfg(not(feature = "demo"))]
pub extern "C" fn CorePluginInit() -> bool {
if plugin_init().is_err() {
- log::error!("Failed to initialize SVD plug-in");
+ tracing::error!("Failed to initialize SVD plug-in");
return false;
}
true
@@ -163,14 +162,14 @@ pub extern "C" fn CorePluginInit() -> bool {
#[cfg(feature = "demo")]
pub extern "C" fn SVDPluginInit() -> bool {
if plugin_init().is_err() {
- log::error!("Failed to initialize SVD plug-in");
+ tracing::error!("Failed to initialize SVD plug-in");
return false;
}
true
}
fn plugin_init() -> Result<(), ()> {
- Logger::new("SVD").with_level(LevelFilter::Debug).init();
+ binaryninja::tracing_init!("SVD");
binaryninja::command::register_command(
"Load SVD File",
@@ -185,13 +184,13 @@ fn plugin_init() -> Result<(), ()> {
let view = ctx.view();
let load_settings = LoadSettings::from_view_settings(&view);
let Some(file) = &load_settings.auto_load_file else {
- log::debug!("No SVD file specified, skipping...");
+ tracing::debug!("No SVD file specified, skipping...");
return;
};
let file_content = match std::fs::read_to_string(file) {
Ok(content) => content,
Err(e) => {
- log::error!("Failed to read file: {}", e);
+ tracing::error!("Failed to read file: {}", e);
return;
}
};
@@ -204,7 +203,7 @@ fn plugin_init() -> Result<(), ()> {
mapper.map_to_view(&view);
}
Err(e) => {
- log::error!("Failed to parse SVD file: {:?}", e);
+ tracing::error!("Failed to parse SVD file: {:?}", e);
}
}
};
diff --git a/plugins/svd/src/mapper.rs b/plugins/svd/src/mapper.rs
index 4c49145b..2c09eb95 100644
--- a/plugins/svd/src/mapper.rs
+++ b/plugins/svd/src/mapper.rs
@@ -6,6 +6,7 @@ use binaryninja::rc::Ref;
use binaryninja::section::{SectionBuilder, Semantics};
use binaryninja::segment::{SegmentBuilder, SegmentFlags};
use binaryninja::symbol::{SymbolBuilder, SymbolType};
+use binaryninja::tracing;
use binaryninja::types::{
BaseStructure, EnumerationBuilder, MemberAccess, MemberScope, NamedTypeReference,
NamedTypeReferenceClass, StructureBuilder, StructureMember, Type, TypeBuilder,
@@ -78,7 +79,7 @@ impl DeviceMapper {
}
pub fn map_to_view(&self, view: &BinaryView) {
- log::info!("Mapping device... {}", self.device.name);
+ tracing::info!("Mapping device... {}", self.device.name);
for peripheral in &self.device.peripherals {
match peripheral {
Peripheral::Single(info) => {
@@ -143,7 +144,7 @@ impl DeviceMapper {
address_block: &AddressBlock,
) {
let block_addr = peripheral.base_address + address_block.offset as u64;
- log::info!(
+ tracing::info!(
"Mapping peripheral block @ 0x{:x} for {}",
block_addr,
peripheral.name
@@ -176,7 +177,7 @@ impl DeviceMapper {
);
if !added_memory {
- log::error!(
+ tracing::error!(
"Failed to add memory for peripheral block! {} @ 0x{:x}",
block_name,
block_addr