1 # Copyright 2014-2019 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 # This test checks that inserting a dprintf and detaching does not crash
19 # Related bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17012
21 load_lib gdbserver-support.exp
23 # The test relies on "detach/attach".
24 if { [use_gdb_stub] } then {
29 set escapedbinfile [string_to_regexp ${binfile}]
31 if [prepare_for_testing "failed to prepare for dprintf-detach" \
32 ${testfile} ${srcfile} {debug}] {
36 proc dprintf_detach_test { breakpoint_always_inserted dprintf_style disconnected_dprintf } {
37 set test_prefix "bai=${breakpoint_always_inserted} ds=${dprintf_style} dd=${disconnected_dprintf}"
38 global binfile decimal gdb_prompt escapedbinfile
40 with_test_prefix "$test_prefix" {
41 # Start with a clean gdb
42 clean_restart ${binfile}
44 gdb_test_no_output "set breakpoint always-inserted ${breakpoint_always_inserted}"
45 gdb_test_no_output "set dprintf-style ${dprintf_style}"
46 gdb_test_no_output "set disconnected-dprintf ${disconnected_dprintf}"
49 fail "can't run to main"
53 # Get PID of test program.
55 set test "get inferior process ID"
56 gdb_test_multiple "call (int) getpid ()" $test {
57 -re ".* = ($decimal).*$gdb_prompt $" {
58 set inferior_pid $expect_out(1,string)
63 if {$inferior_pid == -1} {
67 # Add a dprintf and detach.
68 gdb_test "dprintf function, \"hello\"" "Dprintf .*" "dprintf insertion"
69 gdb_test "detach" "Detaching from program: .*$escapedbinfile, .*" "detach program"
73 # Check that the process still exists by attaching a new gdb to it.
74 clean_restart ${binfile}
75 set test "re-attach to inferior"
76 set is_gdbserver [target_is_gdbserver]
78 if { $is_gdbserver == 1 } {
79 setup_kfail "*-*-*" "server/17302"
81 # Give some time for the ex-inferior to run and hopefully not crash.
85 gdb_test "attach $inferior_pid" "Attaching to program: $escapedbinfile, process $inferior_pid.*Reading symbols from.*" "$test"
89 foreach breakpoint_always_inserted { "on" "off" } {
90 foreach dprintf_style { "gdb" "call" "agent" } {
91 foreach disconnected_dprintf { "on" "off" } {
92 dprintf_detach_test $breakpoint_always_inserted $dprintf_style $disconnected_dprintf