@@ -38,6 +38,9 @@ use tracing::*;
3838use crate :: extract_gdb_version;
3939use crate :: is_android_gdb_target;
4040
41+ mod debugger;
42+ use debugger:: DebuggerCommands ;
43+
4144#[ cfg( test) ]
4245mod tests;
4346
@@ -200,12 +203,6 @@ struct TestCx<'test> {
200203 revision : Option < & ' test str > ,
201204}
202205
203- struct DebuggerCommands {
204- commands : Vec < String > ,
205- check_lines : Vec < String > ,
206- breakpoint_lines : Vec < usize > ,
207- }
208-
209206enum ReadFrom {
210207 Path ,
211208 Stdin ( String ) ,
@@ -674,7 +671,10 @@ impl<'test> TestCx<'test> {
674671
675672 // Parse debugger commands etc from test files
676673 let DebuggerCommands { commands, check_lines, breakpoint_lines, .. } =
677- self . parse_debugger_commands ( prefixes) ;
674+ match DebuggerCommands :: parse_from ( & self . testpaths . file , self . config , prefixes) {
675+ Ok ( cmds) => cmds,
676+ Err ( e) => self . fatal ( & e) ,
677+ } ;
678678
679679 // https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-commands
680680 let mut script_str = String :: with_capacity ( 2048 ) ;
@@ -757,7 +757,10 @@ impl<'test> TestCx<'test> {
757757 } ;
758758
759759 let DebuggerCommands { commands, check_lines, breakpoint_lines } =
760- self . parse_debugger_commands ( prefixes) ;
760+ match DebuggerCommands :: parse_from ( & self . testpaths . file , self . config , prefixes) {
761+ Ok ( cmds) => cmds,
762+ Err ( e) => self . fatal ( & e) ,
763+ } ;
761764 let mut cmds = commands. join ( "\n " ) ;
762765
763766 // compile test file (it should have 'compile-flags:-g' in the header)
@@ -1018,7 +1021,10 @@ impl<'test> TestCx<'test> {
10181021
10191022 // Parse debugger commands etc from test files
10201023 let DebuggerCommands { commands, check_lines, breakpoint_lines, .. } =
1021- self . parse_debugger_commands ( prefixes) ;
1024+ match DebuggerCommands :: parse_from ( & self . testpaths . file , self . config , prefixes) {
1025+ Ok ( cmds) => cmds,
1026+ Err ( e) => self . fatal ( & e) ,
1027+ } ;
10221028
10231029 // Write debugger script:
10241030 // We don't want to hang when calling `quit` while the process is still running
@@ -1131,45 +1137,6 @@ impl<'test> TestCx<'test> {
11311137 ProcRes { status, stdout : out, stderr : err, cmdline : format ! ( "{:?}" , cmd) }
11321138 }
11331139
1134- fn parse_debugger_commands ( & self , debugger_prefixes : & [ & str ] ) -> DebuggerCommands {
1135- let directives = debugger_prefixes
1136- . iter ( )
1137- . map ( |prefix| ( format ! ( "{}-command" , prefix) , format ! ( "{}-check" , prefix) ) )
1138- . collect :: < Vec < _ > > ( ) ;
1139-
1140- let mut breakpoint_lines = vec ! [ ] ;
1141- let mut commands = vec ! [ ] ;
1142- let mut check_lines = vec ! [ ] ;
1143- let mut counter = 1 ;
1144- let reader = BufReader :: new ( File :: open ( & self . testpaths . file ) . unwrap ( ) ) ;
1145- for line in reader. lines ( ) {
1146- match line {
1147- Ok ( line) => {
1148- let line =
1149- if line. starts_with ( "//" ) { line[ 2 ..] . trim_start ( ) } else { line. as_str ( ) } ;
1150-
1151- if line. contains ( "#break" ) {
1152- breakpoint_lines. push ( counter) ;
1153- }
1154-
1155- for & ( ref command_directive, ref check_directive) in & directives {
1156- self . config
1157- . parse_name_value_directive ( & line, command_directive)
1158- . map ( |cmd| commands. push ( cmd) ) ;
1159-
1160- self . config
1161- . parse_name_value_directive ( & line, check_directive)
1162- . map ( |cmd| check_lines. push ( cmd) ) ;
1163- }
1164- }
1165- Err ( e) => self . fatal ( & format ! ( "Error while parsing debugger commands: {}" , e) ) ,
1166- }
1167- counter += 1 ;
1168- }
1169-
1170- DebuggerCommands { commands, check_lines, breakpoint_lines }
1171- }
1172-
11731140 fn cleanup_debug_info_options ( & self , options : & Option < String > ) -> Option < String > {
11741141 if options. is_none ( ) {
11751142 return None ;
0 commit comments