Skip to content
Merged
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
28 changes: 15 additions & 13 deletions src/bootstrap/src/core/debuggers/cdb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::env;
use std::path::PathBuf;

use crate::core::config::TargetSelection;
Expand All @@ -8,18 +7,19 @@ pub(crate) struct Cdb {
}

/// We consult the registry to find the installed cdb.exe and try "Program Files" if that fails.
#[cfg(windows)]
pub(crate) fn discover_cdb(target: TargetSelection) -> Option<Cdb> {
if !cfg!(windows) || !target.ends_with("-pc-windows-msvc") {
if !target.ends_with("-pc-windows-msvc") {
return None;
}

let cdb_arch = if cfg!(target_arch = "x86") {
let cdb_arch = if target.starts_with("i686") {
"x86"
} else if cfg!(target_arch = "x86_64") {
} else if target.starts_with("x86_64") {
"x64"
} else if cfg!(target_arch = "aarch64") {
} else if target.starts_with("aarch64") || target.starts_with("arm64") {
"arm64"
} else if cfg!(target_arch = "arm") {
} else if target.starts_with("arm") || target.starts_with("thumb") {
"arm"
} else {
return None; // No compatible CDB.exe in the Windows 10 SDK
Expand All @@ -29,6 +29,11 @@ pub(crate) fn discover_cdb(target: TargetSelection) -> Option<Cdb> {
Some(Cdb { cdb: path })
}

#[cfg(not(windows))]
pub(crate) fn discover_cdb(_target: TargetSelection) -> Option<Cdb> {
None
}

#[cfg(windows)]
fn discover_cdb_registry(cdb_arch: &'static str) -> Option<PathBuf> {
use windows_registry::LOCAL_MACHINE;
Expand All @@ -39,14 +44,11 @@ fn discover_cdb_registry(cdb_arch: &'static str) -> Option<PathBuf> {
path.exists().then_some(path)
}

#[cfg(not(windows))]
fn discover_cdb_registry(_cdb_arch: &'static str) -> Option<PathBuf> {
None
}

#[cfg(windows)]
fn discover_cdb_program_files(cdb_arch: &'static str) -> Option<PathBuf> {
let mut path =
PathBuf::from(env::var_os("ProgramFiles(x86)").or_else(|| env::var_os("ProgramFiles"))?);
let mut path = PathBuf::from(
std::env::var_os("ProgramFiles(x86)").or_else(|| std::env::var_os("ProgramFiles"))?,
);
path.extend([r"Windows Kits\10\Debuggers", cdb_arch, r"cdb.exe"]);
path.exists().then_some(path)
}
Loading