Skip to content

Commit 336c665

Browse files
authored
Rollup merge of rust-lang#150201 - Enselic:debugger-tests-revisions-2, r=Zalathar
compiletest: Support revisions in debuginfo (read: debugger) tests And start using revisions in `tests/debuginfo/macro-stepping.rs` to prevent regressing both with and without `SingleUseConsts` MIR pass. I recommend commit-by-commit review. ## ~TODO~ - [x] Verify this more carefully. - [x] Possibly do some preparatory PRs before taking this PR out of draft. - [x] Rebase on rust-lang#150205 once merged so we don't have to add another "`+ 1`". ## CC CC ``@Zalathar`` since you might have opinions about that I expose a helper function to reduce duplication CC ``@saethlin`` since this is what we will use for `tests/debuginfo/basic-stepping.rs` in rust-lang#147426 (in the same way I use it in `tests/debuginfo/macro-stepping.rs` here)
2 parents f280e76 + 423a8dc commit 336c665

4 files changed

Lines changed: 42 additions & 29 deletions

File tree

src/tools/compiletest/src/directives.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::directives::directive_names::{
1515
};
1616
pub(crate) use crate::directives::file::FileDirectives;
1717
use crate::directives::handlers::DIRECTIVE_HANDLERS_MAP;
18-
use crate::directives::line::{DirectiveLine, line_directive};
18+
use crate::directives::line::DirectiveLine;
1919
use crate::directives::needs::CachedNeedsConditions;
2020
use crate::edition::{Edition, parse_edition};
2121
use crate::errors::ErrorKind;
@@ -29,6 +29,7 @@ mod directive_names;
2929
mod file;
3030
mod handlers;
3131
mod line;
32+
pub(crate) use line::line_directive;
3233
mod line_number;
3334
pub(crate) use line_number::LineNumber;
3435
mod needs;

src/tools/compiletest/src/runtest/debugger.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::io::{BufRead, BufReader};
44

55
use camino::{Utf8Path, Utf8PathBuf};
66

7-
use crate::directives::LineNumber;
7+
use crate::directives::{LineNumber, line_directive};
88
use crate::runtest::ProcRes;
99

1010
/// Representation of information to invoke a debugger and check its output
@@ -17,10 +17,16 @@ pub(super) struct DebuggerCommands {
1717
check_lines: Vec<(LineNumber, String)>,
1818
/// Source file name
1919
file: Utf8PathBuf,
20+
/// The revision being tested, if any
21+
revision: Option<String>,
2022
}
2123

