Commit | Line | Data |
---|---|---|
0b302171 | 1 | # Copyright 2009, 2011-2012 Free Software Foundation, Inc. |
9f2982ff JK |
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 | ||
75d9f9ff JK |
16 | if [is_remote target] { |
17 | # The test always runs locally. | |
18 | return 0 | |
19 | } | |
20 | ||
9f2982ff JK |
21 | set test valgrind-db-attach |
22 | set srcfile $test.c | |
23 | set executable $test | |
24 | set binfile ${objdir}/${subdir}/${executable} | |
25 | if {[build_executable $test.exp $executable $srcfile {debug}] == -1} { | |
26 | return -1 | |
27 | } | |
28 | ||
29 | gdb_exit | |
30 | ||
31 | # remote_spawn breaks the command on each whitespace despite possible quoting. | |
32 | # Use backslash-escaped whitespace there instead: | |
33 | ||
34 | set db_command "--db-command=$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts] %f %p" | |
35 | regsub -all " " $db_command "\\ " db_command | |
36 | ||
37 | set test "spawn valgrind" | |
38 | set cmd "valgrind --db-attach=yes $db_command $binfile" | |
39 | set res [remote_spawn host $cmd]; | |
40 | if { $res < 0 || $res == "" } { | |
41 | verbose -log "Spawning $cmd failed." | |
67bdab6c | 42 | unsupported $test |
9f2982ff JK |
43 | return -1 |
44 | } | |
45 | pass $test | |
46 | # Declare GDB now as running. | |
47 | set gdb_spawn_id -1 | |
48 | ||
e11ac3a3 JK |
49 | # GDB spawned by `valgrind --db-attach=yes' stops already after the startup is |
50 | # executed, like with non-extended gdbserver. It is also not correct to | |
51 | # run/attach the inferior. | |
52 | set use_gdb_stub 1 | |
53 | ||
9f2982ff JK |
54 | set test "valgrind started" |
55 | # The trailing '.' differs for different memcheck versions. | |
56 | gdb_test_multiple "" $test { | |
57 | -re "Memcheck, a memory error detector\\.?\r\n" { | |
58 | pass $test | |
59 | } | |
60 | -re "valgrind: failed to start tool 'memcheck' for platform '.*': No such file or directory" { | |
67bdab6c DJ |
61 | unsupported $test |
62 | return -1 | |
63 | } | |
5bbad94c UW |
64 | -re "valgrind: wrong ELF executable class" { |
65 | unsupported $test | |
66 | return -1 | |
67 | } | |
67bdab6c DJ |
68 | -re "command not found" { |
69 | # The spawn succeeded, but then valgrind was not found - e.g. if | |
70 | # we spawned SSH to a remote system. | |
71 | unsupported $test | |
9f2982ff JK |
72 | return -1 |
73 | } | |
74 | } | |
75 | ||
76 | set double_free [gdb_get_line_number "double-free"] | |
77 | ||
d3765805 | 78 | set test "attach to debugger" |
9f2982ff | 79 | gdb_test_multiple "" $test { |
f0d1a53e | 80 | -re "Invalid free\\(\\).*: main \\(${srcfile}:$double_free\\)\r\n.*---- Attach to debugger \\? --- \[^\r\n\]* ---- " { |
9f2982ff JK |
81 | send_gdb "y\r" |
82 | } | |
83 | -re "---- Attach to debugger \\? --- \[^\r\n\]* ---- " { | |
84 | send_gdb "n\r" | |
85 | exp_continue | |
86 | } | |
87 | } | |
88 | ||
de7ff789 | 89 | gdb_test "" ".*" "eat first prompt" |
9f2982ff JK |
90 | |
91 | # Initialization from default_gdb_start. | |
27d3a1a2 MS |
92 | gdb_test_no_output "set height 0" |
93 | gdb_test_no_output "set width 0" | |
9f2982ff JK |
94 | |
95 | gdb_test "bt" "in main \\(.*\\) at .*${srcfile}:$double_free" | |
a391a2f6 PA |
96 | |
97 | # Explicitly kill the program so it doesn't dump core when we quit->detach. | |
98 | gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y" |