@@ -432,17 +432,22 @@ pub(crate) fn download_debug_info(view: &BinaryView) -> Result<Ref<BinaryView>,
432432}
433433
434434
435- pub ( crate ) fn load_debug_info_for_build_id ( view : & BinaryView ) -> Result < Option < Ref < BinaryView > > , String > {
435+ pub ( crate ) fn find_local_debug_file ( view : & BinaryView ) -> Option < String > {
436436 let settings = Settings :: new ( "" ) ;
437437 let debug_info_paths = settings. get_string_list ( "analysis.debugInfo.debugDirectories" , Some ( view) , None ) ;
438+
438439 if debug_info_paths. is_empty ( ) {
439- return Ok ( None )
440+ return None
440441 }
441442
443+ let build_id = match get_build_id ( view) {
444+ Ok ( x) => x,
445+ Err ( _) => return None ,
446+ } ;
447+
442448 for debug_info_path in debug_info_paths. into_iter ( ) {
443449 if let Ok ( path) = PathBuf :: from_str ( & debug_info_path. to_string ( ) )
444450 {
445- let build_id = get_build_id ( view) ?;
446451 let elf_path = path
447452 . join ( & build_id[ ..2 ] )
448453 . join ( & build_id[ 2 ..] )
@@ -452,25 +457,36 @@ pub(crate) fn load_debug_info_for_build_id(view: &BinaryView) -> Result<Option<R
452457 . join ( & build_id[ ..2 ] )
453458 . join ( format ! ( "{}.debug" , & build_id[ 2 ..] ) ) ;
454459
455- let options = "{\" analysis.debugInfo.internal\" : false}" ;
456460 let final_path = if debug_ext_path. exists ( ) {
457461 debug_ext_path
458462 }
459463 else if elf_path. exists ( ) {
460464 elf_path
461465 }
462466 else {
463- // No paths exist
464- return Ok ( None )
467+ // No paths exist in this dir, try the next one
468+ continue ;
465469 } ;
466- return Ok (
467- binaryninja:: load_with_options (
468- final_path. to_string_lossy ( ) . to_string ( ) ,
469- false ,
470- Some ( options)
471- )
472- ) ;
470+ return final_path
471+ . to_str ( )
472+ . and_then ( |x| Some ( x. to_string ( ) ) ) ;
473473 }
474474 }
475- Ok ( None )
475+ None
476+ }
477+
478+
479+ pub ( crate ) fn load_debug_info_for_build_id ( view : & BinaryView ) -> Result < Option < Ref < BinaryView > > , String > {
480+ if let Some ( debug_file_path) = find_local_debug_file ( view) {
481+ Ok (
482+ binaryninja:: load_with_options (
483+ debug_file_path,
484+ false ,
485+ Some ( "{\" analysis.debugInfo.internal\" : false}" )
486+ )
487+ )
488+ }
489+ else {
490+ Ok ( None )
491+ }
476492}
0 commit comments