| 1 | # Copyright 2009-2019 Free Software Foundation, Inc. |
| 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 | |
| 30 | if ![supports_reverse] { |
| 31 | return |
| 32 | } |
| 33 | |
| 34 | load_lib mi-support.exp |
| 35 | set MIFLAGS "-i=mi" |
| 36 | |
| 37 | gdb_exit |
| 38 | if [mi_gdb_start] { |
| 39 | continue |
| 40 | } |
| 41 | |
| 42 | standard_testfile basics.c |
| 43 | |
| 44 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
| 45 | untested "failed to compile" |
| 46 | return -1 |
| 47 | } |
| 48 | |
| 49 | mi_run_to_main |
| 50 | |
| 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\",method=\"full\"\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" |
| 57 | return -1 |
| 58 | } |
| 59 | } |
| 60 | |
| 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"] |
| 79 | |
| 80 | # Forward execute to the callme() function, so that we can |
| 81 | # execute backward from there. |
| 82 | mi_continue_to callme |
| 83 | mi_delete_breakpoints |
| 84 | |
| 85 | proc test_controlled_execution_reverse {} { |
| 86 | global mi_gdb_prompt |
| 87 | global srcfile |
| 88 | global hex |
| 89 | |
| 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 |
| 96 | |
| 97 | # Test exec-reverse-finish |
| 98 | |
| 99 | mi_execute_to "exec-finish --reverse" \ |
| 100 | "end-stepping-range" "main" "" \ |
| 101 | "basics.c" $line_main_callme_1 "" \ |
| 102 | "reverse finish from callme" |
| 103 | |
| 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. |
| 108 | |
| 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" |
| 113 | |
| 114 | # Test exec-reverse-step |
| 115 | |
| 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" |
| 121 | |
| 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" |
| 127 | |
| 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" |
| 133 | |
| 134 | mi_execute_to "exec-step --reverse" \ |
| 135 | "end-stepping-range" "callee4" "" \ |
| 136 | "basics.c" "\[0-9\]+" "" \ |
| 137 | "reverse step to callee4" |
| 138 | |
| 139 | # Test exec-reverse-[step|next]-instruction |
| 140 | |
| 141 | mi_execute_to "exec-step-instruction --reverse" \ |
| 142 | "end-stepping-range" "callee4" "" \ |
| 143 | "basics.c" "\[0-9\]+" "" \ |
| 144 | "reverse-step-instruction at callee4" |
| 145 | |
| 146 | mi_execute_to "exec-next-instruction --reverse" \ |
| 147 | "end-stepping-range" "callee4" "" \ |
| 148 | "basics.c" "\[0-9\]+" "" \ |
| 149 | "reverse-next-instruction at callee4" |
| 150 | |
| 151 | # Test exec-reverse-continue |
| 152 | |
| 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_body |
| 157 | |
| 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" |
| 164 | |
| 165 | mi_execute_to "exec-continue --reverse" \ |
| 166 | "" "main" "" \ |
| 167 | "basics.c" $line_main_body "" \ |
| 168 | "reverse-continue at main" |
| 169 | } |
| 170 | |
| 171 | test_controlled_execution_reverse |
| 172 | |
| 173 | mi_gdb_exit |
| 174 | return 0 |