Skip to content

Commit 008fa22

Browse files
committed
Auto merge of #159455 - Kobzol:bootstrap-discover-lldb, r=jieyouxu
Implement opt-in debugger discovery for GDB and LLDB in bootstrap GDB and LLDB is no longer automatically auto-discovered, you can opt into the previous behavior using `build.gdb/lldb = "discover"`. Note: this means that unless you opt into using a specific debugger, you won't run any `debuginfo` tests by default (except for `cdb`, which is still automatically detected). r? @jieyouxu
2 parents da86f4d + 8790990 commit 008fa22

11 files changed

Lines changed: 80 additions & 46 deletions

File tree

bootstrap.example.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,12 @@
343343

344344
# The path to (or name of) the GDB executable to use. This is only used for
345345
# executing the debuginfo test suite.
346+
# Set this to "discover" to automatically discover GDB from the environment.
346347
#build.gdb = "gdb"
347348

348349
# The path to (or name of) the LLDB executable to use. This is only used for
349350
# executing the debuginfo test suite.
351+
# Set this to "discover" to automatically discover LLDB from the environment.
350352
#build.lldb = "lldb"
351353

352354
# The node.js executable to use. Note that this is only used for the emscripten

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,7 @@ Please disable assertions with `rust.debug-assertions = false`.
25442544

25452545
if let Some(debuggers::Gdb { gdb }) = debuggers::discover_gdb(builder, android.as_ref())
25462546
{
2547-
cmd.arg("--gdb").arg(gdb.as_ref());
2547+
cmd.arg("--gdb").arg(gdb);
25482548
}
25492549

25502550
if let Some(debuggers::Lldb { lldb_exe, lldb_version }) =

