Skip to content

Commit 602df74

Browse files
committed
fmt
1 parent 0cace49 commit 602df74

33 files changed

+299
-271
lines changed

rust/examples/dwarf/dwarf_import/src/die_handlers.rs

+24-11
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,10 @@ pub(crate) fn handle_pointer<R: Reader<Offset = usize>>(
169169

170170
if let Some(pointer_size) = get_size_as_usize(entry) {
171171
if let Some(entry_type_offset) = entry_type {
172-
let parent_type = debug_info_builder.get_type(entry_type_offset).unwrap().get_type();
172+
let parent_type = debug_info_builder
173+
.get_type(entry_type_offset)
174+
.unwrap()
175+
.get_type();
173176
Some(Type::pointer_of_width(
174177
parent_type.as_ref(),
175178
pointer_size,
@@ -187,7 +190,10 @@ pub(crate) fn handle_pointer<R: Reader<Offset = usize>>(
187190
))
188191
}
189192
} else if let Some(entry_type_offset) = entry_type {
190-
let parent_type = debug_info_builder.get_type(entry_type_offset).unwrap().get_type();
193+
let parent_type = debug_info_builder
194+
.get_type(entry_type_offset)
195+
.unwrap()
196+
.get_type();
191197
Some(Type::pointer_of_width(
192198
parent_type.as_ref(),
193199
debug_info_builder_context.default_address_size(),
@@ -225,7 +231,10 @@ pub(crate) fn handle_array<R: Reader<Offset = usize>>(
225231
// For multidimensional arrays, DW_TAG_subrange_type or DW_TAG_enumeration_type
226232

227233
if let Some(entry_type_offset) = entry_type {
228-
let parent_type = debug_info_builder.get_type(entry_type_offset).unwrap().get_type();
234+
let parent_type = debug_info_builder
235+
.get_type(entry_type_offset)
236+
.unwrap()
237+
.get_type();
229238

230239
let mut tree = unit.entries_tree(Some(entry.offset())).unwrap();
231240
let mut children = tree.root().unwrap().children();
@@ -282,12 +291,10 @@ pub(crate) fn handle_function<R: Reader<Offset = usize>>(
282291
// or is otherwise DW_TAG_unspecified_parameters
283292

284293
let return_type = match entry_type {
285-
Some(entry_type_offset) => {
286-
debug_info_builder
287-
.get_type(entry_type_offset)
288-
.expect("Subroutine return type was not processed")
289-
.get_type()
290-
}
294+
Some(entry_type_offset) => debug_info_builder
295+
.get_type(entry_type_offset)
296+
.expect("Subroutine return type was not processed")
297+
.get_type(),
291298
None => Type::void(),
292299
};
293300

@@ -355,7 +362,10 @@ pub(crate) fn handle_const(
355362
// ?DW_AT_type
356363

357364
if let Some(entry_type_offset) = entry_type {
358-
let parent_type = debug_info_builder.get_type(entry_type_offset).unwrap().get_type();
365+
let parent_type = debug_info_builder
366+
.get_type(entry_type_offset)
367+
.unwrap()
368+
.get_type();
359369
Some((*parent_type).to_builder().set_const(true).finalize())
360370
} else {
361371
Some(TypeBuilder::void().set_const(true).finalize())
@@ -375,7 +385,10 @@ pub(crate) fn handle_volatile(
375385
// ?DW_AT_type
376386

377387
if let Some(entry_type_offset) = entry_type {
378-
let parent_type = debug_info_builder.get_type(entry_type_offset).unwrap().get_type();
388+
let parent_type = debug_info_builder
389+
.get_type(entry_type_offset)
390+
.unwrap()
391+
.get_type();
379392
Some((*parent_type).to_builder().set_volatile(true).finalize())
380393
} else {
381394
Some(TypeBuilder::void().set_volatile(true).finalize())

rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs

+50-32
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
use crate::helpers::{get_uid, resolve_specification, DieReference};
1616

1717
use binaryninja::{
18+
binaryninjacore_sys::BNVariableSourceType,
1819
binaryview::{BinaryView, BinaryViewBase, BinaryViewExt},
1920
debuginfo::{DebugFunctionInfo, DebugInfo},
2021
platform::Platform,
2122
rc::*,
2223
symbol::SymbolType,
2324
templatesimplifier::simplify_str_to_fqn,
2425
types::{Conf, FunctionParameter, NamedTypedVariable, Type, Variable},
25-
binaryninjacore_sys::BNVariableSourceType,
2626
};
2727

2828
use gimli::{DebuggingInformationEntry, Dwarf, Reader, Unit};
@@ -184,7 +184,7 @@ pub(crate) struct DebugInfoBuilder {
184184
full_function_name_indices: HashMap<String, usize>,
185185
types: HashMap<TypeUID, DebugType>,
186186
data_variables: HashMap<u64, (Option<String>, TypeUID)>,
187-
range_data_offsets: iset::IntervalMap<u64, i64>
187+
range_data_offsets: iset::IntervalMap<u64, i64>,
188188
}
189189

190190
impl DebugInfoBuilder {
@@ -218,10 +218,10 @@ impl DebugInfoBuilder {
218218
// TODO : Consider further falling back on address/architecture
219219

220220
/*
221-
If it has a raw_name and we know it, update it and return
222-
Else if it has a full_name and we know it, update it and return
223-
Else Add a new entry if we don't know the full_name or raw_name
224-
*/
221+
If it has a raw_name and we know it, update it and return
222+
Else if it has a full_name and we know it, update it and return
223+
Else Add a new entry if we don't know the full_name or raw_name
224+
*/
225225

226226
if let Some(ident) = &raw_name {
227227
// check if we already know about this raw name's index
@@ -232,20 +232,20 @@ impl DebugInfoBuilder {
232232
let function = self.functions.get_mut(*idx).unwrap();
233233

234234
if function.full_name.is_some() && function.full_name != full_name {
235-
self.full_function_name_indices.remove(function.full_name.as_ref().unwrap());
235+
self.full_function_name_indices
236+
.remove(function.full_name.as_ref().unwrap());
236237
}
237238

238239
function.update(full_name, raw_name, return_type, address, parameters);
239240

240-
if function.full_name.is_some() {
241-
self.full_function_name_indices.insert(function.full_name.clone().unwrap(), *idx);
241+
if function.full_name.is_some() {
242+
self.full_function_name_indices
243+
.insert(function.full_name.clone().unwrap(), *idx);
242244
}
243245

244246
return Some(*idx);
245247
}
246-
}
247-
248-
else if let Some(ident) = &full_name {
248+
} else if let Some(ident) = &full_name {
249249
// check if we already know about this full name's index
250250
// if we do, and the raw name will change, remove the known raw index if it exists
251251
// update the function
@@ -254,13 +254,15 @@ impl DebugInfoBuilder {
254254
let function = self.functions.get_mut(*idx).unwrap();
255255

256256
if function.raw_name.is_some() && function.raw_name != raw_name {
257-
self.raw_function_name_indices.remove(function.raw_name.as_ref().unwrap());
257+
self.raw_function_name_indices
258+
.remove(function.raw_name.as_ref().unwrap());
258259
}
259260

260261
function.update(full_name, raw_name, return_type, address, parameters);
261262

262-
if function.raw_name.is_some() {
263-
self.raw_function_name_indices.insert(function.raw_name.clone().unwrap(), *idx);
263+
if function.raw_name.is_some() {
264+
self.raw_function_name_indices
265+
.insert(function.raw_name.clone().unwrap(), *idx);
264266
}
265267

266268
return Some(*idx);
@@ -284,15 +286,17 @@ impl DebugInfoBuilder {
284286
};
285287

286288
if let Some(n) = &function.full_name {
287-
self.full_function_name_indices.insert(n.clone(), self.functions.len());
289+
self.full_function_name_indices
290+
.insert(n.clone(), self.functions.len());
288291
}
289292

290293
if let Some(n) = &function.raw_name {
291-
self.raw_function_name_indices.insert(n.clone(), self.functions.len());
294+
self.raw_function_name_indices
295+
.insert(n.clone(), self.functions.len());
292296
}
293297

294298
self.functions.push(function);
295-
Some(self.functions.len()-1)
299+
Some(self.functions.len() - 1)
296300
}
297301

298302
pub(crate) fn functions(&self) -> &[FunctionInfoBuilder] {
@@ -303,7 +307,13 @@ impl DebugInfoBuilder {
303307
self.types.values()
304308
}
305309

306-
pub(crate) fn add_type(&mut self, type_uid: TypeUID, name: &String, t: Ref<Type>, commit: bool) {
310+
pub(crate) fn add_type(
311+
&mut self,
312+
type_uid: TypeUID,
313+
name: &String,
314+
t: Ref<Type>,
315+
commit: bool,
316+
) {
307317
if let Some(DebugType {
308318
name: existing_name,
309319
t: existing_type,
@@ -339,7 +349,6 @@ impl DebugInfoBuilder {
339349
self.types.contains_key(&type_uid)
340350
}
341351

342-
343352
pub(crate) fn add_stack_variable(
344353
&mut self,
345354
fn_idx: Option<usize>,
@@ -352,11 +361,10 @@ impl DebugInfoBuilder {
352361
if x.len() == 1 && x.chars().next() == Some('\x00') {
353362
// Anonymous variable, generate name
354363
format!("debug_var_{}", offset)
355-
}
356-
else {
364+
} else {
357365
x
358366
}
359-
},
367+
}
360368
None => {
361369
// Anonymous variable, generate name
362370
format!("debug_var_{}", offset)
@@ -365,14 +373,16 @@ impl DebugInfoBuilder {
365373

366374
let Some(function_index) = fn_idx else {
367375
// If we somehow lost track of what subprogram we're in or we're not actually in a subprogram
368-
error!("Trying to add a local variable outside of a subprogram. Please report this issue.");
376+
error!(
377+
"Trying to add a local variable outside of a subprogram. Please report this issue."
378+
);
369379
return;
370380
};
371381

372382
// Either get the known type or use a 0 confidence void type so we at least get the name applied
373383
let t = match type_uid {
374384
Some(uid) => Conf::new(self.get_type(uid).unwrap().get_type(), 128),
375-
None => Conf::new(Type::void(), 0)
385+
None => Conf::new(Type::void(), 0),
376386
};
377387
let function = &mut self.functions[function_index];
378388

@@ -384,7 +394,8 @@ impl DebugInfoBuilder {
384394
return;
385395
};
386396

387-
let Some(offset_adjustment) = self.range_data_offsets.values_overlap(func_addr).next() else {
397+
let Some(offset_adjustment) = self.range_data_offsets.values_overlap(func_addr).next()
398+
else {
388399
// Unknown why, but this is happening with MachO + external dSYM
389400
debug!("Refusing to add a local variable ({}@{}) to function at {} without a known CIE offset.", name, offset, func_addr);
390401
return;
@@ -398,9 +409,14 @@ impl DebugInfoBuilder {
398409
return;
399410
}
400411

401-
let var = Variable::new(BNVariableSourceType::StackVariableSourceType, 0, adjusted_offset);
402-
function.stack_variables.push(NamedTypedVariable::new(var, name, t, false));
403-
412+
let var = Variable::new(
413+
BNVariableSourceType::StackVariableSourceType,
414+
0,
415+
adjusted_offset,
416+
);
417+
function
418+
.stack_variables
419+
.push(NamedTypedVariable::new(var, name, t, false));
404420
}
405421

406422
pub(crate) fn add_data_variable(
@@ -448,7 +464,9 @@ impl DebugInfoBuilder {
448464

449465
fn get_function_type(&self, function: &FunctionInfoBuilder) -> Ref<Type> {
450466
let return_type = match function.return_type {
451-
Some(return_type_id) => Conf::new(self.get_type(return_type_id).unwrap().get_type(), 128),
467+
Some(return_type_id) => {
468+
Conf::new(self.get_type(return_type_id).unwrap().get_type(), 128)
469+
}
452470
_ => Conf::new(binaryninja::types::Type::void(), 0),
453471
};
454472

@@ -480,7 +498,7 @@ impl DebugInfoBuilder {
480498
Some(self.get_function_type(function)),
481499
function.address,
482500
function.platform.clone(),
483-
vec![], // TODO : Components
501+
vec![], // TODO : Components
484502
function.stack_variables.clone(), // TODO: local non-stack variables
485503
));
486504
}
@@ -520,7 +538,7 @@ impl DebugInfoBuilder {
520538

521539
if let Some(address) = func.address.as_mut() {
522540
let diff = bv.start() - bv.original_base();
523-
*address += diff; // rebase the address
541+
*address += diff; // rebase the address
524542
let existing_functions = bv.functions_at(*address);
525543
match existing_functions.len().cmp(&1) {
526544
Ordering::Greater => {

rust/examples/dwarf/dwarf_import/src/functions.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ pub(crate) fn parse_function_entry<R: Reader<Offset = usize>>(
8080
let raw_name = get_raw_name(unit, entry, debug_info_builder_context);
8181
let return_type = get_type(unit, entry, debug_info_builder_context, debug_info_builder);
8282
let address = get_start_address(unit, entry, debug_info_builder_context);
83-
let (parameters, variable_arguments) = get_parameters(unit, entry, debug_info_builder_context, debug_info_builder);
83+
let (parameters, variable_arguments) =
84+
get_parameters(unit, entry, debug_info_builder_context, debug_info_builder);
8485

8586
// If we have a raw name, it might be mangled, see if we can demangle it into full_name
8687
// raw_name should contain a superset of the info we have in full_name
@@ -96,9 +97,7 @@ pub(crate) fn parse_function_entry<R: Reader<Offset = usize>>(
9697
});
9798

9899
static ABI_REGEX_MEM: OnceLock<Regex> = OnceLock::new();
99-
let abi_regex = ABI_REGEX_MEM.get_or_init(|| {
100-
Regex::new(r"\[abi:v\d+\]").unwrap()
101-
});
100+
let abi_regex = ABI_REGEX_MEM.get_or_init(|| Regex::new(r"\[abi:v\d+\]").unwrap());
102101
if let Ok(sym) = cpp_demangle::Symbol::new(possibly_mangled_name) {
103102
if let Ok(demangled) = sym.demangle(demangle_options) {
104103
let cleaned = abi_regex.replace_all(&demangled, "");
@@ -114,5 +113,12 @@ pub(crate) fn parse_function_entry<R: Reader<Offset = usize>>(
114113
full_name = debug_info_builder_context.get_name(unit, entry)
115114
}
116115

117-
debug_info_builder.insert_function(full_name, raw_name, return_type, address, &parameters, variable_arguments)
116+
debug_info_builder.insert_function(
117+
full_name,
118+
raw_name,
119+
return_type,
120+
address,
121+
&parameters,
122+
variable_arguments,
123+
)
118124
}

0 commit comments

Comments
 (0)