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