Home | History | Annotate | Line # | Download | only in gdb.reverse
      1 #   Copyright 2022-2024 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.  It tests the functionality of
     17 # the maintenance print record-instruction command, but does not check the
     18 # syntax, only if the command finds or fails to find recorded history.
     19 # This is done by putting the inferior in mulpitle states with and without
     20 # history to be printed, then checking if GDB is able to print an
     21 # instruction or not.
     22 # To identify if GDB has printed an instruction, we can see if some
     23 # change is printed, since any instruction must have at least a change
     24 # to the PC.
     25 
     26 if ![supports_reverse] {
     27     return
     28 }
     29 
     30 standard_testfile
     31 
     32 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
     33     return -1
     34 }
     35 
     36 proc test_print { has_history level test_name } {
     37     gdb_test_multiple "maint print record-instruction $level" $test_name {
     38 	-re -wrap ".*Not enough recorded history.*" {
     39 	    gdb_assert !$has_history $test_name
     40 	}
     41 
     42     -re -wrap ".*changed.*" {
     43 	    gdb_assert $has_history $test_name
     44 	}
     45     }
     46 }
     47 
     48 if { ![runto_main] } {
     49     return 0
     50 }
     51 
     52 #confirm that GDB doesn't go crazy if recording isn't enabled
     53 test_print false "" "print before starting to record"
     54 
     55 if ![supports_process_record] {
     56     # No point in testing the rest if we can't record anything
     57     return
     58 }
     59 
     60 gdb_test_no_output "record" "turn on process record"
     61 
     62 test_print false "" "print before any instruction"
     63 
     64 gdb_test "stepi 3" ".*" "collecting history"
     65 test_print true "" "print current after executing a bit"
     66 test_print true "-1" "print previous after executing a bit"
     67 test_print false "1" "print following after executing a bit"
     68 
     69 gdb_test "reverse-stepi" ".*" "moving back"
     70 test_print true "" "print current after reversing"
     71 test_print true "-1" "print previous after reversing"
     72 test_print true "1" "print following after reversing"
     73 
     74 test_print false "-10" "trying to print too far back"
     75 test_print false "10" "trying to print too far forward"
     76