Rollup merge of #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 https://github.com/rust-lang/rust/pull/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 https://github.com/rust-lang/rust/pull/147426 (in the same way I use it in `tests/debuginfo/macro-stepping.rs` here)
This commit is contained in:
Stuart Cook 2026-01-04 21:37:02 +11:00 committed by GitHub
commit 336c6658e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 42 additions and 29 deletions

View file

@ -15,7 +15,7 @@ use crate::directives::directive_names::{
};
pub(crate) use crate::directives::file::FileDirectives;
use crate::directives::handlers::DIRECTIVE_HANDLERS_MAP;
use crate::directives::line::{DirectiveLine, line_directive};
use crate::directives::line::DirectiveLine;
use crate::directives::needs::CachedNeedsConditions;
use crate::edition::{Edition, parse_edition};
use crate::errors::ErrorKind;
@ -29,6 +29,7 @@ mod directive_names;
mod file;
mod handlers;
mod line;
pub(crate) use line::line_directive;
mod line_number;
pub(crate) use line_number::LineNumber;
mod needs;

View file

@ -4,7 +4,7 @@ use std::io::{BufRead, BufReader};
use camino::{Utf8Path, Utf8PathBuf};
use crate::directives::LineNumber;
use crate::directives::{LineNumber, line_directive};
use crate::runtest::ProcRes;
/// Representation of information to invoke a debugger and check its output
@ -17,10 +17,16 @@ pub(super) struct DebuggerCommands {
check_lines: Vec<(LineNumber, String)>,
/// Source file name
file: Utf8PathBuf,
/// The revision being tested, if any
revision: Option<String>,
}
impl DebuggerCommands {
pub fn parse_from(file: &Utf8Path, debugger_prefix: &str) -> Result<Self, String> {
pub fn parse_from(
file: &Utf8Path,
debugger_prefix: &str,
test_revision: Option<&str>,
) -> Result<Self, String> {
let command_directive = format!("{debugger_prefix}-command");
let check_directive = format!("{debugger_prefix}-check");
@ -37,19 +43,33 @@ impl DebuggerCommands {
continue;
}
let Some(line) = line.trim_start().strip_prefix("//@").map(str::trim_start) else {
let Some(directive) = line_directive(file, line_number, &line) else {
continue;
};
if let Some(command) = parse_name_value(&line, &command_directive) {
commands.push(command);
if !directive.applies_to_test_revision(test_revision) {
continue;
}
if let Some(pattern) = parse_name_value(&line, &check_directive) {
check_lines.push((line_number, pattern));
if directive.name == command_directive
&& let Some(command) = directive.value_after_colon()
{
commands.push(command.to_string());
}
if directive.name == check_directive
&& let Some(pattern) = directive.value_after_colon()
{
check_lines.push((line_number, pattern.to_string()));
}
}
Ok(Self { commands, breakpoint_lines, check_lines, file: file.to_path_buf() })
Ok(Self {
commands,
breakpoint_lines,
check_lines,
file: file.to_path_buf(),
revision: test_revision.map(str::to_owned),
})
}
/// Given debugger output and lines to check, ensure that every line is
@ -81,9 +101,11 @@ impl DebuggerCommands {
Ok(())
} else {
let fname = self.file.file_name().unwrap();
let revision_suffix =
self.revision.as_ref().map_or(String::new(), |r| format!("#{}", r));
let mut msg = format!(
"check directive(s) from `{}` not found in debugger output. errors:",
self.file
"check directive(s) from `{}{}` not found in debugger output. errors:",
self.file, revision_suffix
);
for (src_lineno, err_line) in missing {
@ -103,18 +125,6 @@ impl DebuggerCommands {
}
}
/// Split off from the main `parse_name_value_directive`, so that improvements
/// to directive handling aren't held back by debuginfo test commands.
fn parse_name_value(line: &str, name: &str) -> Option<String> {
if let Some(after_name) = line.strip_prefix(name)
&& let Some(value) = after_name.strip_prefix(':')
{
Some(value.to_owned())
} else {
None
}
}
/// Check that the pattern in `check_line` applies to `line`. Returns `true` if they do match.
fn check_single_line(line: &str, check_line: &str) -> bool {
// Allow check lines to leave parts unspecified (e.g., uninitialized

View file

@ -46,7 +46,7 @@ impl TestCx<'_> {
}
// Parse debugger commands etc from test files
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "cdb")
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "cdb", self.revision)
.unwrap_or_else(|e| self.fatal(&e));
// https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-commands
@ -105,7 +105,7 @@ impl TestCx<'_> {
}
fn run_debuginfo_gdb_test(&self) {
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "gdb")
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "gdb", self.revision)
.unwrap_or_else(|e| self.fatal(&e));
let mut cmds = dbg_cmds.commands.join("\n");
@ -366,7 +366,7 @@ impl TestCx<'_> {
}
// Parse debugger commands etc from test files
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "lldb")
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "lldb", self.revision)
.unwrap_or_else(|e| self.fatal(&e));
// Write debugger script:

View file

@ -14,8 +14,10 @@
#[macro_use]
extern crate macro_stepping; // exports new_scope!()
//@ compile-flags:-g -Zmir-enable-passes=-SingleUseConsts
// SingleUseConsts shouldn't need to be disabled, see #128945
//@ compile-flags: -g
// FIXME(#128945): SingleUseConsts shouldn't need to be disabled.
//@ revisions: default-mir-passes no-SingleUseConsts-mir-pass
//@ [no-SingleUseConsts-mir-pass] compile-flags: -Zmir-enable-passes=-SingleUseConsts
// === GDB TESTS ===================================================================================
@ -48,7 +50,7 @@ extern crate macro_stepping; // exports new_scope!()
//@ gdb-check:[...]#inc-loc2[...]
//@ gdb-command:next
//@ gdb-command:frame
//@ gdb-check:[...]#inc-loc3[...]
//@ [no-SingleUseConsts-mir-pass] gdb-check:[...]#inc-loc3[...]
// === LLDB TESTS ==================================================================================