summaryrefslogtreecommitdiff
path: root/plugins/dwarf
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/dwarf
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/dwarf')
-rw-r--r--plugins/dwarf/dwarf_export/Cargo.toml1
-rw-r--r--plugins/dwarf/dwarf_export/src/lib.rs22
-rw-r--r--plugins/dwarf/dwarf_import/Cargo.toml1
-rw-r--r--plugins/dwarf/dwarf_import/demo/Cargo.toml1
-rw-r--r--plugins/dwarf/dwarf_import/src/die_handlers.rs31
-rw-r--r--plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs42
-rw-r--r--plugins/dwarf/dwarf_import/src/functions.rs21
-rw-r--r--plugins/dwarf/dwarf_import/src/helpers.rs19
-rw-r--r--plugins/dwarf/dwarf_import/src/lib.rs47
-rw-r--r--plugins/dwarf/dwarf_import/src/types.rs34
10 files changed, 109 insertions, 110 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",
diff --git a/plugins/dwarf/dwarf_import/Cargo.toml b/plugins/dwarf/dwarf_import/Cargo.toml
index 15f3fda8..f71d4cf4 100644
--- a/plugins/dwarf/dwarf_import/Cargo.toml
+++ b/plugins/dwarf/dwarf_import/Cargo.toml
@@ -15,7 +15,6 @@ dwarfreader = { path = "../shared/" }
binaryninja.workspace = true
binaryninjacore-sys.workspace = true
gimli = "0.31"
-log = "0.4"
iset = "0.2.2"
cpp_demangle = "0.4.3"
regex = "1"
diff --git a/plugins/dwarf/dwarf_import/demo/Cargo.toml b/plugins/dwarf/dwarf_import/demo/Cargo.toml
index e088fb68..3a5ad601 100644
--- a/plugins/dwarf/dwarf_import/demo/Cargo.toml
+++ b/plugins/dwarf/dwarf_import/demo/Cargo.toml
@@ -16,7 +16,6 @@ dwarfreader = { path = "../../shared/" }
binaryninja = { workspace = true, features = ["demo"]}
binaryninjacore-sys.workspace = true
gimli = "0.31"
-log = "0.4"
iset = "0.2.2"
cpp_demangle = "0.4.3"
regex = "1"
diff --git a/plugins/dwarf/dwarf_import/src/die_handlers.rs b/plugins/dwarf/dwarf_import/src/die_handlers.rs
index fed3a1da..b4b526a0 100644
--- a/plugins/dwarf/dwarf_import/src/die_handlers.rs
+++ b/plugins/dwarf/dwarf_import/src/die_handlers.rs
@@ -18,6 +18,7 @@ use crate::{helpers::*, ReaderType};
use binaryninja::{
rc::*,
+ tracing,
types::{EnumerationBuilder, FunctionParameter, ReferenceType, Type, TypeBuilder},
};
@@ -109,7 +110,7 @@ pub(crate) fn handle_enum<R: ReaderType>(
let mut tree = match unit.entries_tree(Some(entry.offset())) {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to get enum entry tree: {}", e);
+ tracing::error!("Failed to get enum entry tree: {}", e);
return None;
}
};
@@ -117,7 +118,7 @@ pub(crate) fn handle_enum<R: ReaderType>(
let tree_root = match tree.root() {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to get enum entry tree root: {}", e);
+ tracing::error!("Failed to get enum entry tree root: {}", e);
return None;
}
};
@@ -132,15 +133,15 @@ pub(crate) fn handle_enum<R: ReaderType>(
enumeration_builder.insert(&name, value);
} else {
// Somehow the child entry is not a const value.
- log::error!("Unhandled enum member value type for `{}`", name);
+ tracing::error!("Unhandled enum member value type for `{}`", name);
}
}
Ok(None) => {
// Somehow the child entry does not have a const value.
- log::error!("Enum member `{}` has no constant value attribute", name);
+ tracing::error!("Enum member `{}` has no constant value attribute", name);
}
Err(e) => {
- log::error!("Error parsing next attribute entry for `{}`: {}", name, e);
+ tracing::error!("Error parsing next attribute entry for `{}`: {}", name, e);
return None;
}
}
@@ -208,7 +209,7 @@ pub(crate) fn handle_pointer<R: ReaderType>(
Some(entry_type_offset) => {
let debug_target_type =
debug_info_builder.get_type(entry_type_offset).or_else(|| {
- log::error!(
+ tracing::error!(
"Failed to get pointer target type at entry offset {}",
entry_type_offset
);
@@ -255,7 +256,7 @@ pub(crate) fn handle_array<R: ReaderType>(
let parent_type = debug_info_builder
.get_type(entry_type_offset)
.or_else(|| {
- log::error!(
+ tracing::error!(
"Failed to get array member type at entry offset {}",
entry_type_offset
);
@@ -266,14 +267,14 @@ pub(crate) fn handle_array<R: ReaderType>(
let mut tree = match unit.entries_tree(Some(entry.offset())) {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to get array entry tree: {}", e);
+ tracing::error!("Failed to get array entry tree: {}", e);
return None;
}
};
let tree_root = match tree.root() {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to get array entry tree root: {}", e);
+ tracing::error!("Failed to get array entry tree root: {}", e);
return None;
}
};
@@ -351,7 +352,7 @@ pub(crate) fn handle_function<R: ReaderType>(
let mut tree = match unit.entries_tree(Some(entry.offset())) {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to get function entry tree: {}", e);
+ tracing::error!("Failed to get function entry tree: {}", e);
return None;
}
};
@@ -359,7 +360,7 @@ pub(crate) fn handle_function<R: ReaderType>(
let tree_root = match tree.root() {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to get function entry tree root: {}", e);
+ tracing::error!("Failed to get function entry tree root: {}", e);
return None;
}
};
@@ -374,7 +375,7 @@ pub(crate) fn handle_function<R: ReaderType>(
debug_info_builder_context,
debug_info_builder,
) else {
- log::error!(
+ tracing::error!(
"Failed to get function parameter child type in unit {:?} at offset {:x}",
unit.header.offset(),
child.entry().offset().0,
@@ -384,7 +385,7 @@ pub(crate) fn handle_function<R: ReaderType>(
let name = debug_info_builder_context.get_name(dwarf, unit, child.entry());
let child_debug_type = debug_info_builder.get_type(child_uid).or_else(|| {
- log::error!(
+ tracing::error!(
"Failed to get function parameter type with uid {}",
child_uid
);
@@ -439,7 +440,7 @@ pub(crate) fn handle_const(
Some(entry_type_offset) => debug_info_builder
.get_type(entry_type_offset)
.or_else(|| {
- log::error!(
+ tracing::error!(
"Failed to get const type with entry offset {}",
entry_type_offset
);
@@ -469,7 +470,7 @@ pub(crate) fn handle_volatile(
Some(entry_type_offset) => debug_info_builder
.get_type(entry_type_offset)
.or_else(|| {
- log::error!(
+ tracing::error!(
"Failed to get volatile type with entry offset {}",
entry_type_offset
);
diff --git a/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs
index 497e6c9c..397e07a3 100644
--- a/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs
+++ b/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs
@@ -25,6 +25,7 @@ use binaryninja::{
rc::*,
symbol::SymbolType,
template_simplifier::simplify_str_to_fqn,
+ tracing,
types::{FunctionParameter, Type},
variable::NamedVariableWithType,
};
@@ -34,7 +35,6 @@ use gimli::{DebuggingInformationEntry, Dwarf, Unit};
use binaryninja::confidence::Conf;
use binaryninja::variable::{Variable, VariableSourceType};
use indexmap::{map::Values, IndexMap};
-use log::{debug, error, warn};
use std::{cmp::Ordering, collections::HashMap, hash::Hash};
pub(crate) type TypeUID = usize;
@@ -133,7 +133,7 @@ impl<R: ReaderType> DebugInfoBuilderContext<R> {
if let Ok(unit) = dwarf.unit(header) {
units.push(unit);
} else {
- error!("Unable to read DWARF information. File may be malformed or corrupted. Not applying debug info.");
+ tracing::error!("Unable to read DWARF information. File may be malformed or corrupted. Not applying debug info.");
return None;
}
}
@@ -145,7 +145,7 @@ impl<R: ReaderType> DebugInfoBuilderContext<R> {
if let Ok(unit) = sup_dwarf.unit(header) {
sup_units.push(unit);
} else {
- error!("Unable to read supplementary DWARF information. File may be malformed or corrupted. Not applying debug info.");
+ tracing::error!("Unable to read supplementary DWARF information. File may be malformed or corrupted. Not applying debug info.");
return None;
}
}
@@ -193,7 +193,7 @@ impl<R: ReaderType> DebugInfoBuilderContext<R> {
match &entry_unit.entry(entry_offset) {
Ok(x) => x,
Err(e) => {
- log::error!(
+ tracing::error!(
"Failed to get entry {:?} in unit {:?}: {}",
entry_offset,
entry_unit.header.offset(),
@@ -265,7 +265,7 @@ impl DebugInfoBuilder {
// if the full name exists, update the stored index for the full name
if let Some(idx) = self.raw_function_name_indices.get(ident) {
let function = self.functions.get_mut(*idx).or_else(|| {
- log::error!("Failed to get function with index {}", idx);
+ tracing::error!("Failed to get function with index {}", idx);
None
})?;
@@ -298,7 +298,7 @@ impl DebugInfoBuilder {
// if the raw name exists, update the stored index for the raw name
if let Some(idx) = self.full_function_name_indices.get(ident) {
let function = self.functions.get_mut(*idx).or_else(|| {
- log::error!("Failed to get function with index {}", idx);
+ tracing::error!("Failed to get function with index {}", idx);
None
})?;
@@ -325,7 +325,7 @@ impl DebugInfoBuilder {
return Some(*idx);
}
} else {
- debug!("Function entry in DWARF without full or raw name.");
+ tracing::debug!("Function entry in DWARF without full or raw name.");
return None;
}
@@ -387,7 +387,7 @@ impl DebugInfoBuilder {
},
) {
if existing_type != t && commit {
- warn!("DWARF info contains duplicate type definition. Overwriting type `{}` (named `{:?}`) with `{}` (named `{:?}`)",
+ tracing::warn!("DWARF info contains duplicate type definition. Overwriting type `{}` (named `{:?}`) with `{}` (named `{:?}`)",
existing_type,
existing_name,
t,
@@ -434,7 +434,7 @@ impl DebugInfoBuilder {
let Some(function_index) = fn_idx else {
// If we somehow lost track of what subprogram we're in or we're not actually in a subprogram
- error!(
+ tracing::error!(
"Trying to add a local variable outside of a subprogram. Please report this issue."
);
return;
@@ -452,12 +452,12 @@ impl DebugInfoBuilder {
let Some(func_addr) = function.address else {
// If we somehow are processing a function's variables before the function is created
- error!("Trying to add a local variable without a known function start. Please report this issue.");
+ tracing::error!("Trying to add a local variable without a known function start. Please report this issue.");
return;
};
let Some(frame_base) = &function.frame_base else {
- error!("Trying to add a local variable ({}) to a function ({:#x}) without a frame base. Please report this issue.", name, func_addr);
+ tracing::error!("Trying to add a local variable ({}) to a function ({:#x}) without a frame base. Please report this issue.", name, func_addr);
return;
};
@@ -480,7 +480,7 @@ impl DebugInfoBuilder {
.cloned()
else {
// Unknown why, but this is happening with MachO + external dSYM
- debug!("Refusing to add a local variable ({}@{}) to function at {} without a known CFA adjustment.", name, offset, func_addr);
+ tracing::debug!("Refusing to add a local variable ({}@{}) to function at {} without a known CFA adjustment.", name, offset, func_addr);
return;
};
@@ -510,7 +510,7 @@ impl DebugInfoBuilder {
if adjusted_offset > 0 {
// If we somehow end up with a positive sp offset
- error!("Trying to add a local variable \"{}\" in function at {:#x} at positive storage offset {}. Please report this issue.", name, func_addr, adjusted_offset);
+ tracing::error!("Trying to add a local variable \"{}\" in function at {:#x} at positive storage offset {}. Please report this issue.", name, func_addr, adjusted_offset);
return;
}
@@ -536,7 +536,7 @@ impl DebugInfoBuilder {
let existing_type = match self.get_type(existing_type_uid) {
Some(x) => x.ty.as_ref(),
None => {
- log::error!(
+ tracing::error!(
"Failed to find existing type with uid {} for data variable at {:#x}",
existing_type_uid,
address
@@ -548,7 +548,7 @@ impl DebugInfoBuilder {
let new_type = match self.get_type(type_uid) {
Some(x) => x.ty.as_ref(),
None => {
- log::error!(
+ tracing::error!(
"Failed to find new type with uid {} for data variable at {:#x}",
type_uid,
address
@@ -558,7 +558,7 @@ impl DebugInfoBuilder {
};
if existing_type_uid != type_uid || existing_type != new_type {
- warn!("DWARF info contains duplicate data variable definition. Overwriting data variable at {:#08x} (`{}`) with `{}`",
+ tracing::warn!("DWARF info contains duplicate data variable definition. Overwriting data variable at {:#08x} (`{}`) with `{}`",
address,
existing_type,
new_type
@@ -580,7 +580,7 @@ impl DebugInfoBuilder {
// Prevent storing two types with the same name and differing definitions
if let Some(stored_uid) = type_uids_by_name.get(&debug_type_name) {
let Some(stored_debug_type) = self.types.get(stored_uid) else {
- error!("Stored type name without storing a type! Please report this error. UID: {}, name: {}", stored_uid, debug_type_name);
+ tracing::error!("Stored type name without storing a type! Please report this error. UID: {}, name: {}", stored_uid, debug_type_name);
continue;
};
@@ -624,14 +624,14 @@ impl DebugInfoBuilder {
if let Some(target_type) = self.get_type(target_uid) {
debug_info.add_type(&debug_type_name, &target_type.get_type(), &[]);
} else {
- error!(
+ tracing::error!(
"Failed to find typedef {} target for uid {}",
debug_type_name,
ntr.name()
);
}
} else {
- error!(
+ tracing::error!(
"Failed to find typedef {} target uid for {}",
debug_type_name,
ntr.name()
@@ -650,7 +650,7 @@ impl DebugInfoBuilder {
let data_var_type = match self.get_type(*type_uid) {
Some(x) => &x.ty,
None => {
- log::error!("Failed to find type for data variable at {:#x}", address);
+ tracing::error!("Failed to find type for data variable at {:#x}", address);
continue;
}
};
@@ -752,7 +752,7 @@ impl DebugInfoBuilder {
let existing_functions = bv.functions_at(*address);
match existing_functions.len().cmp(&1) {
Ordering::Greater => {
- warn!("Multiple existing functions at address {address:08x}. One or more functions at this address may have the wrong platform information. Please report this binary.");
+ tracing::warn!("Multiple existing functions at address {address:08x}. One or more functions at this address may have the wrong platform information. Please report this binary.");
}
Ordering::Equal => {
func.platform = Some(existing_functions.get(0).platform())
diff --git a/plugins/dwarf/dwarf_import/src/functions.rs b/plugins/dwarf/dwarf_import/src/functions.rs
index adc74c41..709cea62 100644
--- a/plugins/dwarf/dwarf_import/src/functions.rs
+++ b/plugins/dwarf/dwarf_import/src/functions.rs
@@ -19,9 +19,9 @@ use crate::types::get_type;
use crate::{helpers::*, ReaderType};
use binaryninja::template_simplifier::simplify_str_to_str;
+use binaryninja::tracing;
use cpp_demangle::DemangleOptions;
use gimli::{constants, AttributeValue, DebuggingInformationEntry, Dwarf, Operation, Unit};
-use log::{debug, error};
use regex::Regex;
#[derive(PartialEq, Eq, Hash)]
@@ -45,14 +45,14 @@ fn get_parameters<R: ReaderType>(
let mut sub_die_tree = match unit.entries_tree(Some(entry.offset())) {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to get function parameter entry tree: {}", e);
+ tracing::error!("Failed to get function parameter entry tree: {}", e);
return (vec![], false);
}
};
let root = match sub_die_tree.root() {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to get function parameter entry tree root: {}", e);
+ tracing::error!("Failed to get function parameter entry tree root: {}", e);
return (vec![], false);
}
};
@@ -148,7 +148,7 @@ pub(crate) fn parse_function_entry<R: ReaderType>(
}
if raw_name.is_none() && full_name.is_none() {
- debug!(
+ tracing::debug!(
"Function entry in DWARF without full or raw name: .debug_info offset {:?}",
entry.offset().to_debug_info_offset(&unit.header)
);
@@ -203,13 +203,13 @@ pub(crate) fn parse_lexical_block<R: ReaderType>(
let unit_base = match unit.header.offset().as_debug_info_offset() {
Some(x) => x.0,
None => {
- log::warn!("Unable to get unit offset in debug info: {:?}. This may be an indicator of parsing issues.", unit.header.offset());
+ tracing::warn!("Unable to get unit offset in debug info: {:?}. This may be an indicator of parsing issues.", unit.header.offset());
0
}
};
let Ok(Some(low_pc)) = dwarf.attr_address(unit, low_pc_value.clone()) else {
- error!(
+ tracing::error!(
"Failed to read lexical block low_pc for entry {:#x}, please report this bug.",
unit_base + entry.offset().0
);
@@ -217,7 +217,7 @@ pub(crate) fn parse_lexical_block<R: ReaderType>(
};
let Ok(Some(high_pc_value)) = entry.attr_value(constants::DW_AT_high_pc) else {
- error!("Failed to read lexical block high_pc attribute for entry {:#x}, please report this bug.", unit_base + entry.offset().0);
+ tracing::error!("Failed to read lexical block high_pc attribute for entry {:#x}, please report this bug.", unit_base + entry.offset().0);
return None;
};
@@ -226,7 +226,7 @@ pub(crate) fn parse_lexical_block<R: ReaderType>(
.and_then(|x| Some(low_pc + x))
.or_else(|| dwarf.attr_address(unit, high_pc_value).unwrap_or(None))
else {
- error!(
+ tracing::error!(
"Failed to read lexical block high_pc for entry {:#x}, please report this bug.",
unit_base + entry.offset().0
);
@@ -244,9 +244,10 @@ pub(crate) fn parse_lexical_block<R: ReaderType>(
// Ranges where start == end may be ignored (DWARFv5 spec, 2.17.3 line 17)
return None;
} else {
- error!(
+ tracing::error!(
"Invalid lexical block range: {:#x} -> {:#x}",
- low_pc, high_pc
+ low_pc,
+ high_pc
);
}
} else {
diff --git a/plugins/dwarf/dwarf_import/src/helpers.rs b/plugins/dwarf/dwarf_import/src/helpers.rs
index aca614ab..d2654d98 100644
--- a/plugins/dwarf/dwarf_import/src/helpers.rs
+++ b/plugins/dwarf/dwarf_import/src/helpers.rs
@@ -18,12 +18,12 @@ use std::{str::FromStr, sync::mpsc};
use crate::{DebugInfoBuilderContext, ReaderType};
use binaryninja::binary_view::BinaryViewBase;
-use binaryninja::Endianness;
use binaryninja::{
binary_view::{BinaryView, BinaryViewExt},
download::{DownloadInstanceInputOutputCallbacks, DownloadProvider},
settings::Settings,
};
+use binaryninja::{tracing, Endianness};
use gimli::Dwarf;
use gimli::{
constants, Attribute, AttributeValue,
@@ -32,7 +32,6 @@ use gimli::{
};
use binaryninja::settings::QueryOptions;
-use log::warn;
pub(crate) fn get_uid<R: ReaderType>(
dwarf: &Dwarf<R>,
@@ -111,14 +110,16 @@ pub(crate) fn get_attr_die<'a, R: ReaderType>(
let sup: &Dwarf<R> = match dwarf.sup() {
Some(x) => x,
None => {
- log::error!("Trying to get offset in supplmentary dwarf info, but none is present");
+ tracing::error!("Trying to get offset in supplmentary dwarf info, but none is present");
return None;
}
};
return Some(DieReference::UnitAndOffset((sup, source_unit, new_offset)));
}
}
- warn!("Failed to fetch DIE. Supplementary debug information may be incomplete.");
+ tracing::warn!(
+ "Failed to fetch DIE. Supplementary debug information may be incomplete."
+ );
None
}
_ => None,
@@ -143,7 +144,7 @@ pub(crate) fn resolve_specification<'a, R: ReaderType>(
if let Ok(entry) = entry_unit.entry(entry_offset) {
resolve_specification(dwarf, entry_unit, &entry, debug_info_builder_context)
} else {
- warn!("Failed to fetch DIE for attr DW_AT_specification. Debug information may be incomplete.");
+ tracing::warn!("Failed to fetch DIE for attr DW_AT_specification. Debug information may be incomplete.");
DieReference::Err
}
}
@@ -161,12 +162,12 @@ pub(crate) fn resolve_specification<'a, R: ReaderType>(
if entry_offset == entry.offset()
&& unit.header.offset() == entry_unit.header.offset()
{
- warn!("DWARF information is invalid (infinite abstract origin reference cycle). Debug information may be incomplete.");
+ tracing::warn!("DWARF information is invalid (infinite abstract origin reference cycle). Debug information may be incomplete.");
DieReference::Err
} else if let Ok(new_entry) = entry_unit.entry(entry_offset) {
resolve_specification(dwarf, entry_unit, &new_entry, debug_info_builder_context)
} else {
- warn!("Failed to fetch DIE for attr DW_AT_abstract_origin. Debug information may be incomplete.");
+ tracing::warn!("Failed to fetch DIE for attr DW_AT_abstract_origin. Debug information may be incomplete.");
DieReference::Err
}
}
@@ -189,7 +190,7 @@ pub(crate) fn get_name<R: ReaderType>(
let resolved_entry = match entry_unit.entry(entry_offset) {
Ok(x) => x,
Err(_) => {
- log::error!(
+ tracing::error!(
"Failed to get entry in unit at {:?} at offset {:#x} (get_name)",
entry_unit.header.offset(),
entry_offset.0
@@ -236,7 +237,7 @@ pub(crate) fn get_raw_name<R: ReaderType>(
let resolved_entry = match entry_unit.entry(entry_offset) {
Ok(x) => x,
Err(_) => {
- log::error!(
+ tracing::error!(
"Failed to get entry in unit at {:?} at offset {:#x} (get_raw_name)",
entry_unit.header.offset(),
entry_offset.0
diff --git a/plugins/dwarf/dwarf_import/src/lib.rs b/plugins/dwarf/dwarf_import/src/lib.rs
index f192f9d1..e227a459 100644
--- a/plugins/dwarf/dwarf_import/src/lib.rs
+++ b/plugins/dwarf/dwarf_import/src/lib.rs
@@ -34,6 +34,7 @@ use binaryninja::{
debuginfo::{CustomDebugInfoParser, DebugInfo, DebugInfoParser},
settings::Settings,
template_simplifier::simplify_str_to_str,
+ tracing,
};
use dwarfreader::create_section_reader_object;
@@ -43,10 +44,8 @@ use gimli::{
SectionId, Unit, UnwindContext, UnwindSection,
};
-use binaryninja::logger::Logger;
use helpers::{get_build_id, load_debug_info_for_build_id};
use iset::IntervalMap;
-use log::{debug, error, warn};
use object::read::macho::FatArch;
use object::{Object, ObjectSection};
@@ -126,7 +125,7 @@ fn recover_names_internal<R: ReaderType>(
while let Ok(Some(header)) = iter.next() {
let unit_offset = header.offset().as_debug_info_offset().map_or_else(
|| {
- log::warn!("Failed to get debug info offset for {:?}", header.offset());
+ tracing::warn!("Failed to get debug info offset for {:?}", header.offset());
0
},
|x| x.0,
@@ -134,7 +133,7 @@ fn recover_names_internal<R: ReaderType>(
let unit = match dwarf.unit(header) {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to get unit at {:#x}: {}", unit_offset, e);
+ tracing::error!("Failed to get unit at {:#x}: {}", unit_offset, e);
continue;
}
};
@@ -163,7 +162,7 @@ fn recover_names_internal<R: ReaderType>(
depth += delta_depth;
if depth < 0 {
- error!("DWARF information is seriously malformed. Aborting parsing.");
+ tracing::error!("DWARF information is seriously malformed. Aborting parsing.");
return false;
}
@@ -196,7 +195,7 @@ fn recover_names_internal<R: ReaderType>(
let resolved_entry = match entry_unit.entry(entry_offset) {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to resolve entry in unit {:?} at offset {:#x} (resolve_namespace_name): {}", entry_unit.header.offset(), entry_offset.0, e);
+ tracing::error!("Failed to resolve entry in unit {:?} at offset {:#x} (resolve_namespace_name): {}", entry_unit.header.offset(), entry_offset.0, e);
return;
}
};
@@ -210,7 +209,7 @@ fn recover_names_internal<R: ReaderType>(
)
}
DieReference::Err => {
- warn!(
+ tracing::warn!(
"Failed to fetch DIE when resolving namespace. Debug information may be incomplete."
);
}
@@ -436,7 +435,7 @@ where
}) {
Ok(fde) => fde,
Err(e) => {
- error!("Failed to parse FDE: {}", e);
+ tracing::error!("Failed to parse FDE: {}", e);
continue;
}
};
@@ -447,7 +446,7 @@ where
}
if fde.initial_address().overflowing_add(fde.len()).1 {
- warn!(
+ tracing::warn!(
"FDE at offset {:?} exceeds bounds of memory space! {:#x} + length {:#x}",
fde.offset(),
fde.initial_address(),
@@ -481,7 +480,7 @@ where
cfa_offsets
.insert(row.start_address()..row.end_address(), *offset);
} else {
- debug!(
+ tracing::debug!(
"Invalid FDE table row addresses: {:#x}..{:#x}",
row.start_address(),
row.end_address()
@@ -489,7 +488,7 @@ where
}
}
CfaRule::Expression(_) => {
- debug!("Unhandled CFA expression when determining offset");
+ tracing::debug!("Unhandled CFA expression when determining offset");
}
};
}
@@ -548,7 +547,7 @@ fn parse_dwarf(
progress: Box<dyn Fn(usize, usize) -> Result<(), ()>>,
) -> Result<DebugInfoBuilder, String> {
if debug_file.section_by_name(".gnu_debugaltlink").is_some() && supplementary_data.is_none() {
- log::warn!(".gnu_debugaltlink section present but no supplementary data provided. DWARF parsing may fail.")
+ tracing::warn!(".gnu_debugaltlink section present but no supplementary data provided. DWARF parsing may fail.")
}
let address_size = match debug_file.architecture().address_size() {
@@ -588,7 +587,7 @@ fn parse_dwarf(
create_section_reader_object(section_id, &sup_file, sup_endian, sup_dwo_file)
};
if let Err(e) = dwarf.load_sup(sup_section_reader) {
- error!("Failed to load supplementary file: {}", e);
+ tracing::error!("Failed to load supplementary file: {}", e);
}
}
@@ -620,7 +619,7 @@ fn parse_dwarf(
let sup = match dwarf.sup() {
Some(x) => x,
None => {
- log::error!(
+ tracing::error!(
"Supplemental units found but no supplementary DWARF info available"
);
break;
@@ -743,7 +742,7 @@ impl CustomDebugInfoParser for DWARFParser {
match helpers::load_sibling_debug_file(bv) {
Ok(x) => x,
Err(e) => {
- log::error!("Failed loading sibling debug file: {}", e);
+ tracing::error!("Failed loading sibling debug file: {}", e);
None
}
}
@@ -754,7 +753,7 @@ impl CustomDebugInfoParser for DWARFParser {
match load_debug_info_for_build_id(&build_id, bv) {
Ok(x) => x,
Err(e) => {
- log::error!("Failed loading debug info from build id: {}", e);
+ tracing::error!("Failed loading debug info from build id: {}", e);
None
}
}
@@ -771,7 +770,7 @@ impl CustomDebugInfoParser for DWARFParser {
let debug_file = match parse_data_to_object(debug_data_vec.as_slice(), bv) {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to parse debug data: {}", e);
+ tracing::error!("Failed to parse debug data: {}", e);
return false;
}
};
@@ -784,7 +783,7 @@ impl CustomDebugInfoParser for DWARFParser {
let sup_data = match load_debug_info_for_build_id(sup_build_id, bv) {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to load supplementary debug file: {}", e);
+ tracing::error!("Failed to load supplementary debug file: {}", e);
None
}
};
@@ -795,13 +794,13 @@ impl CustomDebugInfoParser for DWARFParser {
|sup_file_path| match std::fs::read(sup_file_path) {
Ok(sup_data) => Some(sup_data),
Err(e) => {
- log::error!("Failed reading supplementary file {}: {}", x, e);
+ tracing::error!("Failed reading supplementary file {}: {}", x, e);
None
}
},
),
Err(e) => {
- log::error!("Supplementary file path is invalid utf8: {}", e);
+ tracing::error!("Supplementary file path is invalid utf8: {}", e);
None
}
})
@@ -812,7 +811,7 @@ impl CustomDebugInfoParser for DWARFParser {
match parse_data_to_object(data.as_slice(), bv) {
Ok(x) => Some(x),
Err(e) => {
- log::error!("Failed to parse supplementary debug data: {}", e);
+ tracing::error!("Failed to parse supplementary debug data: {}", e);
None
}
}
@@ -823,7 +822,7 @@ impl CustomDebugInfoParser for DWARFParser {
if let Ok(Some((_, expected_build_id))) = debug_file.gnu_debugaltlink() {
if let Ok(Some(loaded_sup_build_id)) = sup_file.build_id() {
if loaded_sup_build_id != expected_build_id {
- log::warn!(
+ tracing::warn!(
"Supplementary debug info build id ({}) does not match expected ({})",
loaded_sup_build_id
.iter()
@@ -845,7 +844,7 @@ impl CustomDebugInfoParser for DWARFParser {
true
}
Err(e) => {
- log::error!("Failed to parse DWARF: {}", e);
+ tracing::error!("Failed to parse DWARF: {}", e);
false
}
};
@@ -855,7 +854,7 @@ impl CustomDebugInfoParser for DWARFParser {
}
fn plugin_init() {
- Logger::new("DWARF").init();
+ binaryninja::tracing_init!("DWARF Import");
let settings = Settings::new();
diff --git a/plugins/dwarf/dwarf_import/src/types.rs b/plugins/dwarf/dwarf_import/src/types.rs
index 7f9e4e5d..45ccf74e 100644
--- a/plugins/dwarf/dwarf_import/src/types.rs
+++ b/plugins/dwarf/dwarf_import/src/types.rs
@@ -18,6 +18,7 @@ use crate::{die_handlers::*, ReaderType};
use binaryninja::{
rc::*,
+ tracing,
types::{
BaseStructure, MemberAccess, MemberScope, ReferenceType, StructureBuilder, StructureType,
Type, TypeClass,
@@ -26,8 +27,6 @@ use binaryninja::{
use gimli::{constants, AttributeValue, DebuggingInformationEntry, DwAt, Dwarf, Operation, Unit};
-use log::{debug, error, warn};
-
pub(crate) fn parse_variable<R: ReaderType>(
dwarf: &Dwarf<R>,
unit: &Unit<R>,
@@ -79,7 +78,7 @@ pub(crate) fn parse_variable<R: ReaderType>(
if let Ok(address) = dwarf.address(unit, index) {
debug_info_builder.add_data_variable(address, full_name, uid)
} else {
- warn!("Invalid index into IAT: {}", index.0);
+ tracing::warn!("Invalid index into IAT: {}", index.0);
}
}
}
@@ -96,11 +95,12 @@ pub(crate) fn parse_variable<R: ReaderType>(
);
}
Ok(op) => {
- debug!("Unhandled operation type for variable: {:?}", op);
+ tracing::debug!("Unhandled operation type for variable: {:?}", op);
}
- Err(e) => error!(
+ Err(e) => tracing::error!(
"Error parsing operation type for variable {:?}: {}",
- full_name, e
+ full_name,
+ e
),
}
}
@@ -191,14 +191,14 @@ fn do_structure_parse<R: ReaderType>(
let mut tree = match unit.entries_tree(Some(entry.offset())) {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to get structure entry tree: {}", e);
+ tracing::error!("Failed to get structure entry tree: {}", e);
return None;
}
};
let tree_root = match tree.root() {
Ok(x) => x,
Err(e) => {
- log::error!("Failed to get structure entry tree root: {}", e);
+ tracing::error!("Failed to get structure entry tree root: {}", e);
return None;
}
};
@@ -238,7 +238,7 @@ fn do_structure_parse<R: ReaderType>(
let Some(struct_offset_bytes) = get_attr_as_u64(&raw_struct_offset)
.or_else(|| get_expr_value(unit, raw_struct_offset))
else {
- log::warn!(
+ tracing::warn!(
"Failed to get DW_AT_data_member_location for offset {:#x} in unit {:?}",
child_entry.offset().0,
unit.header.offset()
@@ -323,7 +323,7 @@ fn do_structure_parse<R: ReaderType>(
debug_info_builder_context,
debug_info_builder,
) else {
- warn!("Failed to get base type for inheritance");
+ tracing::warn!("Failed to get base type for inheritance");
continue;
};
let Some(base_dbg_ty) = debug_info_builder.get_type(base_type_id) else {
@@ -334,7 +334,7 @@ fn do_structure_parse<R: ReaderType>(
let Ok(Some(raw_data_member_location)) =
child_entry.attr(constants::DW_AT_data_member_location)
else {
- warn!("Failed to get DW_AT_data_member_location for inheritance");
+ tracing::warn!("Failed to get DW_AT_data_member_location for inheritance");
continue;
};
@@ -405,7 +405,7 @@ pub(crate) fn get_type<R: ReaderType>(
let resolved_entry = match entry_unit.entry(entry_offset) {
Ok(x) => x,
Err(e) => {
- log::error!(
+ tracing::error!(
"Failed to resolve entry in unit {:?} at offset {:#x}: {}",
entry_unit.header.offset(),
entry_offset.0,
@@ -423,7 +423,7 @@ pub(crate) fn get_type<R: ReaderType>(
)
}
DieReference::Err => {
- warn!("Failed to fetch DIE when getting type through DW_AT_type. Debug information may be incomplete.");
+ tracing::warn!("Failed to fetch DIE when getting type through DW_AT_type. Debug information may be incomplete.");
None
}
}
@@ -440,7 +440,7 @@ pub(crate) fn get_type<R: ReaderType>(
let resolved_entry = match entry_unit.entry(entry_offset) {
Ok(x) => x,
Err(e) => {
- log::error!(
+ tracing::error!(
"Failed to resolve entry in unit {:?} at offset {:#x}: {}",
entry_unit.header.offset(),
entry_offset.0,
@@ -458,7 +458,7 @@ pub(crate) fn get_type<R: ReaderType>(
)
}
DieReference::Err => {
- warn!("Failed to fetch DIE when getting type through DW_AT_abstract_origin. Debug information may be incomplete.");
+ tracing::warn!("Failed to fetch DIE when getting type through DW_AT_abstract_origin. Debug information may be incomplete.");
None
}
}
@@ -472,7 +472,7 @@ pub(crate) fn get_type<R: ReaderType>(
let resolved_entry = match entry_unit.entry(entry_offset) {
Ok(x) => x,
Err(e) => {
- log::error!(
+ tracing::error!(
"Failed to resolve entry in unit {:?} at offset {:#x}: {}",
entry_unit.header.offset(),
entry_offset.0,
@@ -491,7 +491,7 @@ pub(crate) fn get_type<R: ReaderType>(
}
DieReference::UnitAndOffset(_) => None,
DieReference::Err => {
- warn!(
+ tracing::warn!(
"Failed to fetch DIE when getting type. Debug information may be incomplete."
);
None