Skip to content

Commit 2f8824a

Browse files
committedDec 28, 2024·
Simplify DebuggerCommands::parse_from to only take one prefix
1 parent a625ddd commit 2f8824a

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed
 

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

+8-17
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@ pub(super) struct DebuggerCommands {
1919
}
2020

2121
impl DebuggerCommands {
22-
pub fn parse_from(
23-
file: &Path,
24-
config: &Config,
25-
debugger_prefixes: &[&str],
26-
) -> Result<Self, String> {
27-
let directives = debugger_prefixes
28-
.iter()
29-
.map(|prefix| (format!("{prefix}-command"), format!("{prefix}-check")))
30-
.collect::<Vec<_>>();
22+
pub fn parse_from(file: &Path, config: &Config, debugger_prefix: &str) -> Result<Self, String> {
23+
let command_directive = format!("{debugger_prefix}-command");
24+
let check_directive = format!("{debugger_prefix}-check");
3125

3226
let mut breakpoint_lines = vec![];
3327
let mut commands = vec![];
@@ -48,14 +42,11 @@ impl DebuggerCommands {
4842
continue;
4943
};
5044

51-
for &(ref command_directive, ref check_directive) in &directives {
52-
config
53-
.parse_name_value_directive(&line, command_directive)
54-
.map(|cmd| commands.push(cmd));
55-
56-
config
57-
.parse_name_value_directive(&line, check_directive)
58-
.map(|cmd| check_lines.push((line_no, cmd)));
45+
if let Some(command) = config.parse_name_value_directive(&line, &command_directive) {
46+
commands.push(command);
47+
}
48+
if let Some(pattern) = config.parse_name_value_directive(&line, &check_directive) {
49+
check_lines.push((line_no, pattern));
5950
}
6051
}
6152

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl TestCx<'_> {
6060
}
6161

6262
// Parse debugger commands etc from test files
63-
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, self.config, &["cdb"])
63+
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, self.config, "cdb")
6464
.unwrap_or_else(|e| self.fatal(&e));
6565

6666
// https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-commands
@@ -131,7 +131,7 @@ impl TestCx<'_> {
131131
}
132132

133133
fn run_debuginfo_gdb_test_no_opt(&self) {
134-
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, self.config, &["gdb"])
134+
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, self.config, "gdb")
135135
.unwrap_or_else(|e| self.fatal(&e));
136136
let mut cmds = dbg_cmds.commands.join("\n");
137137

@@ -397,7 +397,7 @@ impl TestCx<'_> {
397397
}
398398

399399
// Parse debugger commands etc from test files
400-
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, self.config, &["lldb"])
400+
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, self.config, "lldb")
401401
.unwrap_or_else(|e| self.fatal(&e));
402402

403403
// Write debugger script:

0 commit comments

Comments
 (0)
Please sign in to comment.