Skip to content

Update debuginfo test runner to provide more useful output #113306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2023
Merged
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
13 changes: 7 additions & 6 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,21 +588,22 @@ impl TestProps {
}
}

/// Extract a `(Option<line_config>, directive)` directive from a line if comment is present.
pub fn line_directive<'line>(
comment: &str,
ln: &'line str,
) -> Option<(Option<&'line str>, &'line str)> {
let ln = ln.trim_start();
if ln.starts_with(comment) {
let ln = ln[comment.len()..].trim_start();
if ln.starts_with('[') {
// A comment like `//[foo]` is specific to revision `foo`
if let Some(close_brace) = ln.find(']') {
let lncfg = &ln[1..close_brace];
let Some(close_brace) = ln.find(']') else {
panic!("malformed condition directive: expected `{}[foo]`, found `{}`", comment, ln);
};

Some((Some(lncfg), ln[(close_brace + 1)..].trim_start()))
} else {
panic!("malformed condition directive: expected `{}[foo]`, found `{}`", comment, ln)
}
let lncfg = &ln[1..close_brace];
Some((Some(lncfg), ln[(close_brace + 1)..].trim_start()))
} else {
Some((None, ln))
}
Expand Down
78 changes: 35 additions & 43 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::extract_gdb_version;
use crate::is_android_gdb_target;

mod debugger;
use debugger::{check_debugger_output, DebuggerCommands};
use debugger::DebuggerCommands;

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -997,16 +997,13 @@ impl<'test> TestCx<'test> {
};

// Parse debugger commands etc from test files
let DebuggerCommands { commands, check_lines, breakpoint_lines, .. } =
match DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
self.revision,
) {
Ok(cmds) => cmds,
Err(e) => self.fatal(&e),
};
let dbg_cmds = DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
self.revision,
)
.unwrap_or_else(|e| self.fatal(&e));

// https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-commands
let mut script_str = String::with_capacity(2048);
Expand All @@ -1023,12 +1020,12 @@ impl<'test> TestCx<'test> {

// Set breakpoints on every line that contains the string "#break"
let source_file_name = self.testpaths.file.file_name().unwrap().to_string_lossy();
for line in &breakpoint_lines {
for line in &dbg_cmds.breakpoint_lines {
script_str.push_str(&format!("bp `{}:{}`\n", source_file_name, line));
}

// Append the other `cdb-command:`s
for line in &commands {
for line in &dbg_cmds.commands {
script_str.push_str(line);
script_str.push_str("\n");
}
Expand Down Expand Up @@ -1058,7 +1055,7 @@ impl<'test> TestCx<'test> {
self.fatal_proc_rec("Error while running CDB", &debugger_run_result);
}

if let Err(e) = check_debugger_output(&debugger_run_result, &check_lines) {
if let Err(e) = dbg_cmds.check_output(&debugger_run_result) {
self.fatal_proc_rec(&e, &debugger_run_result);
}
}
Expand Down Expand Up @@ -1088,17 +1085,14 @@ impl<'test> TestCx<'test> {
PREFIXES
};

let DebuggerCommands { commands, check_lines, breakpoint_lines } =
match DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
self.revision,
) {
Ok(cmds) => cmds,
Err(e) => self.fatal(&e),
};
let mut cmds = commands.join("\n");
let dbg_cmds = DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
self.revision,
)
.unwrap_or_else(|e| self.fatal(&e));
let mut cmds = dbg_cmds.commands.join("\n");

// compile test file (it should have 'compile-flags:-g' in the header)
let should_run = self.run_if_enabled();
Expand Down Expand Up @@ -1132,13 +1126,14 @@ impl<'test> TestCx<'test> {
./{}/stage2/lib/rustlib/{}/lib/\n",
self.config.host, self.config.target
));
for line in &breakpoint_lines {
for line in &dbg_cmds.breakpoint_lines {
script_str.push_str(
&format!(
format!(
"break {:?}:{}\n",
self.testpaths.file.file_name().unwrap().to_string_lossy(),
*line
)[..],
)
.as_str(),
);
}
script_str.push_str(&cmds);
Expand Down Expand Up @@ -1279,7 +1274,7 @@ impl<'test> TestCx<'test> {
}

// Add line breakpoints
for line in &breakpoint_lines {
for line in &dbg_cmds.breakpoint_lines {
script_str.push_str(&format!(
"break '{}':{}\n",
self.testpaths.file.file_name().unwrap().to_string_lossy(),
Expand Down Expand Up @@ -1315,7 +1310,7 @@ impl<'test> TestCx<'test> {
self.fatal_proc_rec("gdb failed to execute", &debugger_run_result);
}

if let Err(e) = check_debugger_output(&debugger_run_result, &check_lines) {
if let Err(e) = dbg_cmds.check_output(&debugger_run_result) {
self.fatal_proc_rec(&e, &debugger_run_result);
}
}
Expand Down Expand Up @@ -1372,16 +1367,13 @@ impl<'test> TestCx<'test> {
};

// Parse debugger commands etc from test files
let DebuggerCommands { commands, check_lines, breakpoint_lines, .. } =
match DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
self.revision,
) {
Ok(cmds) => cmds,
Err(e) => self.fatal(&e),
};
let dbg_cmds = DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
self.revision,
)
.unwrap_or_else(|e| self.fatal(&e));

// Write debugger script:
// We don't want to hang when calling `quit` while the process is still running
Expand Down Expand Up @@ -1430,15 +1422,15 @@ impl<'test> TestCx<'test> {

// Set breakpoints on every line that contains the string "#break"
let source_file_name = self.testpaths.file.file_name().unwrap().to_string_lossy();
for line in &breakpoint_lines {
for line in &dbg_cmds.breakpoint_lines {
script_str.push_str(&format!(
"breakpoint set --file '{}' --line {}\n",
source_file_name, line
));
}

// Append the other commands
for line in &commands {
for line in &dbg_cmds.commands {
script_str.push_str(line);
script_str.push_str("\n");
}
Expand All @@ -1458,7 +1450,7 @@ impl<'test> TestCx<'test> {
self.fatal_proc_rec("Error while running LLDB", &debugger_run_result);
}

if let Err(e) = check_debugger_output(&debugger_run_result, &check_lines) {
if let Err(e) = dbg_cmds.check_output(&debugger_run_result) {
self.fatal_proc_rec(&e, &debugger_run_result);
}
}
Expand Down
Loading