Home | History | Annotate | Line # | Download | only in gdb.base
valgrind-disp-step.exp revision 1.1
      1 # Copyright 2012-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 # Step over breakpoints with displaced stepping on, against Valgrind.
     17 # We can't really use displaced stepping with Valgrind, so what this
     18 # really tests is that GDB falls back to in-line stepping
     19 # automatically instead of getting stuck or crashing.
     20 
     21 if [is_remote target] {
     22     # The test always runs locally.
     23     return 0
     24 }
     25 
     26 standard_testfile .c
     27 if {[build_executable "failed to build" $testfile $srcfile {debug}] == -1} {
     28     return -1
     29 }
     30 
     31 set test "spawn valgrind"
     32 set cmd "valgrind --vgdb-error=0 $binfile"
     33 set res [remote_spawn host $cmd]
     34 if { $res < 0 || $res == "" } {
     35     verbose -log "Spawning $cmd failed."
     36     unsupported $test
     37     return -1
     38 }
     39 pass $test
     40 # Declare GDB now as running.
     41 set gdb_spawn_id $res
     42 
     43 # GDB started by vgdb stops already after the startup is executed, like with
     44 # non-extended gdbserver.  It is also not correct to run/attach the inferior.
     45 set use_gdb_stub 1
     46 
     47 set test "valgrind started"
     48 # The trailing '.' differs for different memcheck versions.
     49 gdb_test_multiple "" $test {
     50     -re "Memcheck, a memory error detector\\.?\r\n" {
     51 	pass $test
     52     }
     53     -re "valgrind: failed to start tool 'memcheck' for platform '.*': No such file or directory" {
     54 	unsupported $test
     55 	return -1
     56     }
     57     -re "valgrind: wrong ELF executable class" {
     58 	unsupported $test
     59 	return -1
     60     }
     61     -re "command not found" {
     62 	# The spawn succeeded, but then valgrind was not found - e.g. if
     63 	# we spawned SSH to a remote system.
     64 	unsupported $test
     65 	return -1
     66     }
     67     -re "valgrind: Bad option.*--vgdb-error=0" {
     68 	# valgrind is not >= 3.7.0.
     69 	unsupported $test
     70 	return -1
     71     }
     72 }
     73 
     74 set test "vgdb prompt"
     75 # The trailing '.' differs for different memcheck versions.
     76 gdb_test_multiple "" $test {
     77     -re "  (target remote | \[^\r\n\]*/vgdb \[^\r\n\]*)\r\n" {
     78 	set vgdbcmd $expect_out(1,string)
     79 	pass $test
     80     }
     81 }
     82 
     83 # Do not kill valgrind.
     84 set valgrind_pid [exp_pid -i [board_info host fileid]]
     85 unset gdb_spawn_id
     86 set board [host_info name]
     87 unset_board_info fileid
     88 
     89 clean_restart $testfile
     90 
     91 # Make sure we're disconnected, in case we're testing with the
     92 # native-extended-gdbserver board, where gdb_start/gdb_load spawn
     93 # gdbserver and connect to it.
     94 gdb_test "disconnect" ".*"
     95 
     96 gdb_test "$vgdbcmd" " in \\.?_start .*" "target remote for vgdb"
     97 
     98 gdb_test "monitor v.set gdb_output" "valgrind output will go to gdb.*"
     99 
    100 gdb_test_no_output "set displaced-stepping off"
    101 gdb_breakpoint "main" "breakpoint at main"
    102 gdb_test "continue" " stop 0 .*" "continue to main"
    103 delete_breakpoints
    104 
    105 set curr_stop 0
    106 foreach displaced { "off" "on" } {
    107     with_test_prefix "displaced $displaced" {
    108 
    109 	gdb_test_no_output "set displaced-stepping $displaced"
    110 
    111 	foreach go { "once" "twice" } {
    112 	    with_test_prefix $go {
    113 		gdb_test "break" "Breakpoint .* at .*" "set breakpoint"
    114 
    115 		# Whether we should see a warning.
    116 		set should_warn [expr {$go == "once" && $displaced == "on"}]
    117 
    118 		incr curr_stop
    119 
    120 		set msg "step over breakpoint"
    121 		set pattern " stop $curr_stop .*$gdb_prompt $"
    122 		gdb_test_multiple "next" $msg {
    123 		    -re "warning: disabling displaced stepping.*$pattern" {
    124 			gdb_assert $should_warn $msg
    125 		    }
    126 		    -re "$pattern" {
    127 			gdb_assert !$should_warn $msg
    128 		    }
    129 		}
    130 	    }
    131 	}
    132     }
    133 }
    134 
    135 # Only if valgrind got stuck.
    136 remote_exec host "kill -9 ${valgrind_pid}"
    137