1 # Copyright (C) 2007, 2009, 2010, 2011 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 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.
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.
24 # This test has only been verified with Linux targets, and would need
25 # to be generalized to support other targets
26 if ![istarget *-*-linux*] then {
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.
32 if [is_remote target] then {
41 set testfile "thread_events"
42 set srcfile ${testfile}.c
43 set binfile ${objdir}/${subdir}/${testfile}
45 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
49 proc gdb_test_thread_start {messages_enabled command pattern message} {
52 if { $messages_enabled } {
59 return [gdb_test_multiple $command $message {
60 -re "\\\[New Thread \[^\]\]*\\\]\r\n" {
64 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
65 if { $events_seen != $events_expected } {
66 fail "$message (saw $events_seen, expected $events_expected)"
74 proc gdb_test_thread_exit {messages_enabled command pattern message} {
77 if { $messages_enabled } {
84 return [gdb_test_multiple $command $message {
85 -re "\\\[Thread \[^\]\]* exited\\\]\r\n" {
89 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
90 if { $events_seen != $events_expected } {
91 fail "$message (saw $events_seen, expected $events_expected)"
99 proc test_thread_messages {enabled} {
100 global srcdir subdir binfile srcfile
103 set enabled_string "with messages enabled"
105 set enabled_string "with messages disabled"
109 gdb_reinitialize_dir $srcdir/$subdir
113 gdb_test "set print thread-events on"
115 gdb_test "set print thread-events off"
118 # The initial thread may log a 'New Thread' message, but we don't
120 if ![runto_main] then {
121 fail "Can't run to main $enabled_string"
125 gdb_test "break threadfunc" \
126 "Breakpoint.*at.* file .*$srcfile, line.*" \
127 "breakpoint at threadfunc $enabled_string"
128 gdb_test "break after_join_func" \
129 "Breakpoint.*at.* file .*$srcfile, line.*" \
130 "breakpoint at after_join_func $enabled_string"
132 # continue to threadfunc breakpoint. A thread will start.
133 # Expect to see a thread start message, if messages are enabled.
134 gdb_test_thread_start $enabled "continue" \
135 ".*Breakpoint .*,.*threadfunc.*at.*$srcfile:.*" \
136 "continue to threadfunc $enabled_string"
138 # continue to after_join_func breakpoint. A thread will exit.
139 # Expect to see a thread exit message, if messages are enabled.
140 gdb_test_thread_exit $enabled "continue" \
141 ".*Breakpoint .*,.*after_join_func.*at.*$srcfile:.*" \
142 "continue to after_join_func $enabled_string"
149 test_thread_messages 0
150 test_thread_messages 1