Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 2009-2022 Free Software Foundation, Inc. |
8a980b44 PA |
2 | |
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. | |
7 | # | |
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. | |
12 | # | |
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/>. | |
15 | ||
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: | |
19 | # - exec-continue | |
20 | # - exec-finish | |
21 | # - exec-next | |
22 | # - exec-step | |
23 | # - exec-next-instruction | |
24 | # - exec-step-instruction | |
25 | ||
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. | |
28 | # | |
29 | ||
979ade8b | 30 | if ![supports_reverse] { |
8a980b44 PA |
31 | return |
32 | } | |
33 | ||
34 | load_lib mi-support.exp | |
35 | set MIFLAGS "-i=mi" | |
36 | ||
298a9cf0 TT |
37 | standard_testfile basics.c |
38 | ||
9357e021 | 39 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
5b362f04 | 40 | untested "failed to compile" |
8a980b44 PA |
41 | return -1 |
42 | } | |
43 | ||
b75d55d4 PA |
44 | mi_clean_restart $binfile |
45 | mi_runto_main | |
8a980b44 | 46 | |
979ade8b | 47 | if [supports_process_record] { |
8a980b44 PA |
48 | # Activate process record/replay |
49 | if [mi_gdb_test "-interpreter-exec console record" \ | |
647c264c | 50 | "=record-started,thread-group=\"i1\",method=\"full\"\r\n\\^done" \ |
82a90ccf | 51 | "Turn on process record"] { |
4ec70201 | 52 | warning "Fail to activate process record/replay, tests in this group will not be performed.\n" |
8a980b44 PA |
53 | return -1 |
54 | } | |
55 | } | |
56 | ||
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"] | |
75 | ||
76 | # Forward execute to the callme() function, so that we can | |
77 | # execute backward from there. | |
78 | mi_continue_to callme | |
79 | mi_delete_breakpoints | |
80 | ||
81 | proc test_controlled_execution_reverse {} { | |
82 | global mi_gdb_prompt | |
83 | global srcfile | |
84 | global hex | |
85 | ||
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 | |
92 | ||
93 | # Test exec-reverse-finish | |
94 | ||
95 | mi_execute_to "exec-finish --reverse" \ | |
96 | "end-stepping-range" "main" "" \ | |
97 | "basics.c" $line_main_callme_1 "" \ | |
98 | "reverse finish from callme" | |
99 | ||
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. | |
104 | ||
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" | |
109 | ||
110 | # Test exec-reverse-step | |
111 | ||
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\"\}" \ | |
115 | "basics.c" $line_callee1_close "" \ | |
116 | "reverse step to callee1" | |
117 | ||
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" | |
123 | ||
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" | |
129 | ||
130 | mi_execute_to "exec-step --reverse" \ | |
131 | "end-stepping-range" "callee4" "" \ | |
132 | "basics.c" "\[0-9\]+" "" \ | |
133 | "reverse step to callee4" | |
134 | ||
135 | # Test exec-reverse-[step|next]-instruction | |
136 | ||
137 | mi_execute_to "exec-step-instruction --reverse" \ | |
138 | "end-stepping-range" "callee4" "" \ | |
139 | "basics.c" "\[0-9\]+" "" \ | |
140 | "reverse-step-instruction at callee4" | |
141 | ||
142 | mi_execute_to "exec-next-instruction --reverse" \ | |
143 | "end-stepping-range" "callee4" "" \ | |
144 | "basics.c" "\[0-9\]+" "" \ | |
145 | "reverse-next-instruction at callee4" | |
146 | ||
147 | # Test exec-reverse-continue | |
148 | ||
149 | mi_create_breakpoint "-t basics.c:$line_callee3_head" \ | |
4b48d439 KS |
150 | "insert temp breakpoint at basics.c:$line_callee3_head" \ |
151 | -number 3 -disp del -func callee3 -file ".*basics.c" \ | |
a9e40818 | 152 | -line $line_callee3_body |
8a980b44 PA |
153 | |
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" | |
160 | ||
161 | mi_execute_to "exec-continue --reverse" \ | |
162 | "" "main" "" \ | |
163 | "basics.c" $line_main_body "" \ | |
164 | "reverse-continue at main" | |
165 | } | |
166 | ||
167 | test_controlled_execution_reverse | |
168 | ||
169 | mi_gdb_exit | |
170 | return 0 |