12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- use crate :: { helpers:: { get_uid, resolve_specification, DieReference } , ReaderType } ;
15
+ use crate :: {
16
+ helpers:: { get_uid, resolve_specification, DieReference } ,
17
+ ReaderType ,
18
+ } ;
16
19
17
20
use binaryninja:: {
21
+ binaryninjacore_sys:: BNVariableSourceType ,
18
22
binaryview:: { BinaryView , BinaryViewBase , BinaryViewExt } ,
19
23
debuginfo:: { DebugFunctionInfo , DebugInfo } ,
20
24
platform:: Platform ,
@@ -120,7 +124,6 @@ pub(crate) struct DebugInfoBuilderContext<R: ReaderType> {
120
124
121
125
impl < R : ReaderType > DebugInfoBuilderContext < R > {
122
126
pub ( crate ) fn new ( view : & BinaryView , dwarf : & Dwarf < R > ) -> Option < Self > {
123
-
124
127
let mut units = vec ! [ ] ;
125
128
let mut iter = dwarf. units ( ) ;
126
129
while let Ok ( Some ( header) ) = iter. next ( ) {
@@ -200,7 +203,7 @@ pub(crate) struct DebugInfoBuilder {
200
203
full_function_name_indices : HashMap < String , usize > ,
201
204
types : HashMap < TypeUID , DebugType > ,
202
205
data_variables : HashMap < u64 , ( Option < String > , TypeUID ) > ,
203
- range_data_offsets : iset:: IntervalMap < u64 , i64 >
206
+ range_data_offsets : iset:: IntervalMap < u64 , i64 > ,
204
207
}
205
208
206
209
impl DebugInfoBuilder {
@@ -234,10 +237,10 @@ impl DebugInfoBuilder {
234
237
// TODO : Consider further falling back on address/architecture
235
238
236
239
/*
237
- If it has a raw_name and we know it, update it and return
238
- Else if it has a full_name and we know it, update it and return
239
- Else Add a new entry if we don't know the full_name or raw_name
240
- */
240
+ If it has a raw_name and we know it, update it and return
241
+ Else if it has a full_name and we know it, update it and return
242
+ Else Add a new entry if we don't know the full_name or raw_name
243
+ */
241
244
242
245
if let Some ( ident) = & raw_name {
243
246
// check if we already know about this raw name's index
@@ -248,20 +251,20 @@ impl DebugInfoBuilder {
248
251
let function = self . functions . get_mut ( * idx) . unwrap ( ) ;
249
252
250
253
if function. full_name . is_some ( ) && function. full_name != full_name {
251
- self . full_function_name_indices . remove ( function. full_name . as_ref ( ) . unwrap ( ) ) ;
254
+ self . full_function_name_indices
255
+ . remove ( function. full_name . as_ref ( ) . unwrap ( ) ) ;
252
256
}
253
257
254
258
function. update ( full_name, raw_name, return_type, address, parameters) ;
255
259
256
- if function. full_name . is_some ( ) {
257
- self . full_function_name_indices . insert ( function. full_name . clone ( ) . unwrap ( ) , * idx) ;
260
+ if function. full_name . is_some ( ) {
261
+ self . full_function_name_indices
262
+ . insert ( function. full_name . clone ( ) . unwrap ( ) , * idx) ;
258
263
}
259
264
260
265
return Some ( * idx) ;
261
266
}
262
- }
263
-
264
- else if let Some ( ident) = & full_name {
267
+ } else if let Some ( ident) = & full_name {
265
268
// check if we already know about this full name's index
266
269
// if we do, and the raw name will change, remove the known raw index if it exists
267
270
// update the function
@@ -270,13 +273,15 @@ impl DebugInfoBuilder {
270
273
let function = self . functions . get_mut ( * idx) . unwrap ( ) ;
271
274
272
275
if function. raw_name . is_some ( ) && function. raw_name != raw_name {
273
- self . raw_function_name_indices . remove ( function. raw_name . as_ref ( ) . unwrap ( ) ) ;
276
+ self . raw_function_name_indices
277
+ . remove ( function. raw_name . as_ref ( ) . unwrap ( ) ) ;
274
278
}
275
279
276
280
function. update ( full_name, raw_name, return_type, address, parameters) ;
277
281
278
- if function. raw_name . is_some ( ) {
279
- self . raw_function_name_indices . insert ( function. raw_name . clone ( ) . unwrap ( ) , * idx) ;
282
+ if function. raw_name . is_some ( ) {
283
+ self . raw_function_name_indices
284
+ . insert ( function. raw_name . clone ( ) . unwrap ( ) , * idx) ;
280
285
}
281
286
282
287
return Some ( * idx) ;
@@ -300,15 +305,17 @@ impl DebugInfoBuilder {
300
305
} ;
301
306
302
307
if let Some ( n) = & function. full_name {
303
- self . full_function_name_indices . insert ( n. clone ( ) , self . functions . len ( ) ) ;
308
+ self . full_function_name_indices
309
+ . insert ( n. clone ( ) , self . functions . len ( ) ) ;
304
310
}
305
311
306
312
if let Some ( n) = & function. raw_name {
307
- self . raw_function_name_indices . insert ( n. clone ( ) , self . functions . len ( ) ) ;
313
+ self . raw_function_name_indices
314
+ . insert ( n. clone ( ) , self . functions . len ( ) ) ;
308
315
}
309
316
310
317
self . functions . push ( function) ;
311
- Some ( self . functions . len ( ) - 1 )
318
+ Some ( self . functions . len ( ) - 1 )
312
319
}
313
320
314
321
pub ( crate ) fn functions ( & self ) -> & [ FunctionInfoBuilder ] {
@@ -319,7 +326,13 @@ impl DebugInfoBuilder {
319
326
self . types . values ( )
320
327
}
321
328
322
- pub ( crate ) fn add_type ( & mut self , type_uid : TypeUID , name : & String , t : Ref < Type > , commit : bool ) {
329
+ pub ( crate ) fn add_type (
330
+ & mut self ,
331
+ type_uid : TypeUID ,
332
+ name : & String ,
333
+ t : Ref < Type > ,
334
+ commit : bool ,
335
+ ) {
323
336
if let Some ( DebugType {
324
337
name : existing_name,
325
338
t : existing_type,
@@ -355,7 +368,6 @@ impl DebugInfoBuilder {
355
368
self . types . contains_key ( & type_uid)
356
369
}
357
370
358
-
359
371
pub ( crate ) fn add_stack_variable (
360
372
& mut self ,
361
373
fn_idx : Option < usize > ,
@@ -368,11 +380,10 @@ impl DebugInfoBuilder {
368
380
if x. len ( ) == 1 && x. chars ( ) . next ( ) == Some ( '\x00' ) {
369
381
// Anonymous variable, generate name
370
382
format ! ( "debug_var_{}" , offset)
371
- }
372
- else {
383
+ } else {
373
384
x
374
385
}
375
- } ,
386
+ }
376
387
None => {
377
388
// Anonymous variable, generate name
378
389
format ! ( "debug_var_{}" , offset)
@@ -381,14 +392,16 @@ impl DebugInfoBuilder {
381
392
382
393
let Some ( function_index) = fn_idx else {
383
394
// If we somehow lost track of what subprogram we're in or we're not actually in a subprogram
384
- error ! ( "Trying to add a local variable outside of a subprogram. Please report this issue." ) ;
395
+ error ! (
396
+ "Trying to add a local variable outside of a subprogram. Please report this issue."
397
+ ) ;
385
398
return ;
386
399
} ;
387
400
388
401
// Either get the known type or use a 0 confidence void type so we at least get the name applied
389
402
let t = match type_uid {
390
403
Some ( uid) => Conf :: new ( self . get_type ( uid) . unwrap ( ) . get_type ( ) , 128 ) ,
391
- None => Conf :: new ( Type :: void ( ) , 0 )
404
+ None => Conf :: new ( Type :: void ( ) , 0 ) ,
392
405
} ;
393
406
let function = & mut self . functions [ function_index] ;
394
407
@@ -400,7 +413,8 @@ impl DebugInfoBuilder {
400
413
return ;
401
414
} ;
402
415
403
- let Some ( offset_adjustment) = self . range_data_offsets . values_overlap ( func_addr) . next ( ) else {
416
+ let Some ( offset_adjustment) = self . range_data_offsets . values_overlap ( func_addr) . next ( )
417
+ else {
404
418
// Unknown why, but this is happening with MachO + external dSYM
405
419
debug ! ( "Refusing to add a local variable ({}@{}) to function at {} without a known CIE offset." , name, offset, func_addr) ;
406
420
return ;
@@ -414,9 +428,14 @@ impl DebugInfoBuilder {
414
428
return ;
415
429
}
416
430
417
- let var = Variable :: new ( VariableSourceType :: StackVariableSourceType , 0 , adjusted_offset) ;
418
- function. stack_variables . push ( NamedTypedVariable :: new ( var, name, t, false ) ) ;
419
-
431
+ let var = Variable :: new (
432
+ VariableSourceType :: StackVariableSourceType ,
433
+ 0 ,
434
+ adjusted_offset,
435
+ ) ;
436
+ function
437
+ . stack_variables
438
+ . push ( NamedTypedVariable :: new ( var, name, t, false ) ) ;
420
439
}
421
440
422
441
pub ( crate ) fn add_data_variable (
@@ -464,7 +483,9 @@ impl DebugInfoBuilder {
464
483
465
484
fn get_function_type ( & self , function : & FunctionInfoBuilder ) -> Ref < Type > {
466
485
let return_type = match function. return_type {
467
- Some ( return_type_id) => Conf :: new ( self . get_type ( return_type_id) . unwrap ( ) . get_type ( ) , 128 ) ,
486
+ Some ( return_type_id) => {
487
+ Conf :: new ( self . get_type ( return_type_id) . unwrap ( ) . get_type ( ) , 128 )
488
+ }
468
489
_ => Conf :: new ( binaryninja:: types:: Type :: void ( ) , 0 ) ,
469
490
} ;
470
491
@@ -496,7 +517,7 @@ impl DebugInfoBuilder {
496
517
Some ( self . get_function_type ( function) ) ,
497
518
function. address ,
498
519
function. platform . clone ( ) ,
499
- vec ! [ ] , // TODO : Components
520
+ vec ! [ ] , // TODO : Components
500
521
function. stack_variables . clone ( ) , // TODO: local non-stack variables
501
522
) ) ;
502
523
}
@@ -536,7 +557,7 @@ impl DebugInfoBuilder {
536
557
537
558
if let Some ( address) = func. address . as_mut ( ) {
538
559
let diff = bv. start ( ) - bv. original_image_base ( ) ;
539
- * address += diff; // rebase the address
560
+ * address += diff; // rebase the address
540
561
let existing_functions = bv. functions_at ( * address) ;
541
562
match existing_functions. len ( ) . cmp ( & 1 ) {
542
563
Ordering :: Greater => {
0 commit comments