1 # Copyright 2012-2013 Free Software Foundation, Inc.
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.
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.
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/>.
16 if [is_remote target] {
17 # The test always runs locally.
21 set test valgrind-infcall
24 set binfile ${objdir}/${subdir}/${executable}
25 if {[build_executable $test.exp $executable $srcfile {debug}] == -1} {
29 set test "spawn valgrind"
30 set cmd "valgrind --vgdb-error=0 $binfile"
31 set res [remote_spawn host $cmd];
32 if { $res < 0 || $res == "" } {
33 verbose -log "Spawning $cmd failed."
38 # Declare GDB now as running.
41 # GDB started by vgdb stops already after the startup is executed, like with
42 # non-extended gdbserver. It is also not correct to run/attach the inferior.
45 set test "valgrind started"
46 # The trailing '.' differs for different memcheck versions.
47 gdb_test_multiple "" $test {
48 -re "Memcheck, a memory error detector\\.?\r\n" {
51 -re "valgrind: failed to start tool 'memcheck' for platform '.*': No such file or directory" {
55 -re "valgrind: wrong ELF executable class" {
59 -re "command not found" {
60 # The spawn succeeded, but then valgrind was not found - e.g. if
61 # we spawned SSH to a remote system.
65 -re "valgrind: Bad option.*--vgdb-error=0" {
66 # valgrind is not >= 3.7.0.
72 set test "vgdb prompt"
73 # The trailing '.' differs for different memcheck versions.
74 gdb_test_multiple "" $test {
75 -re " (target remote | \[^\r\n\]*/vgdb \[^\r\n\]*)\r\n" {
76 set vgdbcmd $expect_out(1,string)
81 # Do not kill valgrind.
82 set valgrind_pid [exp_pid -i [board_info host fileid]]
84 set board [host_info name]
85 unset_board_info fileid
87 clean_restart $executable
89 gdb_test "$vgdbcmd" " in \\.?_start .*" "target remote for vgdb"
91 gdb_test "monitor v.set gdb_output" "valgrind output will go to gdb.*"
95 while {$loop && $continue_count < 100} {
96 set test "continue #$continue_count"
97 gdb_test_multiple "continue" "" {
98 -re "Invalid free\\(\\).*: main .*\r\n$gdb_prompt $" {
102 -re "Remote connection closed.*\r\n$gdb_prompt $" {
103 fail "$test (remote connection closed)"
106 -re "The program is not being run\\.\r\n$gdb_prompt $" {
107 fail "$test (valgrind vgdb has terminated)"
110 -re "\r\n$gdb_prompt $" {
111 pass "$test (false warning)"
114 set continue_count [expr $continue_count + 1]
117 set test "p gdb_test_infcall ()"
118 gdb_test_multiple $test $test {
119 -re "unhandled instruction bytes.*\r\n$gdb_prompt $" {
122 -re "Continuing \\.\\.\\..*\r\n\\\$1 = 2\r\n$gdb_prompt $" {
127 # Only if valgrind got stuck.
128 remote_exec host "kill -9 ${valgrind_pid}"