1 # Copyright 2009-2014 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
42 standard_testfile basics.c
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
45 untested ${testfile}.exp
51 if [supports_process_record] {
52 # Activate process record/replay
53 if [mi_gdb_test "-interpreter-exec console record" \
54 "=record-started,thread-group=\"i1\"\r\n\\^done" \
55 "Turn on process record"] {
56 warning "Fail to activate process record/replay, tests in this group will not be performed.\n"
61 # Locate line numbers in basics.c.
62 set line_callee4_head [gdb_get_line_number "callee4 ("]
63 set line_callee4_body [expr $line_callee4_head + 2]
64 set line_callee3_head [gdb_get_line_number "callee3 ("]
65 set line_callee3_body [expr $line_callee3_head + 2]
66 set line_callee3_close [expr $line_callee3_head + 3]
67 set line_callee2_head [gdb_get_line_number "callee2 ("]
68 set line_callee2_body [expr $line_callee2_head + 2]
69 set line_callee2_close [expr $line_callee2_head + 3]
70 set line_callee1_head [gdb_get_line_number "callee1 ("]
71 set line_callee1_body [expr $line_callee1_head + 2]
72 set line_callee1_close [expr $line_callee1_head + 3]
73 set line_callme_head [gdb_get_line_number "callme"]
74 set line_callme_body [expr $line_callme_head + 2]
75 set line_main_head [gdb_get_line_number "main ("]
76 set line_main_body [expr $line_main_head + 2]
77 set line_main_hello [gdb_get_line_number "Hello, World!"]
78 set line_main_callme_1 [gdb_get_line_number "callme (1"]
80 # Forward execute to the callme() function, so that we can
81 # execute backward from there.
85 proc test_controlled_execution_reverse {} {
90 global line_callee4_head line_callee4_body
91 global line_callee3_head line_callee3_body line_callee3_close
92 global line_callee2_head line_callee2_body line_callee2_close
93 global line_callee1_head line_callee1_body line_callee1_close
94 global line_main_head line_main_body
95 global line_main_hello line_main_callme_1
97 # Test exec-reverse-finish
99 mi_execute_to "exec-finish --reverse" \
100 "end-stepping-range" "main" "" \
101 "basics.c" $line_main_callme_1 "" \
102 "reverse finish from callme"
104 # Test exec-reverse-next
105 # It takes two steps to get back to the previous line,
106 # as the first step moves us to the start of the current line,
107 # and the one after that moves back to the previous line.
109 mi_execute_to "exec-next --reverse 2" \
110 "end-stepping-range" "main" "" \
111 "basics.c" $line_main_hello "" \
112 "reverse next to get over the call to do_nothing"
114 # Test exec-reverse-step
116 mi_execute_to "exec-step --reverse" \
117 "end-stepping-range" "callee1" \
118 "\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}" \
119 "basics.c" $line_callee1_close "" \
120 "reverse step to callee1"
122 mi_execute_to "exec-step --reverse" \
123 "end-stepping-range" "callee2" \
124 "\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\}" \
125 "basics.c" $line_callee2_close "" \
126 "reverse step to callee2"
128 mi_execute_to "exec-step --reverse" \
129 "end-stepping-range" "callee3" \
130 "\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\}" \
131 "basics.c" $line_callee3_close "" \
132 "reverse step to callee3"
134 mi_execute_to "exec-step --reverse" \
135 "end-stepping-range" "callee4" "" \
136 "basics.c" "\[0-9\]+" "" \
137 "reverse step to callee4"
139 # Test exec-reverse-[step|next]-instruction
141 mi_execute_to "exec-step-instruction --reverse" \
142 "end-stepping-range" "callee4" "" \
143 "basics.c" "\[0-9\]+" "" \
144 "reverse-step-instruction at callee4"
146 mi_execute_to "exec-next-instruction --reverse" \
147 "end-stepping-range" "callee4" "" \
148 "basics.c" "\[0-9\]+" "" \
149 "reverse-next-instruction at callee4"
151 # Test exec-reverse-continue
153 mi_create_breakpoint "-t basics.c:$line_callee3_head" \
154 "insert temp breakpoint at basics.c:$line_callee3_head" \
155 -number 3 -disp del -func callee3 -file ".*basics.c" \
156 -line $line_callee3_head
158 mi_execute_to "exec-continue --reverse" \
159 "breakpoint-hit" "callee3" \
160 "\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\}" \
161 "basics.c" "\[0-9\]+" \
162 { "" "disp=\"del\""} \
163 "reverse-continue at callee3"
165 mi_execute_to "exec-continue --reverse" \
167 "basics.c" $line_main_body "" \
168 "reverse-continue at main"
171 test_controlled_execution_reverse