Skip to content

Commit

Permalink
Use the path of the original file to find the debuglink destination
Browse files Browse the repository at this point in the history
  • Loading branch information
zecakeh authored and mstange committed Mar 25, 2023
1 parent cba4e89 commit 2a73d11
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion samply-symbols/src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions samply-symbols/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Self::FL>> {
Ok(Vec::new())
Expand Down
36 changes: 23 additions & 13 deletions wholesym/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use uuid::Uuid;

use std::{
collections::HashMap,
fs::File,
fs::{self, File},
path::{Path, PathBuf},
pin::Pin,
sync::{Arc, Mutex},
Expand Down Expand Up @@ -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<Vec<WholesymFileLocation>> {
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),
),
])
}

Expand Down

0 comments on commit 2a73d11

Please sign in to comment.