]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/thread_events.exp
Inform about new thread in a single place.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / thread_events.exp
1 # Copyright (C) 2007 Free Software Foundation, Inc.
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 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
18
19 # This file was written by Chris Demetriou (cgd@google.com).
20 # It tests printing of thread event (start, exit) information, and
21 # disabling of those messages.
22 #
23 # Note: the format of thread event messages (and also whether or not
24 # messages are printed and can be disabled) is dependent on the target
25 # thread support code.
26
27 # This test has only been verified with Linux targets, and would need
28 # to be generalized to support other targets
29 if ![istarget *-*-linux*] then {
30 return
31 }
32
33 # When using gdbserver, even on Linux, we don't get notifications
34 # about new threads. This is expected, so don't test for that.
35 if [is_remote target] then {
36 return
37 }
38
39 if $tracelevel then {
40 strace $tracelevel
41 }
42
43 set prms_id 0
44 set bug_id 0
45
46 set testfile "thread_events"
47 set srcfile ${testfile}.c
48 set binfile ${objdir}/${subdir}/${testfile}
49
50 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
51 return -1
52 }
53
54 proc gdb_test_thread_start {messages_enabled command pattern message} {
55 global gdb_prompt
56
57 if { $messages_enabled } {
58 set events_expected 1
59 } else {
60 set events_expected 0
61 }
62 set events_seen 0
63
64 return [gdb_test_multiple $command $message {
65 -re "\\\[New Thread \[^\]\]*\\\]\r\n" {
66 incr events_seen;
67 exp_continue;
68 }
69 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
70 if { $events_seen != $events_expected } {
71 fail "$message (saw $events_seen, expected $events_expected)"
72 } else {
73 pass "$message"
74 }
75 }
76 }]
77 }
78
79 proc gdb_test_thread_exit {messages_enabled command pattern message} {
80 global gdb_prompt
81
82 if { $messages_enabled } {
83 set events_expected 1
84 } else {
85 set events_expected 0
86 }
87 set events_seen 0
88
89 return [gdb_test_multiple $command $message {
90 -re "\\\[Thread \[^\]\]* exited\\\]\r\n" {
91 incr events_seen
92 exp_continue;
93 }
94 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
95 if { $events_seen != $events_expected } {
96 fail "$message (saw $events_seen, expected $events_expected)"
97 } else {
98 pass "$message"
99 }
100 }
101 }]
102 }
103
104 proc test_thread_messages {enabled} {
105 global srcdir subdir binfile srcfile
106
107 if { $enabled } {
108 set enabled_string "with messages enabled"
109 } else {
110 set enabled_string "with messages disabled"
111 }
112
113 gdb_start
114 gdb_reinitialize_dir $srcdir/$subdir
115 gdb_load ${binfile}
116
117 if { $enabled } {
118 gdb_test "set print thread-events on"
119 } else {
120 gdb_test "set print thread-events off"
121 }
122
123 # The initial thread may log a 'New Thread' message, but we don't
124 # check for it.
125 if ![runto_main] then {
126 fail "Can't run to main $enabled_string"
127 return 1
128 }
129
130 gdb_test "break threadfunc" \
131 "Breakpoint.*at.* file .*$srcfile, line.*" \
132 "breakpoint at threadfunc $enabled_string"
133 gdb_test "break after_join_func" \
134 "Breakpoint.*at.* file .*$srcfile, line.*" \
135 "breakpoint at after_join_func $enabled_string"
136
137 # continue to threadfunc breakpoint. A thread will start.
138 # Expect to see a thread start message, if messages are enabled.
139 gdb_test_thread_start $enabled "continue" \
140 ".*Breakpoint .*,.*threadfunc.*at.*$srcfile:.*" \
141 "continue to threadfunc $enabled_string"
142
143 # continue to after_join_func breakpoint. A thread will exit.
144 # Expect to see a thread exit message, if messages are enabled.
145 gdb_test_thread_exit $enabled "continue" \
146 ".*Breakpoint .*,.*after_join_func.*at.*$srcfile:.*" \
147 "continue to after_join_func $enabled_string"
148
149 delete_breakpoints
150
151 gdb_exit
152 }
153
154 test_thread_messages 0
155 test_thread_messages 1