Skip to content
Draft
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
2 changes: 1 addition & 1 deletion src/tools/compiletest/src/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod cfg;
mod directive_names;
mod file;
mod handlers;
mod line;
pub(crate) mod line;
mod needs;
#[cfg(test)]
mod tests;
Expand Down
56 changes: 34 additions & 22 deletions src/tools/compiletest/src/runtest/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ pub(super) struct DebuggerCommands {
check_lines: Vec<(usize, 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");

Expand All @@ -28,7 +34,7 @@ impl DebuggerCommands {
let mut check_lines = vec![];
let mut counter = 0;
let reader = BufReader::new(File::open(file.as_std_path()).unwrap());
for (line_no, line) in reader.lines().enumerate() {
for (zero_based_line_no, line) in reader.lines().enumerate() {
counter += 1;
let line = line.map_err(|e| format!("Error while parsing debugger commands: {}", e))?;

Expand All @@ -38,19 +44,35 @@ impl DebuggerCommands {
continue;
}

let Some(line) = line.trim_start().strip_prefix("//@").map(str::trim_start) else {
let Some(directive) =
crate::directives::line::line_directive(file, zero_based_line_no + 1, &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_no, 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(check) = directive.value_after_colon()
{
check_lines.push((zero_based_line_no, check.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
Expand Down Expand Up @@ -82,9 +104,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 {
Expand All @@ -105,18 +129,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
Expand Down
6 changes: 3 additions & 3 deletions src/tools/compiletest/src/runtest/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions tests/debuginfo/macro-stepping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===================================================================================

Expand Down Expand Up @@ -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 ==================================================================================

Expand Down
Loading