summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.threads/process-dies-while-handling-bp.exp
blob: a14d2a2b600e7b5de8e0665413912a3be1d648ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Copyright (C) 2015-2019 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This test spawns a few threads that constantly trip on a breakpoint
# that does not cause a user-visible stop.  While one of those
# breakpoints is being handled, the main thread exits the whole
# process.  The result is that the current thread for which GDB is
# handling the event disappears too and any attempt to access
# register/memory now errors out.  GDB and GDBserver should be able to
# handle this scenario gracefully.
#
# See https://sourceware.org/bugzilla/show_bug.cgi?id=18749

standard_testfile

set linenum [gdb_get_line_number "set break here"]

if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
    return -1
}

# The test proper.  If COND_BP_TARGET is true, then test with
# conditional breakpoints evaluated on the target side, if possible.

proc do_test { non_stop cond_bp_target } {
    global GDBFLAGS
    global gdb_prompt
    global binfile
    global linenum

    set saved_gdbflags $GDBFLAGS
    set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop $non_stop\""]
    clean_restart $binfile
    set GDBFLAGS $saved_gdbflags

    if ![runto_main] then {
	fail "can't run to main"
	return 0
    }

    # Whether it's known that the test fails.
    set should_kfail 0

    if {![gdb_is_target_remote]} {
	set should_kfail 1
    } else {
	if {!$cond_bp_target} {
	    # Leaving breakpoint evaluation to GDB exposes failures
	    # similar to native debugging.
	    gdb_test_no_output "set remote conditional-breakpoints-packet off"
	    set should_kfail 1
	} else {
	    set test "show remote conditional-breakpoints-packet"
	    gdb_test_multiple $test $test {
		-re "currently enabled\.\r\n$gdb_prompt $" {
		    pass $test
		}
		-re "currently disabled\.\r\n$gdb_prompt $" {
		    unsupported "no support for target-side conditional breakpoints"
		    return
		}
	    }
	    set should_kfail 1
	}
    }

    gdb_test "break $linenum if zero == 1" \
	"Breakpoint .*" \
	"set breakpoint that evals false"

    set test "continue &"
    gdb_test_multiple $test $test {
	-re "$gdb_prompt " {
	    pass $test
	}
    }

    set ok 0

    # Setup the kfail upfront in order to also catch GDB internal
    # errors.
    if {$should_kfail} {
	setup_kfail "gdb/18749" "*-*-*"
    }

    set test "inferior 1 exited"
    gdb_test_multiple "" $test {
	-re "Inferior 1 \(\[^\r\n\]+\) exited normally" {
	    set ok 1

	    # Clear the kfail to avoid a PASS -> KPASS dance across
	    # runs.
	    clear_kfail "*-*-linux*"

	    pass $test
	}
	-re "$gdb_prompt " {
	    # Several errors end up at the top level, and printing the
	    # prompt.
	    fail "$test (prompt)"
	}
	-re "Cannot access memory" {
	    fail "$test (memory error)"
	}
	eof {
	    fail "$test (GDB died)"
	}
    }

    if {!$ok} {
	# No use testing further.
	return
    }

    gdb_test "info threads" "No threads\." \
	"no threads left"
}

foreach_with_prefix non_stop {"on" "off"} {
    foreach_with_prefix cond_bp_target {1 0} {
	do_test $non_stop $cond_bp_target
    }
}