diff options
| author | Mason Reed <mason@vector35.com> | 2025-12-17 21:23:46 -0500 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2026-01-11 10:36:01 -0800 |
| commit | 168a3fd34824adc9c6a606cd144219701f15cccf (patch) | |
| tree | 9bbac31ece5ea6ab6627998d995a77f7f7e2f8e6 /plugins/dwarf/dwarf_export | |
| parent | ca91bc1933976c62d24248f0f7c35af38451ff11 (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/dwarf/dwarf_export')
| -rw-r--r-- | plugins/dwarf/dwarf_export/Cargo.toml | 1 | ||||
| -rw-r--r-- | plugins/dwarf/dwarf_export/src/lib.rs | 22 |
2 files changed, 11 insertions, 12 deletions
diff --git a/plugins/dwarf/dwarf_export/Cargo.toml b/plugins/dwarf/dwarf_export/Cargo.toml index 570626f6..81c8a017 100644 --- a/plugins/dwarf/dwarf_export/Cargo.toml +++ b/plugins/dwarf/dwarf_export/Cargo.toml @@ -11,5 +11,4 @@ crate-type = ["cdylib"] binaryninja.workspace = true binaryninjacore-sys.workspace = true gimli = "^0.31" -log = "0.4" object = { version = "0.32.1", features = ["write"] } diff --git a/plugins/dwarf/dwarf_export/src/lib.rs b/plugins/dwarf/dwarf_export/src/lib.rs index 333ce83b..bc7d3c27 100644 --- a/plugins/dwarf/dwarf_export/src/lib.rs +++ b/plugins/dwarf/dwarf_export/src/lib.rs @@ -1,13 +1,13 @@ mod edit_distance; use binaryninja::interaction::form::{Form, FormInputField}; -use binaryninja::logger::Logger; use binaryninja::{ binary_view::{BinaryView, BinaryViewBase, BinaryViewExt}, command::{register_command, Command}, confidence::Conf, rc::Ref, symbol::SymbolType, + tracing, types::{MemberAccess, StructureType, Type, TypeClass}, }; use gimli::{ @@ -17,7 +17,6 @@ use gimli::{ UnitEntryId, }, }; -use log::{error, info, warn, LevelFilter}; use object::{write, Architecture, BinaryFormat, SectionKind}; use std::fs; use std::path::{Path, PathBuf}; @@ -148,7 +147,10 @@ fn export_type( ); } None => { - log::warn!("Could not export base struct `{}`", base_struct.ty.name()); + tracing::warn!( + "Could not export base struct `{}`", + base_struct.ty.name() + ); } } } @@ -374,7 +376,7 @@ fn export_type( Some(typedef_die_uid) } } else { - warn!("Could not get target of typedef `{}`", ntr.name()); + tracing::warn!("Could not get target of typedef `{}`", ntr.name()); None } } @@ -703,12 +705,12 @@ fn write_dwarf<T: gimli::Endianity>( if let Ok(out_data) = out_object.write() { if let Err(err) = fs::write(file_path, out_data) { - error!("Failed to write DWARF file: {}", err); + tracing::error!("Failed to write DWARF file: {}", err); } else { - info!("Successfully saved as DWARF to `{:?}`", file_path); + tracing::info!("Successfully saved as DWARF to `{:?}`", file_path); } } else { - error!("Failed to write DWARF with requested settings"); + tracing::error!("Failed to write DWARF with requested settings"); } Ok(()) @@ -785,7 +787,7 @@ fn export_dwarf(bv: &BinaryView) { }; if let Err(e) = write_dwarf(&save_loc_path, arch, endianness, &mut dwarf) { - error!("Error writing DWARF: {}", e); + tracing::error!("Error writing DWARF: {}", e); } } @@ -802,9 +804,7 @@ impl Command for MyCommand { #[no_mangle] pub extern "C" fn CorePluginInit() -> bool { - Logger::new("DWARF Export") - .with_level(LevelFilter::Debug) - .init(); + binaryninja::tracing_init!("DWARF Export"); register_command( "Export as DWARF", |
