OSDN Git Service

2b69eb8449d506f9b9eac0509f70cc8be5c3515a
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.threads / thread_events.exp
1 # Copyright (C) 2007, 2009-2012 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 # 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
26 if ![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.
32 if [is_remote target] then {
33     return
34 }
35
36
37 set testfile "thread_events"
38 set srcfile ${testfile}.c
39 set binfile ${objdir}/${subdir}/${testfile}
40
41 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
42     return -1
43 }
44
45 proc gdb_test_thread_start {messages_enabled command pattern message} {
46   global gdb_prompt
47
48   if { $messages_enabled } {
49     set events_expected 1
50   } else {
51     set events_expected 0
52   }
53   set events_seen 0
54
55   return [gdb_test_multiple $command $message {
56     -re "\\\[New Thread \[^\]\]*\\\]\r\n" {
57       incr events_seen;
58       exp_continue;
59     }
60     -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
61       if { $events_seen != $events_expected } {
62         fail "$message (saw $events_seen, expected $events_expected)"
63       } else {
64         pass "$message"
65       }
66     }
67   }]
68 }
69
70 proc gdb_test_thread_exit {messages_enabled command pattern message} {
71   global gdb_prompt
72
73   if { $messages_enabled } {
74     set events_expected 1
75   } else {
76     set events_expected 0
77   }
78   set events_seen 0
79
80   return [gdb_test_multiple $command $message {
81     -re "\\\[Thread \[^\]\]* exited\\\]\r\n" {
82       incr events_seen
83       exp_continue;
84     }
85     -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
86       if { $events_seen != $events_expected } {
87         fail "$message (saw $events_seen, expected $events_expected)"
88       } else {
89         pass "$message"
90       }
91     }
92   }]
93 }
94
95 proc test_thread_messages {enabled} {
96   global srcdir subdir binfile srcfile
97
98   if { $enabled } {
99     set enabled_string "with messages enabled"
100   } else {
101     set enabled_string "with messages disabled"
102   }
103
104   gdb_start
105   gdb_reinitialize_dir $srcdir/$subdir
106   gdb_load ${binfile}
107
108   if { $enabled } {
109      gdb_test "set print thread-events on"
110   } else {
111      gdb_test "set print thread-events off"
112   }
113
114   # The initial thread may log a 'New Thread' message, but we don't
115   # check for it.
116   if ![runto_main] then {
117      fail "Can't run to main $enabled_string"
118      return 1
119   }
120
121   gdb_test "break threadfunc" \
122       "Breakpoint.*at.* file .*$srcfile, line.*" \
123       "breakpoint at threadfunc $enabled_string"
124   gdb_test "break after_join_func" \
125       "Breakpoint.*at.* file .*$srcfile, line.*" \
126       "breakpoint at after_join_func $enabled_string"
127
128   # continue to threadfunc breakpoint.  A thread will start.
129   # Expect to see a thread start message, if messages are enabled.
130   gdb_test_thread_start $enabled "continue" \
131        ".*Breakpoint .*,.*threadfunc.*at.*$srcfile:.*" \
132        "continue to threadfunc $enabled_string"
133
134   # continue to after_join_func breakpoint.  A thread will exit.
135   # Expect to see a thread exit message, if messages are enabled.
136   gdb_test_thread_exit $enabled "continue" \
137        ".*Breakpoint .*,.*after_join_func.*at.*$srcfile:.*" \
138        "continue to after_join_func $enabled_string"
139
140   delete_breakpoints
141
142   gdb_exit
143 }
144
145 test_thread_messages 0
146 test_thread_messages 1