Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright (C) 2015-2016 Free Software Foundation, Inc. |
83e97ed0 PA |
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 | # This test spawns a few threads that constantly trip on a breakpoint | |
17 | # that does not cause a user-visible stop. While one of those | |
18 | # breakpoints is being handled, the main thread exits the whole | |
19 | # process. The result is that the current thread for which GDB is | |
20 | # handling the event disappears too and any attempt to access | |
21 | # register/memory now errors out. GDB and GDBserver should be able to | |
22 | # handle this scenario gracefully. | |
23 | # | |
24 | # See https://sourceware.org/bugzilla/show_bug.cgi?id=18749 | |
25 | ||
26 | standard_testfile | |
27 | ||
28 | set linenum [gdb_get_line_number "set break here"] | |
29 | ||
30 | if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} { | |
31 | return -1 | |
32 | } | |
33 | ||
34 | # The test proper. If COND_BP_TARGET is true, then test with | |
35 | # conditional breakpoints evaluated on the target side, if possible. | |
36 | ||
37 | proc do_test { non_stop cond_bp_target } { | |
38 | global GDBFLAGS | |
39 | global gdb_prompt | |
40 | global binfile | |
41 | global linenum | |
42 | ||
43 | set saved_gdbflags $GDBFLAGS | |
44 | set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop $non_stop\""] | |
45 | clean_restart $binfile | |
46 | set GDBFLAGS $saved_gdbflags | |
47 | ||
48 | if ![runto_main] then { | |
49 | fail "Can't run to main" | |
50 | return 0 | |
51 | } | |
52 | ||
53 | # Whether it's known that the test fails. | |
54 | set should_kfail 0 | |
55 | ||
56 | if {![gdb_is_target_remote]} { | |
57 | set should_kfail 1 | |
58 | } else { | |
59 | if {!$cond_bp_target} { | |
60 | # Leaving breakpoint evaluation to GDB exposes failures | |
61 | # similar to native debugging. | |
62 | gdb_test_no_output "set remote conditional-breakpoints-packet off" | |
63 | set should_kfail 1 | |
64 | } else { | |
65 | set test "show remote conditional-breakpoints-packet" | |
66 | gdb_test_multiple $test $test { | |
67 | -re "currently enabled\.\r\n$gdb_prompt $" { | |
68 | pass $test | |
69 | } | |
70 | -re "currently disabled\.\r\n$gdb_prompt $" { | |
71 | unsupported "no support for target-side conditional breakpoints" | |
72 | return | |
73 | } | |
74 | } | |
75 | set should_kfail 1 | |
76 | } | |
77 | } | |
78 | ||
79 | gdb_test "break $linenum if zero == 1" \ | |
80 | "Breakpoint .*" \ | |
81 | "set breakpoint that evals false" | |
82 | ||
83 | set test "continue &" | |
84 | gdb_test_multiple $test $test { | |
85 | -re "$gdb_prompt " { | |
86 | pass $test | |
87 | } | |
88 | } | |
89 | ||
90 | set ok 0 | |
91 | ||
92 | # Setup the kfail upfront in order to also catch GDB internal | |
93 | # errors. | |
94 | if {$should_kfail} { | |
95 | setup_kfail "gdb/18749" "*-*-*" | |
96 | } | |
97 | ||
98 | set test "inferior 1 exited" | |
99 | gdb_test_multiple "" $test { | |
100 | -re "Inferior 1 \(\[^\r\n\]+\) exited normally" { | |
101 | set ok 1 | |
102 | ||
103 | # Clear the kfail to avoid a PASS -> KPASS dance across | |
104 | # runs. | |
105 | clear_kfail "*-*-linux*" | |
106 | ||
107 | pass $test | |
108 | } | |
109 | -re "$gdb_prompt " { | |
110 | # Several errors end up at the top level, and printing the | |
111 | # prompt. | |
112 | fail "$test (prompt)" | |
113 | } | |
114 | -re "Cannot access memory" { | |
115 | fail "$test (memory error)" | |
116 | } | |
117 | eof { | |
118 | fail "$test (GDB died)" | |
119 | } | |
120 | } | |
121 | ||
122 | if {!$ok} { | |
123 | # No use testing further. | |
124 | return | |
125 | } | |
126 | ||
127 | gdb_test "info threads" "No threads\." \ | |
128 | "no threads left" | |
129 | } | |
130 | ||
131 | # Wrapper for foreach that calls with_test_prefix on each iteration, | |
132 | # including the iterator's current value in the prefix. | |
133 | ||
134 | proc foreach_with_prefix {var list body} { | |
135 | upvar 1 $var myvar | |
136 | foreach myvar $list { | |
137 | with_test_prefix "$var=$myvar" { | |
138 | uplevel 1 $body | |
139 | } | |
140 | } | |
141 | } | |
142 | ||
143 | foreach_with_prefix non_stop {"on" "off"} { | |
144 | foreach_with_prefix cond_bp_target {1 0} { | |
145 | do_test $non_stop $cond_bp_target | |
146 | } | |
147 | } |