From 2a73d11860b98486f188b6010713930277d9886a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sat, 25 Mar 2023 17:51:33 +0100 Subject: [PATCH] Use the path of the original file to find the debuglink destination --- samply-symbols/src/elf.rs | 2 +- samply-symbols/src/shared.rs | 1 + wholesym/src/helper.rs | 36 +++++++++++++++++++++++------------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/samply-symbols/src/elf.rs b/samply-symbols/src/elf.rs index 557b8368..538c6cf7 100644 --- a/samply-symbols/src/elf.rs +++ b/samply-symbols/src/elf.rs @@ -65,7 +65,7 @@ where let debug_id = debug_id_for_object(elf_file)?; let name = std::str::from_utf8(name).ok()?; let candidate_paths = helper - .get_candidate_paths_for_gnu_debug_link_dest(name) + .get_candidate_paths_for_gnu_debug_link_dest(original_file_location, name) .ok()?; for candidate_path in candidate_paths { diff --git a/samply-symbols/src/shared.rs b/samply-symbols/src/shared.rs index ab32e5f1..5c22d479 100644 --- a/samply-symbols/src/shared.rs +++ b/samply-symbols/src/shared.rs @@ -320,6 +320,7 @@ pub trait FileAndPathHelper<'h> { /// TODO fn get_candidate_paths_for_gnu_debug_link_dest( &self, + _original_file_location: &Self::FL, _debug_link_name: &str, ) -> FileAndPathHelperResult> { Ok(Vec::new()) diff --git a/wholesym/src/helper.rs b/wholesym/src/helper.rs index 9a2abd54..a7344358 100644 --- a/wholesym/src/helper.rs +++ b/wholesym/src/helper.rs @@ -12,7 +12,7 @@ use uuid::Uuid; use std::{ collections::HashMap, - fs::File, + fs::{self, File}, path::{Path, PathBuf}, pin::Pin, sync::{Arc, Mutex}, @@ -619,22 +619,32 @@ impl<'h> FileAndPathHelper<'h> for Helper { fn get_candidate_paths_for_gnu_debug_link_dest( &self, + original_file_location: &WholesymFileLocation, debug_link_name: &str, ) -> FileAndPathHelperResult> { + let absolute_original_file_parent = match original_file_location { + WholesymFileLocation::LocalFile(path) => { + let parent = path + .parent() + .ok_or("Original file should point to a file")?; + fs::canonicalize(parent)? + } + _ => return Err("Only local files have a .gnu_debuglink".into()), + }; + // https://www-zeuthen.desy.de/unix/unixguide/infohtml/gdb/Separate-Debug-Files.html Ok(vec![ - WholesymFileLocation::LocalFile(PathBuf::from(format!( - "/usr/bin/{}.debug", - &debug_link_name - ))), - WholesymFileLocation::LocalFile(PathBuf::from(format!( - "/usr/bin/.debug/{}.debug", - &debug_link_name - ))), - WholesymFileLocation::LocalFile(PathBuf::from(format!( - "/usr/lib/debug/usr/bin/{}.debug", - &debug_link_name - ))), + WholesymFileLocation::LocalFile(absolute_original_file_parent.join(debug_link_name)), + WholesymFileLocation::LocalFile( + absolute_original_file_parent + .join(".debug") + .join(debug_link_name), + ), + WholesymFileLocation::LocalFile( + Path::new("/usr/lib/debug") + .join(absolute_original_file_parent.strip_prefix("/")?) + .join(debug_link_name), + ), ]) }