1 # Copyright 2009, 2011-2012 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 set test valgrind-db-attach
19 set binfile ${objdir}/${subdir}/${executable}
20 if {[build_executable $test.exp $executable $srcfile {debug}] == -1} {
26 # remote_spawn breaks the command on each whitespace despite possible quoting.
27 # Use backslash-escaped whitespace there instead:
29 set db_command "--db-command=$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts] %f %p"
30 regsub -all " " $db_command "\\ " db_command
32 set test "spawn valgrind"
33 set cmd "valgrind --db-attach=yes $db_command $binfile"
34 set res [remote_spawn host $cmd];
35 if { $res < 0 || $res == "" } {
36 verbose -log "Spawning $cmd failed."
41 # Declare GDB now as running.
44 # GDB spawned by `valgrind --db-attach=yes' stops already after the startup is
45 # executed, like with non-extended gdbserver. It is also not correct to
46 # run/attach the inferior.
49 set test "valgrind started"
50 # The trailing '.' differs for different memcheck versions.
51 gdb_test_multiple "" $test {
52 -re "Memcheck, a memory error detector\\.?\r\n" {
55 -re "valgrind: failed to start tool 'memcheck' for platform '.*': No such file or directory" {
59 -re "valgrind: wrong ELF executable class" {
63 -re "command not found" {
64 # The spawn succeeded, but then valgrind was not found - e.g. if
65 # we spawned SSH to a remote system.
71 set double_free [gdb_get_line_number "double-free"]
73 set test "attach to debugger"
74 gdb_test_multiple "" $test {
75 -re "Invalid free\\(\\) / delete / delete\\\[\\\]\r\n.*: main \\(${srcfile}:$double_free\\)\r\n.*---- Attach to debugger \\? --- \[^\r\n\]* ---- " {
78 -re "---- Attach to debugger \\? --- \[^\r\n\]* ---- " {
84 gdb_test "" ".*" "eat first prompt"
86 # Initialization from default_gdb_start.
87 gdb_test_no_output "set height 0"
88 gdb_test_no_output "set width 0"
90 gdb_test "bt" "in main \\(.*\\) at .*${srcfile}:$double_free"
92 # Explicitly kill the program so it doesn't dump core when we quit->detach.
93 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"