Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the path of the original file to find the debuglink destination #38

Merged
merged 1 commit into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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