OSDN Git Service

Copyright updates for 2007.
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.threads / thread-specific.exp
1 # Copyright 2004, 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Daniel Jacobowitz <drow@mvista.com>.
21 # It tests that the correct breakpoint is reported when we hit a
22 # thread-specific breakpoint inserted for several threads.
23
24 if $tracelevel then {
25         strace $tracelevel
26 }
27
28 set prms_id 0
29 set bug_id 0
30
31 set testfile "thread-specific"
32 set srcfile ${testfile}.c
33 set binfile ${objdir}/${subdir}/${testfile}
34
35 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
36     return -1
37 }
38
39 # Return a list of the valid thread IDs, with the initial thread first.
40 proc get_thread_list { } {
41   global gdb_prompt
42   global expect_out
43
44   set thr_list ""
45
46   gdb_test_multiple "info threads" "get threads list" {
47     -re "info threads\r\n" {
48       exp_continue
49     }
50     -re "^\\*  *(\[0-9\]*) Thread \[^\n\]*main\[^\n\]*\n" {
51       set thr_list "$expect_out(1,string) $thr_list"
52       exp_continue
53     }
54     -re "^  *(\[0-9\]*) Thread \[^\n\]*\n" {
55       lappend thr_list $expect_out(1,string)
56       exp_continue
57     }
58     -re ".*$gdb_prompt $" {
59       if { [llength $thr_list] != 0 } {
60         pass "get threads list"
61       } else {
62         fail "get threads list (no threads)"
63       }
64     }
65   }
66
67   return $thr_list
68 }
69
70 # Start with a fresh gdb.
71
72 gdb_exit
73 gdb_start
74 gdb_reinitialize_dir $srcdir/$subdir
75
76 gdb_load ${binfile}
77
78 gdb_test "set print sevenbit-strings" ""
79 gdb_test "set width 0" ""
80
81 runto_main
82
83 gdb_breakpoint [gdb_get_line_number "thread-specific.exp: last thread start"]
84 gdb_continue_to_breakpoint "all threads started"
85
86 set line [gdb_get_line_number "thread-specific.exp: thread loop"]
87 set threads [get_thread_list]
88
89 if {[llength $threads] == 0} {
90   # We have already issued a FAIL above.
91   return 1
92 }
93
94 gdb_test_multiple "break $line thread [lindex $threads 0]" \
95   "breakpoint $line main thread" {
96     -re "Breakpoint (\[0-9\]*) at.* file .*$srcfile, line.*$gdb_prompt $" {
97       set main_breakpoint $expect_out(1,string)
98       pass "breakpoint $line main thread"
99     }
100 }
101
102 foreach thread [lrange $threads 1 end] {
103   gdb_breakpoint "$line thread $thread"
104 }
105
106 gdb_test_multiple "continue" "continue to thread-specific breakpoint" {
107         -re "Breakpoint $main_breakpoint, .* at .*\r\n$gdb_prompt $" {
108             fail "continue to thread-specific breakpoint (wrong breakpoint)"
109         }
110         -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
111             pass "continue to thread-specific breakpoint"
112         }
113 }
114
115 return 0