1 # Copyright 2009-2020 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 # Generic subroutines for handling valgrind vgdb server.
19 # Start a vgdb server, and connect gdb to it. Return 0 on success, and -1 on
23 global binfile use_gdb_stub board testfile
24 global valgrind_spawn_id gdb_spawn_id
26 set test "spawn valgrind"
27 set cmd "valgrind --vgdb-error=0 $binfile"
28 set res [remote_spawn host $cmd]
29 if { $res < 0 || $res == "" } {
30 verbose -log "Spawning $cmd failed."
35 # Declare GDB now as running.
38 # GDB started by vgdb stops already after the startup is executed, like with
39 # non-extended gdbserver. It is also not correct to run/attach the inferior.
42 set test "valgrind started"
43 # The trailing '.' differs for different memcheck versions.
44 gdb_test_multiple "" $test {
45 -re "Memcheck, a memory error detector\\.?\r\n" {
48 -re "valgrind: failed to start tool 'memcheck' for platform '.*': No such file or directory" {
52 -re "valgrind: wrong ELF executable class" {
56 -re "command not found" {
57 # The spawn succeeded, but then valgrind was not found - e.g. if
58 # we spawned SSH to a remote system.
62 -re "valgrind: Bad option.*--vgdb-error=0" {
63 # valgrind is not >= 3.7.0.
69 set test "vgdb prompt"
70 gdb_test_multiple "" $test {
71 -re " (target remote | \[^\r\n\]*/vgdb \[^\r\n\]*)\r\n" {
72 set vgdbcmd $expect_out(1,string)
77 # Do not kill valgrind.
78 set valgrind_spawn_id [board_info host fileid]
80 set board [host_info name]
81 unset_board_info fileid
83 clean_restart $testfile
85 # Make sure we're disconnected, in case we're testing with the
86 # native-extended-gdbserver board, where gdb_start/gdb_load spawn
87 # gdbserver and connect to it.
88 gdb_test "disconnect" ".*"
90 gdb_test "$vgdbcmd" " in \\.?_start .*" "target remote for vgdb"
92 gdb_test "monitor v.set gdb_output" "valgrind output will go to gdb.*"
101 global valgrind_spawn_id
103 # Only if valgrind got stuck.
104 kill_wait_spawned_process $valgrind_spawn_id