| 1 | # Copyright 2008-2016 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 | # This file is part of the GDB testsuite. |
| 17 | # This test tests the restoration of various kinds of machine state |
| 18 | # to their original values with a process record log. We will execute |
| 19 | # the program forward while it changes various types of data, and |
| 20 | # then execute it backward to see if their values get restored. |
| 21 | # |
| 22 | # The types of machine state (data) that are tested are: |
| 23 | # register variable |
| 24 | # auto variable |
| 25 | # function static variable |
| 26 | # module static variable |
| 27 | # module global variable |
| 28 | # |
| 29 | # TODO: |
| 30 | # various, possibly including... |
| 31 | # .bss variable, .data variable, ... |
| 32 | # shared library variable |
| 33 | # heap variable (pointer)... |
| 34 | # overlay variables... |
| 35 | # Test forward replay |
| 36 | # |
| 37 | |
| 38 | # This test suitable only for process record-replay |
| 39 | if ![supports_process_record] { |
| 40 | return |
| 41 | } |
| 42 | |
| 43 | standard_testfile machinestate.c ms1.c |
| 44 | set precsave [standard_output_file machinestate.precsave] |
| 45 | |
| 46 | if { [prepare_for_testing $testfile.exp $testfile \ |
| 47 | [list $srcfile $srcfile2]] } { |
| 48 | return -1 |
| 49 | } |
| 50 | |
| 51 | set newline "\[\r\n\]+" |
| 52 | |
| 53 | set beginmain [gdb_get_line_number " begin main " $srcfile] |
| 54 | set endmain [gdb_get_line_number " end main " $srcfile] |
| 55 | |
| 56 | # Test begins |
| 57 | |
| 58 | runto main |
| 59 | |
| 60 | if [supports_process_record] { |
| 61 | # Activate process record/replay |
| 62 | gdb_test_no_output "record" "Turn on process record" |
| 63 | } |
| 64 | |
| 65 | gdb_test "break $endmain" \ |
| 66 | "Breakpoint $decimal at .*$srcfile, line $endmain\." \ |
| 67 | "BP at end of main" |
| 68 | |
| 69 | gdb_test "continue" "Breakpoint .* end main .*" "run to end of main" |
| 70 | |
| 71 | gdb_test "record save $precsave" \ |
| 72 | "Saved core file $precsave with execution log\." \ |
| 73 | "save process recfile" |
| 74 | |
| 75 | gdb_test "kill" "" "Kill process, prepare to debug log file" \ |
| 76 | "Kill the program being debugged\\? \\(y or n\\) " "y" |
| 77 | |
| 78 | gdb_test "record restore $precsave" \ |
| 79 | "Restored records from core file .*" \ |
| 80 | "reload prec save file" |
| 81 | |
| 82 | # Proceed to end of main |
| 83 | |
| 84 | gdb_test "break $endmain" \ |
| 85 | "Breakpoint.* file .*$srcfile, line $endmain.*" "" |
| 86 | |
| 87 | gdb_test_multiple "continue" "go to end of main forward" { |
| 88 | -re ".*Breakpoint $decimal,.*$srcfile:$endmain.*$gdb_prompt $" { |
| 89 | pass "go to end of main forward" |
| 90 | } |
| 91 | -re "No more reverse-execution history.* end main .*$gdb_prompt $" { |
| 92 | pass "go to end of main forward" |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | ### |
| 97 | ### |
| 98 | ### |
| 99 | |
| 100 | # Now run backward to each of several points where data is changed. |
| 101 | # |
| 102 | |
| 103 | # Module global variable, reverse |
| 104 | |
| 105 | set breakloc [gdb_get_line_number \ |
| 106 | "module_global_state: set breakpoint here" $srcfile] |
| 107 | |
| 108 | gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" "" |
| 109 | gdb_test "reverse-continue" ".*$srcfile:$breakloc.*" "reverse to $breakloc" |
| 110 | |
| 111 | gdb_test "print aglobal" ".* = 0$newline" "module global reverse-breakpoint" |
| 112 | gdb_test "step" ".* module global post-change .*" "" |
| 113 | gdb_test "print aglobal" ".* = 1$newline" "module global forward past bp" |
| 114 | gdb_test "reverse-step" ".*$newline$breakloc.*" "" |
| 115 | gdb_test "print aglobal" ".* = 0$newline" "module global reverse-step to bp" |
| 116 | |
| 117 | |
| 118 | # Module static variable, reverse |
| 119 | |
| 120 | set breakloc [gdb_get_line_number \ |
| 121 | "module_static_state: set breakpoint here" $srcfile] |
| 122 | |
| 123 | gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" "" |
| 124 | gdb_test "reverse-continue" ".*$srcfile:$breakloc.*" "reverse to $breakloc" |
| 125 | |
| 126 | gdb_test "print astatic" ".* = 0$newline" "module static reverse-breakpoint" |
| 127 | gdb_test "step" ".* module static post-change .*" "" |
| 128 | gdb_test "print astatic" ".* = 1$newline" "module static forward" |
| 129 | gdb_test "reverse-step" ".*$newline$breakloc.*" "" |
| 130 | gdb_test "print astatic" ".* = 0$newline" "module static reverse-step" |
| 131 | |
| 132 | # Function static variable, reverse |
| 133 | |
| 134 | set breakloc [gdb_get_line_number \ |
| 135 | "function_static_state: set breakpoint here" $srcfile] |
| 136 | |
| 137 | gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" "" |
| 138 | gdb_test "reverse-continue" ".*$srcfile:$breakloc.*" "reverse to $breakloc" |
| 139 | |
| 140 | gdb_test "print a" ".* = 0$newline" "function static reverse-breakpoint" |
| 141 | gdb_test "step" ".* function static post-change .*" "" |
| 142 | gdb_test "print a" ".* = 1$newline" "function static forward" |
| 143 | gdb_test "reverse-step" ".*$newline$breakloc.*" "" |
| 144 | gdb_test "print a" ".* = 0$newline" "function static reverse-step" |
| 145 | |
| 146 | # Auto variable, reverse |
| 147 | |
| 148 | set breakloc [gdb_get_line_number \ |
| 149 | "auto_state: set breakpoint here" $srcfile] |
| 150 | |
| 151 | gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" "" |
| 152 | gdb_test "reverse-continue" ".*$srcfile:$breakloc.*" "reverse to $breakloc" |
| 153 | |
| 154 | gdb_test "print a" ".* = 0$newline" "auto var reverse-breakpoint" |
| 155 | gdb_test "step" ".* auto post-change .*" "" |
| 156 | gdb_test "print a" ".* = 1$newline" "auto var forward" |
| 157 | gdb_test "reverse-step" ".*$newline$breakloc.*" "" |
| 158 | gdb_test "print a" ".* = 0$newline" "auto var reverse-step" |
| 159 | |
| 160 | # Register variable, reverse |
| 161 | |
| 162 | set breakloc [gdb_get_line_number \ |
| 163 | "register_state: set breakpoint here" $srcfile] |
| 164 | |
| 165 | gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" "" |
| 166 | gdb_test "reverse-continue" ".*$srcfile:$breakloc.*" "reverse to $breakloc" |
| 167 | |
| 168 | gdb_test "print a" ".* = 0$newline" "register var reverse-breakpoint" |
| 169 | gdb_test "step" ".* register post-change .*" "" |
| 170 | gdb_test "print a" ".* = 1$newline" "register var step post-change" |
| 171 | gdb_test "reverse-step" ".*$newline$breakloc.*" "" |
| 172 | gdb_test "print a" ".* = 0$newline" "register var reverse step-to" |
| 173 | |
| 174 | # Proceed to beginning of main |
| 175 | |
| 176 | gdb_test "tbreak $beginmain" ".*$srcfile, line $beginmain.*" "" |
| 177 | gdb_test "reverse-continue" ".*$srcfile:$beginmain.*" "reverse to main" |
| 178 | |
| 179 | # Now repeat tests while replaying forward. |
| 180 | |
| 181 | # Register variable, forward |
| 182 | |
| 183 | set breakloc [gdb_get_line_number \ |
| 184 | "register_state: set breakpoint here" $srcfile] |
| 185 | |
| 186 | gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" "" |
| 187 | gdb_test "continue" ".*$srcfile:$breakloc.*" "forward to $breakloc" |
| 188 | |
| 189 | gdb_test "print a" ".* = 0$newline" "register var forward-breakpoint" |
| 190 | gdb_test "reverse-step" ".*hide.*" "" |
| 191 | gdb_test "step" ".*$newline$breakloc.*" "" |
| 192 | gdb_test "print a" ".* = 0$newline" "register var forward step-to" |
| 193 | gdb_test "step" ".* register post-change .*" "" |
| 194 | gdb_test "print a" ".* = 1$newline" "register var step post-change" |
| 195 | |
| 196 | # Auto variable, forward |
| 197 | |
| 198 | set breakloc [gdb_get_line_number \ |
| 199 | "auto_state: set breakpoint here" $srcfile] |
| 200 | |
| 201 | gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" "" |
| 202 | gdb_test "continue" ".*$srcfile:$breakloc.*" "forward to $breakloc" |
| 203 | |
| 204 | gdb_test "print a" ".* = 0$newline" "auto var forward-breakpoint" |
| 205 | gdb_test "reverse-step" ".*hide.*" "" |
| 206 | gdb_test "step" ".*$newline$breakloc.*" "" |
| 207 | gdb_test "print a" ".* = 0$newline" "auto var forward step-to" |
| 208 | gdb_test "step" ".* auto post-change .*" "" |
| 209 | gdb_test "print a" ".* = 1$newline" "auto var step post-change" |
| 210 | |
| 211 | # Function static variable, forward |
| 212 | |
| 213 | set breakloc [gdb_get_line_number \ |
| 214 | "function_static_state: set breakpoint here" $srcfile] |
| 215 | |
| 216 | gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" "" |
| 217 | gdb_test "continue" ".*$srcfile:$breakloc.*" "forward to $breakloc" |
| 218 | |
| 219 | gdb_test "print a" ".* = 0$newline" "function static forward-breakpoint" |
| 220 | gdb_test "reverse-step" ".*hide.*" "" |
| 221 | gdb_test "step" ".*$newline$breakloc.*" "" |
| 222 | gdb_test "print a" ".* = 0$newline" "function static forward step-to" |
| 223 | gdb_test "step" ".* function static post-change .*" "" |
| 224 | gdb_test "print a" ".* = 1$newline" "function static step post-change" |
| 225 | |
| 226 | # Module static variable, forward |
| 227 | |
| 228 | set breakloc [gdb_get_line_number \ |
| 229 | "module_static_state: set breakpoint here" $srcfile] |
| 230 | |
| 231 | gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" "" |
| 232 | gdb_test "continue" ".*$srcfile:$breakloc.*" "forward to $breakloc" |
| 233 | |
| 234 | gdb_test "print astatic" ".* = 0$newline" "module static forward-breakpoint" |
| 235 | gdb_test "reverse-step" ".*hide.*" "" |
| 236 | gdb_test "step" ".*$newline$breakloc.*" "" |
| 237 | gdb_test "print astatic" ".* = 0$newline" "module static forward step-to" |
| 238 | gdb_test "step" ".* module static post-change .*" "" |
| 239 | gdb_test "print astatic" ".* = 1$newline" "module static step post-change" |
| 240 | |
| 241 | # Module global variable, forward |
| 242 | |
| 243 | set breakloc [gdb_get_line_number \ |
| 244 | "module_global_state: set breakpoint here" $srcfile] |
| 245 | |
| 246 | gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" "" |
| 247 | gdb_test "continue" ".*$srcfile:$breakloc.*" "forward to $breakloc" |
| 248 | |
| 249 | gdb_test "print aglobal" ".* = 0$newline" "module global forward-breakpoint" |
| 250 | gdb_test "reverse-step" ".*hide.*" "" |
| 251 | gdb_test "step" ".*$newline$breakloc.*" "" |
| 252 | gdb_test "print aglobal" ".* = 0$newline" "module global forward step-to" |
| 253 | gdb_test "step" ".* module global post-change .*" "" |
| 254 | gdb_test "print aglobal" ".* = 1$newline" "module global step post-change" |
| 255 | |