Skip to content

Commit 41f41b2

Browse files
committed
Auto merge of #68391 - tmiasko:compiletest-debuginfo, r=alexcrichton
compiletest: Simplify multi-debugger support Previous implementation used a single mode type to store various pieces of otherwise loosely related information: * Whether debuginfo mode is in use or not. * Which debuggers should run in general. * Which debuggers are enabled for particular test case. The new implementation introduces a separation between those aspects. There is a single debuginfo mode parametrized by a debugger type. The debugger detection is performed first and a separate configuration is created for each detected debugger. The test cases are gathered independently for each debugger which makes it trivial to implement support for `ignore` / `only` conditions. Functional changes: * A single `debuginfo` entry point (rather than `debuginfo-cdb`, `debuginfo-gdb+lldb`, etc.). * Debugger name is included in the test name. * Test outputs are placed in per-debugger directory. * Fixed spurious hash mismatch. Previously, the config mode would change from `DebugInfoGdbLldb` (when collecting tests) to `DebugInfoGdb` or `DebugInfoLldb` (when running them) which would affect hash computation. * PYTHONPATH is additionally included in gdb hash. * lldb-python and lldb-python-dir are additionally included in lldb hash.
2 parents e0bbe79 + 5c384ab commit 41f41b2

File tree

5 files changed

+215
-286
lines changed

5 files changed

+215
-286
lines changed

src/bootstrap/test.rs

-8
Original file line numberDiff line numberDiff line change
@@ -957,14 +957,6 @@ impl Step for Compiletest {
957957
}
958958

959959
if suite == "debuginfo" {
960-
let msvc = builder.config.build.contains("msvc");
961-
if mode == "debuginfo" {
962-
return builder.ensure(Compiletest {
963-
mode: if msvc { "debuginfo-cdb" } else { "debuginfo-gdb+lldb" },
964-
..self
965-
});
966-
}
967-
968960
builder
969961
.ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
970962
}

src/tools/compiletest/src/common.rs

