15
15
use crate :: helpers:: { get_uid, resolve_specification, DieReference } ;
16
16
17
17
use binaryninja:: {
18
+ binaryninjacore_sys:: BNVariableSourceType ,
18
19
binaryview:: { BinaryView , BinaryViewBase , BinaryViewExt } ,
19
20
debuginfo:: { DebugFunctionInfo , DebugInfo } ,
20
21
platform:: Platform ,
21
22
rc:: * ,
22
23
symbol:: SymbolType ,
23
24
templatesimplifier:: simplify_str_to_fqn,
24
25
types:: { Conf , FunctionParameter , NamedTypedVariable , Type , Variable } ,
25
- binaryninjacore_sys:: BNVariableSourceType ,
26
26
} ;
27
27
28
28
use gimli:: { DebuggingInformationEntry , Dwarf , Reader , Unit } ;
@@ -184,7 +184,7 @@ pub(crate) struct DebugInfoBuilder {
184
184
full_function_name_indices : HashMap < String , usize > ,
185
185
types : HashMap < TypeUID , DebugType > ,
186
186
data_variables : HashMap < u64 , ( Option < String > , TypeUID ) > ,
187
- range_data_offsets : iset:: IntervalMap < u64 , i64 >
187
+ range_data_offsets : iset:: IntervalMap < u64 , i64 > ,
188
188
}
189
189
190
190
impl DebugInfoBuilder {
@@ -218,10 +218,10 @@ impl DebugInfoBuilder {
218
218
// TODO : Consider further falling back on address/architecture
219
219
220
220
/*
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
+ */
225
225
226
226
if let Some ( ident) = & raw_name {
227
227
// check if we already know about this raw name's index
@@ -232,20 +232,20 @@ impl DebugInfoBuilder {
232
232
let function = self . functions . get_mut ( * idx) . unwrap ( ) ;
233
233
234
234
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 ( ) ) ;
236
237
}
237
238
238
239
function. update ( full_name, raw_name, return_type, address, parameters) ;
239
240
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) ;
242
244
}
243
245
244
246
return Some ( * idx) ;
245
247
}
246
- }
247
-
248
- else if let Some ( ident) = & full_name {
248
+ } else if let Some ( ident) = & full_name {
249
249
// check if we already know about this full name's index
250
250
// if we do, and the raw name will change, remove the known raw index if it exists
251
251
// update the function
@@ -254,13 +254,15 @@ impl DebugInfoBuilder {
254
254
let function = self . functions . get_mut ( * idx) . unwrap ( ) ;
255
255
256
256
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 ( ) ) ;
258
259
}
259
260
260
261
function. update ( full_name, raw_name, return_type, address, parameters) ;
261
262
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) ;
264
266
}
265
267
266
268
return Some ( * idx) ;
@@ -284,15 +286,17 @@ impl DebugInfoBuilder {
284
286
} ;
285
287
286
288
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 ( ) ) ;
288
291
}
289
292
290
293
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 ( ) ) ;
292
296
}
293
297
294
298
self . functions . push ( function) ;
295
- Some ( self . functions . len ( ) - 1 )
299
+ Some ( self . functions . len ( ) - 1 )
296
300
}
297
301
298
302
pub ( crate ) fn functions ( & self ) -> & [ FunctionInfoBuilder ] {
@@ -303,7 +307,13 @@ impl DebugInfoBuilder {
303
307
self . types . values ( )
304
308
}
305
309
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
+ ) {
307
317
if let Some ( DebugType {
308
318
name : existing_name,
309
319
t : existing_type,
@@ -339,7 +349,6 @@ impl DebugInfoBuilder {
339
349
self . types . contains_key ( & type_uid)
340
350
}
341
351
342
-
343
352
pub ( crate ) fn add_stack_variable (
344
353
& mut self ,
345
354
fn_idx : Option < usize > ,
@@ -352,11 +361,10 @@ impl DebugInfoBuilder {
352
361
if x. len ( ) == 1 && x. chars ( ) . next ( ) == Some ( '\x00' ) {
353
362
// Anonymous variable, generate name
354
363
format ! ( "debug_var_{}" , offset)
355
- }
356
- else {
364
+ } else {
357
365
x
358
366
}
359
- } ,
367
+ }
360
368
None => {
361
369
// Anonymous variable, generate name
362
370
format ! ( "debug_var_{}" , offset)
@@ -365,14 +373,16 @@ impl DebugInfoBuilder {
365
373
366
374
let Some ( function_index) = fn_idx else {
367
375
// 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
+ ) ;
369
379
return ;
370
380
} ;
371
381
372
382
// Either get the known type or use a 0 confidence void type so we at least get the name applied
373
383
let t = match type_uid {
374
384
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 ) ,
376
386
} ;
377
387
let function = & mut self . functions [ function_index] ;
378
388
@@ -384,7 +394,8 @@ impl DebugInfoBuilder {
384
394
return ;
385
395
} ;
386
396
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 {
388
399
// Unknown why, but this is happening with MachO + external dSYM
389
400
debug ! ( "Refusing to add a local variable ({}@{}) to function at {} without a known CIE offset." , name, offset, func_addr) ;
390
401
return ;
@@ -398,9 +409,14 @@ impl DebugInfoBuilder {
398
409
return ;
399
410
}
400
411
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 ) ) ;
404
420
}
405
421
406
422
pub ( crate ) fn add_data_variable (
@@ -448,7 +464,9 @@ impl DebugInfoBuilder {
448
464
449
465
fn get_function_type ( & self , function : & FunctionInfoBuilder ) -> Ref < Type > {
450
466
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
+ }
452
470
_ => Conf :: new ( binaryninja:: types:: Type :: void ( ) , 0 ) ,
453
471
} ;
454
472
@@ -480,7 +498,7 @@ impl DebugInfoBuilder {
480
498
Some ( self . get_function_type ( function) ) ,
481
499
function. address ,
482
500
function. platform . clone ( ) ,
483
- vec ! [ ] , // TODO : Components
501
+ vec ! [ ] , // TODO : Components
484
502
function. stack_variables . clone ( ) , // TODO: local non-stack variables
485
503
) ) ;
486
504
}
@@ -520,7 +538,7 @@ impl DebugInfoBuilder {
520
538
521
539
if let Some ( address) = func. address . as_mut ( ) {
522
540
let diff = bv. start ( ) - bv. original_base ( ) ;
523
- * address += diff; // rebase the address
541
+ * address += diff; // rebase the address
524
542
let existing_functions = bv. functions_at ( * address) ;
525
543
match existing_functions. len ( ) . cmp ( & 1 ) {
526
544
Ordering :: Greater => {
0 commit comments