@@ -38,6 +38,9 @@ use tracing::*;
38
38
use crate :: extract_gdb_version;
39
39
use crate :: is_android_gdb_target;
40
40
41
+ mod debugger;
42
+ use debugger:: DebuggerCommands ;
43
+
41
44
#[ cfg( test) ]
42
45
mod tests;
43
46
@@ -200,12 +203,6 @@ struct TestCx<'test> {
200
203
revision : Option < & ' test str > ,
201
204
}
202
205
203
- struct DebuggerCommands {
204
- commands : Vec < String > ,
205
- check_lines : Vec < String > ,
206
- breakpoint_lines : Vec < usize > ,
207
- }
208
-
209
206
enum ReadFrom {
210
207
Path ,
211
208
Stdin ( String ) ,
@@ -674,7 +671,10 @@ impl<'test> TestCx<'test> {
674
671
675
672
// Parse debugger commands etc from test files
676
673
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
+ } ;
678
678
679
679
// https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-commands
680
680
let mut script_str = String :: with_capacity ( 2048 ) ;
@@ -757,7 +757,10 @@ impl<'test> TestCx<'test> {
757
757
} ;
758
758
759
759
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
+ } ;
761
764
let mut cmds = commands. join ( "\n " ) ;
762
765
763
766
// compile test file (it should have 'compile-flags:-g' in the header)
@@ -1018,7 +1021,10 @@ impl<'test> TestCx<'test> {
1018
1021
1019
1022
// Parse debugger commands etc from test files
1020
1023
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
+ } ;
1022
1028
1023
1029
// Write debugger script:
1024
1030
// We don't want to hang when calling `quit` while the process is still running
@@ -1131,45 +1137,6 @@ impl<'test> TestCx<'test> {
1131
1137
ProcRes { status, stdout : out, stderr : err, cmdline : format ! ( "{:?}" , cmd) }
1132
1138
}
1133
1139
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
-
1173
1140
fn cleanup_debug_info_options ( & self , options : & Option < String > ) -> Option < String > {
1174
1141
if options. is_none ( ) {
1175
1142
return None ;
0 commit comments