diff options
| author | Josh Ferrell <josh@vector35.com> | 2025-11-18 17:08:31 -0500 |
|---|---|---|
| committer | Josh Ferrell <josh@vector35.com> | 2025-11-19 14:30:26 -0500 |
| commit | 69c3f09695b329e6b6794f10f70e13f4e5956596 (patch) | |
| tree | 3f3d3ed128b8a020209992bd664023961058669f /plugins/dwarf/dwarf_import/src/helpers.rs | |
| parent | b7a8df1318c5b0b007dc7f674d99be9af85c0234 (diff) | |
Allow loading supplementary dwarf debug info from path in .gnu_debugaltlink
Diffstat (limited to 'plugins/dwarf/dwarf_import/src/helpers.rs')
| -rw-r--r-- | plugins/dwarf/dwarf_import/src/helpers.rs | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/plugins/dwarf/dwarf_import/src/helpers.rs b/plugins/dwarf/dwarf_import/src/helpers.rs index b13d9860..8ef51f2f 100644 --- a/plugins/dwarf/dwarf_import/src/helpers.rs +++ b/plugins/dwarf/dwarf_import/src/helpers.rs @@ -521,10 +521,16 @@ pub(crate) fn download_debug_info( Err("Could not find a server with debug info for this file".to_string()) } -pub(crate) fn find_local_debug_file_for_build_id( - build_id: &str, - view: &BinaryView, -) -> Option<String> { +pub(crate) fn find_local_debug_file_from_path(path: &PathBuf, view: &BinaryView) -> Option<String> { + // Search debug directories for path (or None if setting disabled/empty), return the first one that exists + // TODO: put absolute paths behind setting? + if path.is_absolute() { + if !path.exists() { + return None; + } + return path.to_str().map(|s| s.to_string()); + } + let mut settings_query_opts = QueryOptions::new_with_view(view); let settings = Settings::new(); let debug_dirs_enabled = settings.get_bool_with_opts( @@ -541,29 +547,27 @@ pub(crate) fn find_local_debug_file_for_build_id( &mut settings_query_opts, ); - if debug_info_paths.is_empty() { - return None; + for debug_info_path in debug_info_paths.into_iter() { + let final_path = PathBuf::from(debug_info_path).join(path); + if final_path.exists() { + return final_path.to_str().map(|s| s.to_string()); + } } + None +} - for debug_info_path in debug_info_paths.into_iter() { - let path = PathBuf::from(debug_info_path); - let elf_path = path.join(&build_id[..2]).join(&build_id[2..]).join("elf"); +pub(crate) fn find_local_debug_file_for_build_id( + build_id: &str, + view: &BinaryView, +) -> Option<String> { + let debug_ext_path = PathBuf::from(&build_id[..2]).join(format!("{}.debug", &build_id[2..])); - let debug_ext_path = path - .join(&build_id[..2]) - .join(format!("{}.debug", &build_id[2..])); + let elf_path = PathBuf::from(&build_id[..2]) + .join(&build_id[2..]) + .join("elf"); - let final_path = if debug_ext_path.exists() { - debug_ext_path - } else if elf_path.exists() { - elf_path - } else { - // No paths exist in this dir, try the next one - continue; - }; - return final_path.to_str().and_then(|x| Some(x.to_string())); - } - None + find_local_debug_file_from_path(&debug_ext_path, view) + .or_else(|| find_local_debug_file_from_path(&elf_path, view)) } pub(crate) fn load_debug_info_for_build_id( @@ -579,7 +583,7 @@ pub(crate) fn load_debug_info_for_build_id( false, Some("{\"analysis.debugInfo.internal\": false}"), ), - false, + true, ); } else if settings.get_bool_with_opts("network.enableDebuginfod", &mut settings_query_opts) { return (download_debug_info(build_id, view).ok(), true); |
