1 # Copyright 2009-2023 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test Machine interface (MI) operations
17 # Verify that, using the MI, we can run a simple program in both forward
18 # and reverse directions with the following execution commands:
23 # - exec-next-instruction
24 # - exec-step-instruction
26 # The goal is not to test gdb functionality, which is done by other tests,
27 # but to verify the correct output response to MI operations.
30 if ![supports_reverse] {
34 load_lib mi-support.exp
37 standard_testfile basics.c
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40 untested "failed to compile"
44 mi_clean_restart $binfile
47 if [supports_process_record] {
48 # Activate process record/replay
49 if [mi_gdb_test "-interpreter-exec console record" \
50 "=record-started,thread-group=\"i1\",method=\"full\"\r\n\\^done" \
51 "Turn on process record"] {
52 warning "Fail to activate process record/replay, tests in this group will not be performed.\n"
57 # Locate line numbers in basics.c.
58 set line_callee4_head [gdb_get_line_number "callee4 ("]
59 set line_callee4_body [expr $line_callee4_head + 2]
60 set line_callee3_head [gdb_get_line_number "callee3 ("]
61 set line_callee3_body [expr $line_callee3_head + 2]
62 set line_callee3_close [expr $line_callee3_head + 3]
63 set line_callee2_head [gdb_get_line_number "callee2 ("]
64 set line_callee2_body [expr $line_callee2_head + 2]
65 set line_callee2_close [expr $line_callee2_head + 3]
66 set line_callee1_head [gdb_get_line_number "callee1 ("]
67 set line_callee1_body [expr $line_callee1_head + 2]
68 set line_callee1_close [expr $line_callee1_head + 3]
69 set line_callme_head [gdb_get_line_number "callme"]
70 set line_callme_body [expr $line_callme_head + 2]
71 set line_main_head [gdb_get_line_number "main ("]
72 set line_main_body [expr $line_main_head + 2]
73 set line_main_hello [gdb_get_line_number "Hello, World!"]
74 set line_main_callme_1 [gdb_get_line_number "callme (1"]
76 # Forward execute to the callme() function, so that we can
77 # execute backward from there.
81 proc test_controlled_execution_reverse {} {
86 global line_callee4_head line_callee4_body
87 global line_callee3_head line_callee3_body line_callee3_close
88 global line_callee2_head line_callee2_body line_callee2_close
89 global line_callee1_head line_callee1_body line_callee1_close
90 global line_main_head line_main_body
91 global line_main_hello line_main_callme_1
93 # Test exec-reverse-finish
95 mi_execute_to "exec-finish --reverse" \
96 "end-stepping-range" "main" "" \
97 "basics.c" $line_main_callme_1 "" \
98 "reverse finish from callme"
100 # Test exec-reverse-next
101 # It takes two steps to get back to the previous line,
102 # as the first step moves us to the start of the current line,
103 # and the one after that moves back to the previous line.
105 mi_execute_to "exec-next --reverse 2" \
106 "end-stepping-range" "main" "" \
107 "basics.c" $line_main_hello "" \
108 "reverse next to get over the call to do_nothing"
110 # Test exec-reverse-step
112 mi_execute_to "exec-step --reverse" \
113 "end-stepping-range" "callee1" \
114 "\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\[0-9\]*\"\}" \
115 "basics.c" $line_callee1_close "" \
116 "reverse step to callee1"
118 mi_execute_to "exec-step --reverse" \
119 "end-stepping-range" "callee2" \
120 "\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\}" \
121 "basics.c" $line_callee2_close "" \
122 "reverse step to callee2"
124 mi_execute_to "exec-step --reverse" \
125 "end-stepping-range" "callee3" \
126 "\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\}" \
127 "basics.c" $line_callee3_close "" \
128 "reverse step to callee3"
130 mi_execute_to "exec-step --reverse" \
131 "end-stepping-range" "callee4" "" \
132 "basics.c" "\[0-9\]+" "" \
133 "reverse step to callee4"
135 # Test exec-reverse-[step|next]-instruction
137 mi_execute_to "exec-step-instruction --reverse" \
138 "end-stepping-range" "callee4" "" \
139 "basics.c" "\[0-9\]+" "" \
140 "reverse-step-instruction at callee4"
142 mi_execute_to "exec-next-instruction --reverse" \
143 "end-stepping-range" "callee4" "" \
144 "basics.c" "\[0-9\]+" "" \
145 "reverse-next-instruction at callee4"
147 # Test exec-reverse-continue
149 mi_create_breakpoint "-t basics.c:$line_callee3_head" \
150 "insert temp breakpoint at basics.c:$line_callee3_head" \
151 -number 3 -disp del -func callee3 -file ".*basics.c" \
152 -line $line_callee3_body
154 mi_execute_to "exec-continue --reverse" \
155 "breakpoint-hit" "callee3" \
156 "\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\}" \
157 "basics.c" "\[0-9\]+" \
158 { "" "disp=\"del\""} \
159 "reverse-continue at callee3"
161 mi_execute_to "exec-continue --reverse" \
163 "basics.c" $line_main_body "" \
164 "reverse-continue at main"
167 test_controlled_execution_reverse