Skip to content
Closed
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
44 changes: 29 additions & 15 deletions src/bootstrap/src/core/debuggers/cdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,42 @@ pub(crate) fn discover_cdb(target: TargetSelection) -> Option<Cdb> {
return None;
}

let pf86 =
PathBuf::from(env::var_os("ProgramFiles(x86)").or_else(|| env::var_os("ProgramFiles"))?);
let cdb_arch = if cfg!(target_arch = "x86") {
"x86"
} else if cfg!(target_arch = "x86_64") {
if let Some(path) = env::var_os("RUSTC_CDB") {

@jieyouxu jieyouxu Mar 3, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: this isn't the direction I was expecting, see the gsoc zulip thread for discussion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I will check.

let path = PathBuf::from(path);
if path.exists() {
return Some(Cdb { cdb: path });
}
}

let cdb_arch = if target.starts_with("x86_64") {
"x64"
} else if cfg!(target_arch = "aarch64") {
} else if target.starts_with("x86") || target.starts_with("i686") || target.starts_with("i586")
{
"x86"
} else if target.starts_with("aarch64") {
"arm64"
} else if cfg!(target_arch = "arm") {
} else if target.starts_with("arm") {
"arm"
} else {
return None; // No compatible CDB.exe in the Windows 10 SDK
return None;
};

let mut path = pf86;
path.push(r"Windows Kits\10\Debuggers"); // We could check 8.1 etc. too?
path.push(cdb_arch);
path.push(r"cdb.exe");
let program_files = [env::var_os("ProgramFiles(x86)"), env::var_os("ProgramFiles")];

if !path.exists() {
return None;
let sdk_versions = ["11", "10", "8.1"];

for base in program_files.iter().flatten() {
for version in &sdk_versions {
let mut path = PathBuf::from(base);
path.push(format!(r"Windows Kits\{}\Debuggers", version));
path.push(cdb_arch);
path.push("cdb.exe");

if path.exists() {
return Some(Cdb { cdb: path });
}
}
}

Some(Cdb { cdb: path })
None
}
26 changes: 16 additions & 10 deletions src/bootstrap/src/core/debuggers/gdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ pub(crate) fn discover_gdb<'a>(
) -> Option<Gdb<'a>> {
// If there's an explicitly-configured gdb, use that.
if let Some(gdb) = builder.config.gdb.as_deref() {
// FIXME(Zalathar): Consider returning None if gdb is an empty string,
// as a way to explicitly disable ambient gdb discovery.
if gdb.as_os_str().is_empty() {
Comment thread
jieyouxu marked this conversation as resolved.
return None;
}

let gdb = Cow::Borrowed(gdb);
return Some(Gdb { gdb });
if verify_gdb(builder, &gdb) {
return Some(Gdb { gdb });
} else {
return None;
}
}

// Otherwise, fall back to whatever gdb is sitting around in PATH.
Expand All @@ -31,12 +37,12 @@ pub(crate) fn discover_gdb<'a>(
None => Path::new("gdb").into(),
};

// Check whether an ambient gdb exists, by running `gdb --version`.
let output = {
let mut gdb_command = BootstrapCommand::new(gdb.as_ref()).allow_failure();
gdb_command.arg("--version");
gdb_command.run_capture(builder)
};
if verify_gdb(builder, &gdb) { Some(Gdb { gdb }) } else { None }
}

if output.is_success() { Some(Gdb { gdb }) } else { None }
// Check whether an ambient gdb exists, by running `gdb --version`.
fn verify_gdb(builder: &Builder<'_>, gdb: &Path) -> bool {
let mut cmd = BootstrapCommand::new(gdb).allow_failure();
cmd.arg("--version");
cmd.run_capture(builder).is_success()
}
Loading