OSDN Git Service

gdb/
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.threads / gcore-thread.exp
1 # Copyright 2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # This file was written by Michael Snyder (msnyder@redhat.com)
18 # This is a test for the gdb command "generate-core-file".
19
20 if $tracelevel then {
21         strace $tracelevel
22 }
23
24 # Single-threaded test case
25 set testfile "gcore-thread"
26 set srcfile  pthreads.c
27 set binfile  ${objdir}/${subdir}/${testfile}
28 set corefile ${objdir}/${subdir}/${testfile}.test
29 set core0file ${objdir}/${subdir}/${testfile}0.test
30
31 if [istarget "*-*-linux"] then {
32     set target_cflags "-D_MIT_POSIX_THREADS"
33 } else {
34     set target_cflags ""
35 }
36
37 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
38     return -1
39 }
40
41 # Now we can proceed with the real testing.
42
43 # Start with a fresh gdb.
44
45 clean_restart ${testfile}
46
47 # regexp for "horizontal" text (i.e. doesn't include newline or
48 # carriage return)
49 set horiz "\[^\n\r\]*"
50
51 # regexp for newline
52 set nl "\[\r\n\]+"
53
54 set timeout 30
55
56 gdb_test_multiple "help gcore" "help gcore" {
57     -re "Undefined command: .gcore.*$gdb_prompt $" {
58         # gcore command not supported -- nothing to test here.
59         unsupported "gdb does not support gcore on this target"
60         return -1;
61     }
62     -re "Save a core file .*$gdb_prompt $" {
63         pass "help gcore"
64     }
65 }
66
67 if { ! [ runto_main ] } then {
68     untested gcore-thread.exp
69     return -1
70 }
71
72 gdb_test_multiple "info threads" "threads are supported" {
73     -re ".* main .*$gdb_prompt $" {
74         # OK, threads are supported.
75     }
76     -re "${nl}$gdb_prompt $" {
77         unsupported "gdb does not support threads on this target"
78         return -1;
79     }
80 }
81
82 # Make sure thread 1 is running
83 delete_breakpoints
84 gdb_breakpoint "thread1"
85 gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
86
87 # Make sure thread 2 is running
88 delete_breakpoints
89 gdb_breakpoint "thread2"
90 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
91
92 set escapedfilename [string_to_regexp $corefile]
93 # Drop corefile
94 gdb_test_multiple "gcore $corefile" "save a corefile" \
95 {
96   -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
97     pass "save a corefile"
98     global core_supported
99     set core_supported 1
100   }
101   -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
102     unsupported "save a corefile"
103     global core_supported
104     set core_supported 0
105   }
106 }
107
108 global core_supported
109 if {!$core_supported} {
110   return -1
111 }
112
113
114 # Test the uninitialized thread list.
115 # Provide the case of glibc td_thr_get_info handling of:
116 # /* Special case for the main thread before initialization.  */
117
118 foreach symbol {__stack_user stack_used} {
119     set test "clear ${symbol}.next"
120     gdb_test_multiple "p *(void **) &${symbol} = 0" $test {
121         -re " = \\(void \\*\\) 0x0\r\n$gdb_prompt $" {
122             pass $test
123         }
124         -re "No symbol \"${symbol}\" in current context\\.\r\n$gdb_prompt $" {
125             xfail $test
126             # Do not do the verification.
127             set core0file ""
128         }
129     }
130 }
131
132 if {"$core0file" != ""} {
133     gdb_test "gcore $core0file" "Saved corefile .*" "save a zeroed-threads corefile"
134 }
135
136
137 # Now restart gdb and load the corefile.
138 clean_restart ${testfile}
139
140 proc load_core { corefile } {
141     global gdb_prompt
142
143     gdb_test_multiple "core $corefile" \
144         "re-load generated corefile" {
145             -re " is not a core dump:.*\r\n$gdb_prompt $" {
146                 fail "re-load generated corefile (bad file format)"
147                 # No use proceeding from here.
148                 return 0;
149             }
150             -re ": No such file or directory.*\r\n$gdb_prompt $" {
151                 fail "re-load generated corefile (file not found)"
152                 # No use proceeding from here.
153                 return 0;
154             }
155             -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
156                 fail "re-load generated corefile (incomplete note section)"
157             }
158             -re "Core was generated by .*\r\n$gdb_prompt $" {
159                 pass "re-load generated corefile"
160             }
161         }
162     return 1
163 }
164
165 if ![load_core $corefile] {
166     return
167 }
168
169 # FIXME: now what can we test about the thread state?
170 # We do not know for certain that there should be at least 
171 # three threads, because who knows what kind of many-to-one
172 # mapping various OS's may do?  Let's assume that there must
173 # be at least two threads:
174
175 gdb_test "info threads" ".*${nl}  2 ${horiz}${nl}\\* 1 .*" \
176         "corefile contains at least two threads"
177
178 # One thread in the corefile should be in the "thread2" function.
179
180 gdb_test "info threads" ".* thread2 .*" \
181         "a corefile thread is executing thread2"
182
183 # The thread2 thread should be marked as the current thread.
184
185 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
186         "thread2 is current thread in corefile"
187
188
189 # Test the uninitialized thread list.
190
191 if {"$core0file" != "" && [load_core $core0file]} {
192
193     gdb_test "info threads" "Cannot find new threads: .*" "zeroed-threads cannot be listed"
194 }