2224
impl DebuggerCommands {
23-
pub fn parse_from(file: &Utf8Path, debugger_prefix: &str) -> Result<Self, String> {
25+
pub fn parse_from(
26+
file: &Utf8Path,
27+
debugger_prefix: &str,
28+
test_revision: Option<&str>,
29+
) -> Result<Self, String> {
2430
let command_directive = format!("{debugger_prefix}-command");
2531
let check_directive = format!("{debugger_prefix}-check");
2632

@@ -37,19 +43,33 @@ impl DebuggerCommands {
3743
continue;
3844
}
3945

40-
let Some(line) = line.trim_start().strip_prefix("//@").map(str::trim_start) else {
46+
let Some(directive) = line_directive(file, line_number, &line) else {
4147
continue;
4248
};
4349

44-
if let Some(command) = parse_name_value(&line, &command_directive) {
45-
commands.push(command);
50+
if !directive.applies_to_test_revision(test_revision) {
51+
continue;
4652
}
47-
if let Some(pattern) = parse_name_value(&line, &check_directive) {
48-
check_lines.push((line_number, pattern));
53+
54+
if directive.name == command_directive
55+
&& let Some(command) = directive.value_after_colon()
56+
{
57+
commands.push(command.to_string());
58+
}
59+
if directive.name == check_directive
60+
&& let Some(pattern) = directive.value_after_colon()
61+
{
62+
check_lines.push((line_number, pattern.to_string()));
4963
}
5064
}
5165

52-
Ok(Self { commands, breakpoint_lines, check_lines, file: file.to_path_buf() })
66+
Ok(Self {
67+
commands,
68+
breakpoint_lines,
69+
check_lines,
70+
file: file.to_path_buf(),
71+
revision: test_revision.map(str::to_owned),
72+
})
5373
}
5474

5575
/// Given debugger output and lines to check, ensure that every line is
@@ -81,9 +101,11 @@ impl DebuggerCommands {
81101
Ok(())
82102
} else {
83103
let fname = self.file.file_name().unwrap();
104+
let revision_suffix =
105+
self.revision.as_ref().map_or(String::new(), |r| format!("#{}", r));
84106
let mut msg = format!(
85-
"check directive(s) from `{}` not found in debugger output. errors:",
86-
self.file
107+
"check directive(s) from `{}{}` not found in debugger output. errors:",
108+
self.file, revision_suffix
87109
);
88110

89111
for (src_lineno, err_line) in missing {
@@ -103,18 +125,6 @@ impl DebuggerCommands {
103125
}
104126
}
105127

106-
/// Split off from the main `parse_name_value_directive`, so that improvements
107-
/// to directive handling aren't held back by debuginfo test commands.
108-
fn parse_name_value(line: &str, name: &str) -> Option<String> {
109-
if let Some(after_name) = line.strip_prefix(name)
110-
&& let Some(value) = after_name.strip_prefix(':')
111-
{
112-
Some(value.to_owned())
113-
} else {
114-
None
115-
}
116-
}
117-
118128
/// Check that the pattern in `check_line` applies to `line`. Returns `true` if they do match.
119129
fn check_single_line(line: &str, check_line: &str) -> bool {
120130
// Allow check lines to leave parts unspecified (e.g., uninitialized

src/tools/compiletest/src/runtest/debuginfo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl TestCx<'_> {
4646
}
4747

4848
// Parse debugger commands etc from test files
49-
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "cdb")
49+
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "cdb", self.revision)
5050
.unwrap_or_else(|e| self.fatal(&e));
5151

5252
// https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-commands
@@ -105,7 +105,7 @@ impl TestCx<'_> {
105105
}
106106

107107
fn run_debuginfo_gdb_test(&self) {
108-
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "gdb")
108+
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "gdb", self.revision)
109109
.unwrap_or_else(|e| self.fatal(&e));
110110
let mut cmds = dbg_cmds.commands.join("\n");
111111

@@ -366,7 +366,7 @@ impl TestCx<'_> {
366366
}
367367

368368
// Parse debugger commands etc from test files
369-
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "lldb")
369+
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "lldb", self.revision)
370370
.unwrap_or_else(|e| self.fatal(&e));
371371

372372
// Write debugger script:

tests/debuginfo/macro-stepping.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
#[macro_use]
1515
extern crate macro_stepping; // exports new_scope!()
1616

17-
//@ compile-flags:-g -Zmir-enable-passes=-SingleUseConsts
18-
// SingleUseConsts shouldn't need to be disabled, see #128945
17+
//@ compile-flags: -g
18+
// FIXME(#128945): SingleUseConsts shouldn't need to be disabled.
19+
//@ revisions: default-mir-passes no-SingleUseConsts-mir-pass
20+
//@ [no-SingleUseConsts-mir-pass] compile-flags: -Zmir-enable-passes=-SingleUseConsts
1921

2022
// === GDB TESTS ===================================================================================
2123

@@ -48,7 +50,7 @@ extern crate macro_stepping; // exports new_scope!()
4850
//@ gdb-check:[...]#inc-loc2[...]
4951
//@ gdb-command:next
5052
//@ gdb-command:frame
51-
//@ gdb-check:[...]#inc-loc3[...]
53+
//@ [no-SingleUseConsts-mir-pass] gdb-check:[...]#inc-loc3[...]
5254

5355
// === LLDB TESTS ==================================================================================
5456

0 commit comments

Comments
 (0)