src/bootstrap/src/core/config/config.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ use crate::core::config::toml::target::{
4949
DefaultLinuxLinkerOverride, Target, TomlTarget, default_linux_linker_overrides,
5050
};
5151
use crate::core::config::{
52-
CompilerBuiltins, CompressDebuginfo, DebuginfoLevel, DryRun, GccCiMode, LlvmLibunwind, Merge,
53-
OverrideAllocator, ReplaceOpt, RustcLto, SplitDebuginfo, StringOrBool, threads_from_config,
52+
CompilerBuiltins, CompressDebuginfo, DebuggerPath, DebuginfoLevel, DryRun, GccCiMode,
53+
LlvmLibunwind, Merge, OverrideAllocator, ReplaceOpt, RustcLto, SplitDebuginfo, StringOrBool,
54+
threads_from_config,
5455
};
5556
use crate::core::download::{
5657
DownloadContext, download_beta_toolchain, is_download_ci_available, maybe_download_rustfmt,
@@ -284,8 +285,8 @@ pub struct Config {
284285
pub codegen_tests: bool,
285286
pub nodejs: Option<PathBuf>,
286287
pub yarn: Option<PathBuf>,
287-
pub gdb: Option<PathBuf>,
288-
pub lldb: Option<PathBuf>,
288+
pub gdb: Option<DebuggerPath>,
289+
pub lldb: Option<DebuggerPath>,
289290
pub python: Option<PathBuf>,
290291
pub windows_rc: Option<PathBuf>,
291292
pub reuse: Option<PathBuf>,
@@ -1457,7 +1458,7 @@ NOTE: Please add `--stage 2` to your command line, or if you're sure you want to
14571458
free_args: flags_free_args,
14581459
full_bootstrap: build_full_bootstrap.unwrap_or(false),
14591460
gcc_ci_mode,
1460-
gdb: build_gdb.map(PathBuf::from),
1461+
gdb: build_gdb,
14611462
host_target,
14621463
hosts,
14631464
in_tree_gcc_info,
@@ -1478,7 +1479,7 @@ NOTE: Please add `--stage 2` to your command line, or if you're sure you want to
14781479
libgccjit_libs_dir: gcc_libgccjit_libs_dir,
14791480
library_docs_private_items: build_library_docs_private_items.unwrap_or(false),
14801481
lld_enabled,
1481-
lldb: build_lldb.map(PathBuf::from),
1482+
lldb: build_lldb,
14821483
llvm_allow_old_toolchain: llvm_allow_old_toolchain.unwrap_or(false),
14831484
llvm_assertions,
14841485
llvm_bitcode_linker_enabled: rust_llvm_bitcode_linker.unwrap_or(false),

src/bootstrap/src/core/config/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,27 @@ pub enum GccCiMode {
508508
DownloadFromCi,
509509
}
510510

511+
#[derive(Clone, Debug, PartialEq)]
512+
pub enum DebuggerPath {
513+
/// Use a debugger at this path
514+
Path(PathBuf),
515+
/// Try to automatically discover a version of a debugger from the environment
516+
Discover,
517+
}
518+
519+
impl<'d> Deserialize<'d> for DebuggerPath {
520+
fn deserialize<D>(deserializer: D) -> Result<Self, <D as serde::Deserializer<'d>>::Error>
521+
where
522+
D: serde::Deserializer<'d>,
523+
{
524+
let value = String::deserialize(deserializer)?;
525+
match value.as_str() {
526+
"discover" => Ok(Self::Discover),
527+
path => Ok(Self::Path(PathBuf::from(path))),
528+
}
529+
}
530+
}
531+
511532
pub fn threads_from_config(v: u32) -> u32 {
512533
match v {
513534
0 => std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32,

src/bootstrap/src/core/config/tests.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use clap::CommandFactory;
1111
use super::flags::Flags;
1212
use super::toml::change_id::ChangeIdWrapper;
1313
use super::toml::rust::parse_codegen_backends;
14-
use super::{Config, RUSTC_IF_UNCHANGED_ALLOWED_PATHS};
14+
use super::{Config, DebuggerPath, RUSTC_IF_UNCHANGED_ALLOWED_PATHS};
1515
use crate::ChangeId;
1616
use crate::core::build_steps::clippy::{LintConfig, get_clippy_rules_in_order};
1717
use crate::core::build_steps::llvm::LLVM_INVALIDATION_PATHS;
@@ -111,7 +111,11 @@ fn override_toml() {
111111
crate::core::config::RustcLto::Fat,
112112
"setting string value without quotes"
113113
);
114-
assert_eq!(config.gdb, Some("bar".into()), "setting string value with quotes");
114+
assert_eq!(
115+
config.gdb,
116+
Some(DebuggerPath::Path("bar".into())),
117+
"setting string value with quotes"
118+
);
115119
assert!(!config.deny_warnings, "setting boolean value");
116120
assert_eq!(
117121
config.optimized_compiler_builtins,

src/bootstrap/src/core/config/toml/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::collections::HashMap;
1111
use serde::{Deserialize, Deserializer};
1212

1313
use crate::core::config::toml::ReplaceOpt;
14-
use crate::core::config::{CompilerBuiltins, Merge, StringOrBool};
14+
use crate::core::config::{CompilerBuiltins, DebuggerPath, Merge, StringOrBool};
1515
use crate::{HashSet, PathBuf, define_config, exit};
1616

1717
define_config! {
@@ -33,8 +33,8 @@ define_config! {
3333
library_docs_private_items: Option<bool> = "library-docs-private-items",
3434
docs_minification: Option<bool> = "docs-minification",
3535
submodules: Option<bool> = "submodules",
36-
gdb: Option<String> = "gdb",
37-
lldb: Option<String> = "lldb",
36+
gdb: Option<DebuggerPath> = "gdb",
37+
lldb: Option<DebuggerPath> = "lldb",
3838
nodejs: Option<String> = "nodejs",
3939
npm: Option<String> = "npm", // unused, present for compatibility
4040
yarn: Option<String> = "yarn",

src/bootstrap/src/core/debuggers/gdb.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
1-
use std::borrow::Cow;
2-
use std::path::Path;
1+
use std::path::PathBuf;
32

43
use crate::core::android;
54
use crate::core::builder::Builder;
5+
use crate::core::config::DebuggerPath;
66
use crate::utils::exec::BootstrapCommand;
77

8-
pub(crate) struct Gdb<'a> {
9-
pub(crate) gdb: Cow<'a, Path>,
8+
pub(crate) struct Gdb {
9+
pub(crate) gdb: PathBuf,
1010
}
1111

12-
pub(crate) fn discover_gdb<'a>(
13-
builder: &'a Builder<'_>,
12+
pub(crate) fn discover_gdb(
13+
builder: &Builder<'_>,
1414
android: Option<&android::Android>,
15-
) -> Option<Gdb<'a>> {
15+
) -> Option<Gdb> {
1616
// If there's an explicitly-configured gdb, use that.
17-
if let Some(gdb) = builder.config.gdb.as_deref() {
18-
// FIXME(Zalathar): Consider returning None if gdb is an empty string,
19-
// as a way to explicitly disable ambient gdb discovery.
20-
let gdb = Cow::Borrowed(gdb);
21-
return Some(Gdb { gdb });
17+
match &builder.config.gdb {
18+
Some(DebuggerPath::Path(path)) => {
19+
return Some(Gdb { gdb: path.clone() });
20+
}
21+
Some(DebuggerPath::Discover) => {}
22+
None => return None,
2223
}
2324

2425
// Otherwise, fall back to whatever gdb is sitting around in PATH.
25-
// (That's the historical behavior, but maybe we should require opt-in?)
26-
27-
let gdb: Cow<'_, Path> = match android {
28-
Some(android::Android { android_cross_path, .. }) => {
29-
android_cross_path.join("bin/gdb").into()
30-
}
31-
None => Path::new("gdb").into(),
26+
let gdb = match android {
27+
Some(android::Android { android_cross_path, .. }) => android_cross_path.join("bin/gdb"),
28+
None => PathBuf::from("gdb"),
3229
};
3330

3431
// Check whether an ambient gdb exists, by running `gdb --version`.
3532
let output = {
36-
let mut gdb_command = BootstrapCommand::new(gdb.as_ref()).allow_failure();
33+
let mut gdb_command = BootstrapCommand::new(&gdb).allow_failure();
3734
gdb_command.arg("--version");
3835
gdb_command.run_capture(builder)
3936
};

src/bootstrap/src/core/debuggers/lldb.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::path::PathBuf;
22

33
use crate::core::builder::Builder;
4+
use crate::core::config::DebuggerPath;
45
use crate::utils::exec::command;
56

67
pub(crate) struct Lldb {
@@ -9,17 +10,17 @@ pub(crate) struct Lldb {
910
}
1011

1112
pub(crate) fn discover_lldb(builder: &Builder<'_>) -> Option<Lldb> {
12-
// FIXME(#148361): We probably should not be picking up whatever arbitrary
13-
// lldb happens to be in the user's path, and instead require some kind of
14-
// explicit opt-in or configuration.
15-
let lldb_exe = builder.config.lldb.clone().unwrap_or_else(|| PathBuf::from("lldb"));
13+
// If a path to a LLDB binary was provided, it has to exist and return some version, to avoid
14+
// silent failures.
15+
let (lldb_exe, explicitly_set_lldb) = match &builder.config.lldb {
16+
Some(DebuggerPath::Path(path)) => (path.clone(), true),
17+
Some(DebuggerPath::Discover) => (PathBuf::from("lldb"), false),
18+
None => return None,
19+
};
1620

1721
let mut cmd = command(&lldb_exe);
1822
cmd.arg("--version");
1923

20-
// If a path to a LLDB binary was provided, it has to exist and return some version, to avoid
21-
// silent failures.
22-
let explicitly_set_lldb = builder.config.lldb.is_some();
2324
if !explicitly_set_lldb {
2425
cmd = cmd.allow_failure();
2526
}

src/bootstrap/src/core/sanity.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{env, fs};
1616

1717
use crate::builder::{Builder, Kind};
1818
use crate::core::build_steps::tool;
19-
use crate::core::config::{CompilerBuiltins, Target};
19+
use crate::core::config::{CompilerBuiltins, DebuggerPath, Target};
2020
use crate::utils::exec::command;
2121
use crate::{Build, Subcommand, t};
2222

@@ -187,12 +187,10 @@ than building it.
187187
.map(|p| cmd_finder.must_have(p))
188188
.or_else(|| cmd_finder.maybe_have("yarn"));
189189

190-
build.config.gdb = build
191-
.config
192-
.gdb
193-
.take()
194-
.map(|p| cmd_finder.must_have(p))
195-
.or_else(|| cmd_finder.maybe_have("gdb"));
190+
build.config.gdb = build.config.gdb.take().map(|p| match p {
191+
DebuggerPath::Discover => DebuggerPath::Discover,
192+
DebuggerPath::Path(path) => DebuggerPath::Path(cmd_finder.must_have(path)),
193+
});
196194

197195
build.config.reuse = build
198196
.config

src/bootstrap/src/utils/change_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,4 +651,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
651651
severity: ChangeSeverity::Info,
652652
summary: "A new `build.sde` configuration option has been added to support intrinsic-test.",
653653
},
654+
ChangeInfo {
655+
change_id: 159455,
656+
severity: ChangeSeverity::Warning,
657+
summary: "GDB and LLDB are no longer automatically discovered from the environment. If you want to use path discovery for them, you can opt in using `build.gdb = \"discover\"` or `build.lldb = \"discover\"`.",
658+
},
654659
];

0 commit comments

Comments
 (0)