+32-17
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ pub enum Mode {
1414
RunFail,
1515
RunPassValgrind,
1616
Pretty,
17-
DebugInfoCdb,
18-
DebugInfoGdbLldb,
19-
DebugInfoGdb,
20-
DebugInfoLldb,
17+
DebugInfo,
2118
Codegen,
2219
Rustdoc,
2320
CodegenUnits,
@@ -32,13 +29,9 @@ pub enum Mode {
3229
impl Mode {
3330
pub fn disambiguator(self) -> &'static str {
3431
// Pretty-printing tests could run concurrently, and if they do,
35-
// they need to keep their output segregated. Same is true for debuginfo tests that
36-
// can be run on cdb, gdb, and lldb.
32+
// they need to keep their output segregated.
3733
match self {
3834
Pretty => ".pretty",
39-
DebugInfoCdb => ".cdb",
40-
DebugInfoGdb => ".gdb",
41-
DebugInfoLldb => ".lldb",
4235
_ => "",
4336
}
4437
}
@@ -52,10 +45,7 @@ impl FromStr for Mode {
5245
"run-fail" => Ok(RunFail),
5346
"run-pass-valgrind" => Ok(RunPassValgrind),
5447
"pretty" => Ok(Pretty),
55-
"debuginfo-cdb" => Ok(DebugInfoCdb),
56-
"debuginfo-gdb+lldb" => Ok(DebugInfoGdbLldb),
57-
"debuginfo-lldb" => Ok(DebugInfoLldb),
58-
"debuginfo-gdb" => Ok(DebugInfoGdb),
48+
"debuginfo" => Ok(DebugInfo),
5949
"codegen" => Ok(Codegen),
6050
"rustdoc" => Ok(Rustdoc),
6151
"codegen-units" => Ok(CodegenUnits),
@@ -77,10 +67,7 @@ impl fmt::Display for Mode {
7767
RunFail => "run-fail",
7868
RunPassValgrind => "run-pass-valgrind",
7969
Pretty => "pretty",
80-
DebugInfoCdb => "debuginfo-cdb",
81-
DebugInfoGdbLldb => "debuginfo-gdb+lldb",
82-
DebugInfoGdb => "debuginfo-gdb",
83-
DebugInfoLldb => "debuginfo-lldb",
70+
DebugInfo => "debuginfo",
8471
Codegen => "codegen",
8572
Rustdoc => "rustdoc",
8673
CodegenUnits => "codegen-units",
@@ -155,6 +142,29 @@ impl CompareMode {
155142
}
156143
}
157144

145+
#[derive(Clone, Copy, Debug, PartialEq)]
146+
pub enum Debugger {
147+
Cdb,
148+
Gdb,
149+
Lldb,
150+
}
151+
152+
impl Debugger {
153+
fn to_str(&self) -> &'static str {
154+
match self {
155+
Debugger::Cdb => "cdb",
156+
Debugger::Gdb => "gdb",
157+
Debugger::Lldb => "lldb",
158+
}
159+
}
160+
}
161+
162+
impl fmt::Display for Debugger {
163+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
164+
fmt::Display::fmt(self.to_str(), f)
165+
}
166+
}
167+
158168
/// Configuration for compiletest
159169
#[derive(Clone)]
160170
pub struct Config {
@@ -208,6 +218,9 @@ pub struct Config {
208218
/// The test mode, compile-fail, run-fail, ui
209219
pub mode: Mode,
210220

221+
/// The debugger to use in debuginfo mode. Unset otherwise.
222+
pub debugger: Option<Debugger>,
223+
211224
/// Run ignored tests
212225
pub run_ignored: bool,
213226

@@ -362,9 +375,11 @@ pub fn output_testname_unique(
362375
revision: Option<&str>,
363376
) -> PathBuf {
364377
let mode = config.compare_mode.as_ref().map_or("", |m| m.to_str());
378+
let debugger = config.debugger.as_ref().map_or("", |m| m.to_str());
365379
PathBuf::from(&testpaths.file.file_stem().unwrap())
366380
.with_extra_extension(revision.unwrap_or(""))
367381
.with_extra_extension(mode)
382+
.with_extra_extension(debugger)
368383
}
369384

370385
/// Absolute path to the directory where all output for the given

src/tools/compiletest/src/header.rs

+47-146
Original file line numberDiff line numberDiff line change
@@ -6,69 +6,26 @@ use std::path::{Path, PathBuf};
66

77
use log::*;
88

9-
use crate::common::{self, CompareMode, Config, FailMode, Mode, PassMode};
9+
use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PassMode};
1010
use crate::extract_gdb_version;
1111
use crate::util;
1212

1313
#[cfg(test)]
1414
mod tests;
1515

16-
/// Whether to ignore the test.
17-
#[derive(Clone, Copy, PartialEq, Debug)]
18-
pub enum Ignore {
19-
/// Runs it.
20-
Run,
21-
/// Ignore it totally.
22-
Ignore,
23-
/// Ignore only the gdb test, but run the lldb test.
24-
IgnoreGdb,
25-
/// Ignore only the lldb test, but run the gdb test.
26-
IgnoreLldb,
27-
}
28-
29-
impl Ignore {
30-
pub fn can_run_gdb(&self) -> bool {
31-
*self == Ignore::Run || *self == Ignore::IgnoreLldb
32-
}
33-
34-
pub fn can_run_lldb(&self) -> bool {
35-
*self == Ignore::Run || *self == Ignore::IgnoreGdb
36-
}
37-
38-
pub fn no_gdb(&self) -> Ignore {
39-
match *self {
40-
Ignore::Run => Ignore::IgnoreGdb,
41-
Ignore::IgnoreGdb => Ignore::IgnoreGdb,
42-
_ => Ignore::Ignore,
43-
}
44-
}
45-
46-
pub fn no_lldb(&self) -> Ignore {
47-
match *self {
48-
Ignore::Run => Ignore::IgnoreLldb,
49-
Ignore::IgnoreLldb => Ignore::IgnoreLldb,
50-
_ => Ignore::Ignore,
51-
}
52-
}
53-
}
54-
5516
/// The result of parse_cfg_name_directive.
5617
#[derive(Clone, Copy, PartialEq, Debug)]
5718
enum ParsedNameDirective {
5819
/// No match.
5920
NoMatch,
6021
/// Match.
6122
Match,
62-
/// Mode was DebugInfoGdbLldb and this matched gdb.
63-
MatchGdb,
64-
/// Mode was DebugInfoGdbLldb and this matched lldb.
65-
MatchLldb,
6623
}
6724

6825
/// Properties which must be known very early, before actually running
6926
/// the test.
7027
pub struct EarlyProps {
71-
pub ignore: Ignore,
28+
pub ignore: bool,
7229
pub should_fail: bool,
7330
pub aux: Vec<String>,
7431
pub aux_crate: Vec<(String, String)>,
@@ -78,84 +35,61 @@ pub struct EarlyProps {
7835
impl EarlyProps {
7936
pub fn from_file(config: &Config, testfile: &Path) -> Self {
8037
let mut props = EarlyProps {
81-
ignore: Ignore::Run,
38+
ignore: false,
8239
should_fail: false,
8340
aux: Vec::new(),
8441
aux_crate: Vec::new(),
8542
revisions: vec![],
8643
};
8744

88-
if config.mode == common::DebugInfoGdbLldb {
89-
if config.lldb_python_dir.is_none() {
90-
props.ignore = props.ignore.no_lldb();
91-
}
92-
if config.gdb_version.is_none() {
93-
props.ignore = props.ignore.no_gdb();
94-
}
95-
} else if config.mode == common::DebugInfoCdb {
96-
if config.cdb.is_none() {
97-
props.ignore = Ignore::Ignore;
98-
}
99-
}
100-
10145
let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some();
10246
let rustc_has_sanitizer_support = env::var_os("RUSTC_SANITIZER_SUPPORT").is_some();
10347

10448
iter_header(testfile, None, &mut |ln| {
10549
// we should check if any only-<platform> exists and if it exists
10650
// and does not matches the current platform, skip the test
107-
if props.ignore != Ignore::Ignore {
51+
if !props.ignore {
10852
props.ignore = match config.parse_cfg_name_directive(ln, "ignore") {
109-
ParsedNameDirective::Match => Ignore::Ignore,
53+
ParsedNameDirective::Match => true,
11054
ParsedNameDirective::NoMatch => props.ignore,
111-
ParsedNameDirective::MatchGdb => props.ignore.no_gdb(),
112-
ParsedNameDirective::MatchLldb => props.ignore.no_lldb(),
11355
};
11456

11557
if config.has_cfg_prefix(ln, "only") {
11658
props.ignore = match config.parse_cfg_name_directive(ln, "only") {
11759
ParsedNameDirective::Match => props.ignore,
118-
ParsedNameDirective::NoMatch => Ignore::Ignore,
119-
ParsedNameDirective::MatchLldb => props.ignore.no_gdb(),
120-
ParsedNameDirective::MatchGdb => props.ignore.no_lldb(),
60+
ParsedNameDirective::NoMatch => true,
12161
};
12262
}
12363

12464
if ignore_llvm(config, ln) {
125-
props.ignore = Ignore::Ignore;
65+
props.ignore = true;
12666
}
12767

12868
if config.run_clang_based_tests_with.is_none()
12969
&& config.parse_needs_matching_clang(ln)
13070
{
131-
props.ignore = Ignore::Ignore;
71+
props.ignore = true;
13272
}
13373

13474
if !rustc_has_profiler_support && config.parse_needs_profiler_support(ln) {
135-
props.ignore = Ignore::Ignore;
75+
props.ignore = true;
13676
}
13777

13878
if !rustc_has_sanitizer_support && config.parse_needs_sanitizer_support(ln) {
139-
props.ignore = Ignore::Ignore;
79+
props.ignore = true;
14080
}
14181

14282
if config.target == "wasm32-unknown-unknown" && config.parse_check_run_results(ln) {
143-
props.ignore = Ignore::Ignore;
83+
props.ignore = true;
14484
}
145-
}
14685

147-
if (config.mode == common::DebugInfoGdb || config.mode == common::DebugInfoGdbLldb)
148-
&& props.ignore.can_run_gdb()
149-
&& ignore_gdb(config, ln)
150-
{
151-
props.ignore = props.ignore.no_gdb();
152-
}
86+
if config.debugger == Some(Debugger::Gdb) && ignore_gdb(config, ln) {
87+
props.ignore = true;
88+
}
15389

154-
if (config.mode == common::DebugInfoLldb || config.mode == common::DebugInfoGdbLldb)
155-
&& props.ignore.can_run_lldb()
156-
&& ignore_lldb(config, ln)
157-
{
158-
props.ignore = props.ignore.no_lldb();
90+
if config.debugger == Some(Debugger::Lldb) && ignore_lldb(config, ln) {
91+
props.ignore = true;
92+
}
15993
}
16094

16195
if let Some(s) = config.parse_aux_build(ln) {
@@ -881,70 +815,37 @@ impl Config {
881815
/// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
882816
/// or `normalize-stderr-32bit`.
883817
fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> ParsedNameDirective {
884-
if line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-') {
885-
let name = line[prefix.len() + 1..].split(&[':', ' '][..]).next().unwrap();
886-
887-
if name == "test" ||
888-
&self.target == name || // triple
889-
util::matches_os(&self.target, name) || // target
890-
util::matches_env(&self.target, name) || // env
891-
name == util::get_arch(&self.target) || // architecture
892-
name == util::get_pointer_width(&self.target) || // pointer width
893-
name == self.stage_id.split('-').next().unwrap() || // stage
894-
(self.target != self.host && name == "cross-compile") ||
895-
match self.compare_mode {
896-
Some(CompareMode::Nll) => name == "compare-mode-nll",
897-
Some(CompareMode::Polonius) => name == "compare-mode-polonius",
898-
None => false,
899-
} ||
900-
(cfg!(debug_assertions) && name == "debug")
901-
{
902-
ParsedNameDirective::Match
903-
} else {
904-
match self.mode {
905-
common::DebugInfoGdbLldb => {
906-
if name == "gdb" {
907-
ParsedNameDirective::MatchGdb
908-
} else if name == "lldb" {
909-
ParsedNameDirective::MatchLldb
910-
} else {
911-
ParsedNameDirective::NoMatch
912-
}
913-
}
914-
common::DebugInfoCdb => {
915-
if name == "cdb" {
916-
ParsedNameDirective::Match
917-
} else {
918-
ParsedNameDirective::NoMatch
919-
}
920-
}
921-
common::DebugInfoGdb => {
922-
if name == "gdb" {
923-
ParsedNameDirective::Match
924-
} else {
925-
ParsedNameDirective::NoMatch
926-
}
927-
}
928-
common::DebugInfoLldb => {
929-
if name == "lldb" {
930-
ParsedNameDirective::Match
931-
} else {
932-
ParsedNameDirective::NoMatch
933-
}
934-
}
935-
common::Pretty => {
936-
if name == "pretty" {
937-
ParsedNameDirective::Match
938-
} else {
939-
ParsedNameDirective::NoMatch
940-
}
941-
}
942-
_ => ParsedNameDirective::NoMatch,
943-
}
944-
}
945-
} else {
946-
ParsedNameDirective::NoMatch
818+
if !line.as_bytes().starts_with(prefix.as_bytes()) {
819+
return ParsedNameDirective::NoMatch;
820+
}
821+
if line.as_bytes().get(prefix.len()) != Some(&b'-') {
822+
return ParsedNameDirective::NoMatch;
947823
}
824+
825+
let name = line[prefix.len() + 1..].split(&[':', ' '][..]).next().unwrap();
826+
827+
let is_match = name == "test" ||
828+
&self.target == name || // triple
829+
util::matches_os(&self.target, name) || // target
830+
util::matches_env(&self.target, name) || // env
831+
name == util::get_arch(&self.target) || // architecture
832+
name == util::get_pointer_width(&self.target) || // pointer width
833+
name == self.stage_id.split('-').next().unwrap() || // stage
834+
(self.target != self.host && name == "cross-compile") ||
835+
match self.compare_mode {
836+
Some(CompareMode::Nll) => name == "compare-mode-nll",
837+
Some(CompareMode::Polonius) => name == "compare-mode-polonius",
838+
None => false,
839+
} ||
840+
(cfg!(debug_assertions) && name == "debug") ||
841+
match self.debugger {
842+
Some(Debugger::Cdb) => name == "cdb",
843+
Some(Debugger::Gdb) => name == "gdb",
844+
Some(Debugger::Lldb) => name == "lldb",
845+
None => false,
846+
};
847+
848+
if is_match { ParsedNameDirective::Match } else { ParsedNameDirective::NoMatch }
948849
}
949850

950851
fn has_cfg_prefix(&self, line: &str, prefix: &str) -> bool {

0 commit comments

Comments
 (0)