Skip to content

Commit eb09898

Browse files
committed
Add support for automatically loading PDB/DWARF info from sibling files in projects
1 parent 55b35df commit eb09898

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

plugins/dwarf/dwarf_import/src/helpers.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,35 @@ pub(crate) fn find_sibling_debug_file(view: &BinaryView) -> Option<String> {
577577

578578
let debug_file = PathBuf::from(format!("{}.debug", full_file_path));
579579
let dsym_folder = PathBuf::from(format!("{}.dSYM", full_file_path));
580+
581+
// Find sibling debug file
580582
if debug_file.exists() && debug_file.is_file() {
581583
return Some(debug_file.to_string_lossy().to_string());
582584
}
583585

586+
// Find sibling debug file in project
587+
if let Some(debug_file_name) = debug_file.file_name() {
588+
if let Some(project_file) = view.file().project_file() {
589+
let project_file_folder_id = project_file.folder().map(|x| x.id());
590+
for file in project_file.project().files().iter() {
591+
if !file.exists_on_disk() {
592+
// If the file doesn't exist, don't consider it
593+
// TODO: if we're connected to a remote project, offer to download the file
594+
continue;
595+
}
596+
597+
let file_folder_id = file.folder().map(|x| x.id());
598+
if *file.name() == *debug_file_name && file_folder_id == project_file_folder_id {
599+
if let Some(path_on_disk) = file.path_on_disk() {
600+
return path_on_disk.to_str().map(|x| x.to_string());
601+
}
602+
}
603+
}
604+
}
605+
}
606+
607+
// Look for dSYM
608+
// TODO: look for dSYM in project
584609
if dsym_folder.exists() && dsym_folder.is_dir() {
585610
let filename = Path::new(&full_file_path)
586611
.file_name()

plugins/pdb-ng/src/lib.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,11 +614,7 @@ impl CustomDebugInfoParser for PDBParser {
614614
potential_path.pop();
615615
potential_path.push(&info.file_name);
616616
if potential_path.exists() {
617-
match fs::read(
618-
potential_path
619-
.to_str()
620-
.expect("Potential path is a real string"),
621-
) {
617+
match fs::read(potential_path) {
622618
Ok(conts) => match self
623619
.load_from_file(&conts, debug_info, view, &progress, true, false)
624620
{
@@ -631,6 +627,35 @@ impl CustomDebugInfoParser for PDBParser {
631627
}
632628
}
633629

630+
// Try in the same folder in the project
631+
if let Some(project_file) = view.file().project_file() {
632+
let project_file_folder_id = project_file.folder().map(|x| x.id());
633+
for file in project_file.project().files().iter() {
634+
let file_folder_id = file.folder().map(|x| x.id());
635+
if file.name() == info.file_name && file_folder_id == project_file_folder_id {
636+
if !file.exists_on_disk() {
637+
// If the file doesn't exist, don't consider it
638+
// TODO: if we're connected to a remote project, offer to download the file
639+
continue;
640+
}
641+
642+
if let Some(path_on_disk) = file.path_on_disk() {
643+
match fs::read(path_on_disk) {
644+
Ok(conts) => match self.load_from_file(
645+
&conts, debug_info, view, &progress, true, false,
646+
) {
647+
Ok(_) => return true,
648+
Err(e) if e.to_string() == "Cancelled" => return false,
649+
Err(e) => debug!("Skipping, {}", e.to_string()),
650+
},
651+
Err(e) if e.to_string() == "Cancelled" => return false,
652+
Err(e) => debug!("Could not read pdb: {}", e.to_string()),
653+
}
654+
}
655+
}
656+
}
657+
}
658+
634659
// Check the local symbol store
635660
if let Ok(local_store_path) = active_local_cache(Some(view)) {
636661
match search_sym_store(view, local_store_path.clone(), &info) {

0 commit comments

Comments
 (0)