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