]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/valgrind-disp-step.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / valgrind-disp-step.exp
CommitLineData
e2882c85 1# Copyright 2012-2018 Free Software Foundation, Inc.
3fc8eb30
PA
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
21if [is_remote target] {
22 # The test always runs locally.
23 return 0
24}
25
26standard_testfile .c
27if {[build_executable "failed to build" $testfile $srcfile {debug}] == -1} {
28 return -1
29}
30
31set test "spawn valgrind"
32set cmd "valgrind --vgdb-error=0 $binfile"
33set res [remote_spawn host $cmd]
34if { $res < 0 || $res == "" } {
35 verbose -log "Spawning $cmd failed."
36 unsupported $test
37 return -1
38}
39pass $test
40# Declare GDB now as running.
41set 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.
45set use_gdb_stub 1
46
47set test "valgrind started"
48# The trailing '.' differs for different memcheck versions.
49gdb_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
74set test "vgdb prompt"
75# The trailing '.' differs for different memcheck versions.
76gdb_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.
84set valgrind_pid [exp_pid -i [board_info host fileid]]
85unset gdb_spawn_id
86set board [host_info name]
87unset_board_info fileid
88
89clean_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.
94gdb_test "disconnect" ".*"
95
96gdb_test "$vgdbcmd" " in \\.?_start .*" "target remote for vgdb"
97
98gdb_test "monitor v.set gdb_output" "valgrind output will go to gdb.*"
99
100gdb_test_no_output "set displaced-stepping off"
101gdb_breakpoint "main" "breakpoint at main"
102gdb_test "continue" " stop 0 .*" "continue to main"
103delete_breakpoints
104
105set curr_stop 0
106foreach 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.
136remote_exec host "kill -9 ${valgrind_pid}"