]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2009-2024 Free Software Foundation, Inc. |
68b9ac18 TV |
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 | # Generic subroutines for handling valgrind vgdb server. | |
17 | ||
18 | # | |
19 | # Start a vgdb server, and connect gdb to it. Return 0 on success, and -1 on | |
20 | # error. | |
21 | # | |
33176ea7 | 22 | proc vgdb_start { {active_at_startup 1} } { |
68b9ac18 TV |
23 | global binfile use_gdb_stub board testfile |
24 | global valgrind_spawn_id gdb_spawn_id | |
33176ea7 | 25 | global decimal |
68b9ac18 TV |
26 | |
27 | set test "spawn valgrind" | |
33176ea7 TV |
28 | set cmd_list [list] |
29 | lappend cmd_list "valgrind" | |
30 | if { $active_at_startup } { | |
31 | lappend cmd_list "--vgdb-error=0" | |
32 | } | |
33 | lappend cmd_list $binfile | |
34 | set cmd [join $cmd_list] | |
68b9ac18 TV |
35 | set res [remote_spawn host $cmd] |
36 | if { $res < 0 || $res == "" } { | |
37 | verbose -log "Spawning $cmd failed." | |
38 | unsupported $test | |
39 | return -1 | |
40 | } | |
41 | pass $test | |
42 | # Declare GDB now as running. | |
43 | set gdb_spawn_id $res | |
44 | ||
45 | # GDB started by vgdb stops already after the startup is executed, like with | |
46 | # non-extended gdbserver. It is also not correct to run/attach the inferior. | |
47 | set use_gdb_stub 1 | |
48 | ||
49 | set test "valgrind started" | |
50 | # The trailing '.' differs for different memcheck versions. | |
51 | gdb_test_multiple "" $test { | |
33176ea7 TV |
52 | -re "==($decimal)== Memcheck, a memory error detector\\.?\r\n" { |
53 | set vgdbpid $expect_out(1,string) | |
68b9ac18 TV |
54 | pass $test |
55 | } | |
56 | -re "valgrind: failed to start tool 'memcheck' for platform '.*': No such file or directory" { | |
57 | unsupported $test | |
58 | return -1 | |
59 | } | |
60 | -re "valgrind: wrong ELF executable class" { | |
61 | unsupported $test | |
62 | return -1 | |
63 | } | |
64 | -re "command not found" { | |
65 | # The spawn succeeded, but then valgrind was not found - e.g. if | |
66 | # we spawned SSH to a remote system. | |
67 | unsupported $test | |
68 | return -1 | |
69 | } | |
70 | -re "valgrind: Bad option.*--vgdb-error=0" { | |
71 | # valgrind is not >= 3.7.0. | |
72 | unsupported $test | |
73 | return -1 | |
74 | } | |
75 | } | |
76 | ||
68b9ac18 TV |
77 | # Do not kill valgrind. |
78 | set valgrind_spawn_id [board_info host fileid] | |
79 | unset gdb_spawn_id | |
80 | set board [host_info name] | |
81 | unset_board_info fileid | |
82 | ||
83 | clean_restart $testfile | |
84 | ||
3f334074 | 85 | set_remotetimeout 4 |
6d5702a5 | 86 | |
68b9ac18 TV |
87 | # Make sure we're disconnected, in case we're testing with the |
88 | # native-extended-gdbserver board, where gdb_start/gdb_load spawn | |
89 | # gdbserver and connect to it. | |
90 | gdb_test "disconnect" ".*" | |
91 | ||
6d5702a5 CL |
92 | set vgdbcmd "target remote | vgdb --wait=2 --max-invoke-ms=2500 --pid=$vgdbpid" |
93 | ||
33176ea7 TV |
94 | if { $active_at_startup } { |
95 | gdb_test "$vgdbcmd" " in \\.?_start .*" "target remote for vgdb" | |
96 | } else { | |
97 | # Let $binfile run a bit before attaching. This is a bit of a hack, | |
98 | # in that it lets test-case valgrind-infcall-2.exp run to the point of | |
99 | # nanosleep, which seems to be required to trigger the error condition. | |
100 | # So, without this, we hit | |
101 | # "UNSUPPORTED: gdb.base/valgrind-infcall-2.exp: do printf". | |
102 | exec sleep 1 | |
68b9ac18 | 103 | |
33176ea7 TV |
104 | # Connect to vgdb. Don't expect to be anywhere in particular. |
105 | gdb_test "$vgdbcmd" "" "target remote for vgdb" | |
106 | } | |
68b9ac18 | 107 | |
33176ea7 | 108 | gdb_test "monitor v.set gdb_output" "valgrind output will go to gdb.*" |
68b9ac18 TV |
109 | return 0 |
110 | } | |
111 | ||
112 | # | |
113 | # Stop vgdb server. | |
114 | # | |
115 | proc vgdb_stop { } { | |
116 | global valgrind_spawn_id | |
117 | ||
118 | # Only if valgrind got stuck. | |
119 | kill_wait_spawned_process $valgrind_spawn_id | |
120 | } |