OSDN Git Service

Copyright year update in most files of the GDB Project.
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.threads / gcore-thread.exp
1 # Copyright 2002-2004, 2007-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 Michael Snyder (msnyder@redhat.com)
17 # This is a test for the gdb command "generate-core-file".
18
19 if $tracelevel then {
20         strace $tracelevel
21 }
22
23 # Single-threaded test case
24 set testfile "gcore-thread"
25 set srcfile  pthreads.c
26 set objfile  ${objdir}/${subdir}/${testfile}.o
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 # Attempt to prevent -Wl,-z,relro which happens by default at least on
38 # Kubuntu-10.10.  Due to PR corefiles/11804 will then GDB be unable to find
39 # libpthread, therefore libthread_db will not fail as expected
40 # on the test `zeroed-threads cannot be listed'.
41
42 set opts [list debug "incdir=${objdir}"]
43 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${objfile}" object $opts] != ""
44     || ([gdb_compile_pthreads "${objfile}" "${binfile}" executable [concat $opts {additional_flags=-Wl,-z,norelro}] ] != ""
45         && [gdb_compile_pthreads "${objfile}" "${binfile}" executable $opts] != "") } {
46     return -1
47 }
48
49 # Now we can proceed with the real testing.
50
51 # Start with a fresh gdb.
52
53 clean_restart ${testfile}
54
55 # regexp for "horizontal" text (i.e. doesn't include newline or
56 # carriage return)
57 set horiz "\[^\n\r\]*"
58
59 # regexp for newline
60 set nl "\[\r\n\]+"
61
62 set timeout 30
63
64 gdb_test_multiple "help gcore" "help gcore" {
65     -re "Undefined command: .gcore.*$gdb_prompt $" {
66         # gcore command not supported -- nothing to test here.
67         unsupported "gdb does not support gcore on this target"
68         return -1;
69     }
70     -re "Save a core file .*$gdb_prompt $" {
71         pass "help gcore"
72     }
73 }
74
75 if { ! [ runto_main ] } then {
76     untested gcore-thread.exp
77     return -1
78 }
79
80 gdb_test_multiple "info threads" "threads are supported" {
81     -re ".* main .*$gdb_prompt $" {
82         # OK, threads are supported.
83     }
84     -re "${nl}$gdb_prompt $" {
85         unsupported "gdb does not support threads on this target"
86         return -1;
87     }
88 }
89
90 # Make sure thread 1 is running
91 delete_breakpoints
92 gdb_breakpoint "thread1"
93 gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
94
95 # Make sure thread 2 is running
96 delete_breakpoints
97 gdb_breakpoint "thread2"
98 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
99
100 set escapedfilename [string_to_regexp $corefile]
101 # Drop corefile
102 set core_supported 0
103 gdb_test_multiple "gcore $corefile" "save a corefile" \
104 {
105   -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
106     pass "save a corefile"
107     global core_supported
108     set core_supported 1
109   }
110   -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
111     unsupported "save a corefile"
112   }
113 }
114
115 if {!$core_supported} {
116   return -1
117 }
118
119
120 # Test the uninitialized thread list.
121 # Provide the case of glibc td_thr_get_info handling of:
122 # /* Special case for the main thread before initialization.  */
123
124 foreach symbol {__stack_user stack_used} {
125     set test "clear ${symbol}.next"
126     gdb_test_multiple "p *(void **) &${symbol} = 0" $test {
127         -re " = \\(void \\*\\) 0x0\r\n$gdb_prompt $" {
128             pass $test
129         }
130         -re "No symbol \"${symbol}\" in current context\\.\r\n$gdb_prompt $" {
131             xfail $test
132             # Do not do the verification.
133             set core0file ""
134         }
135     }
136 }
137
138 if {"$core0file" != ""} {
139     gdb_test "gcore $core0file" "Saved corefile .*" "save a zeroed-threads corefile"
140 }
141
142
143 # Now restart gdb and load the corefile.
144 clean_restart ${testfile}
145
146 proc load_core { corefile } {
147     global gdb_prompt
148     global libthread_db_seen
149
150     set libthread_db_seen 0
151     gdb_test_multiple "core $corefile" \
152         "re-load generated corefile" {
153             -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
154                 set libthread_db_seen 1
155                 exp_continue
156             }
157             -re " is not a core dump:.*\r\n$gdb_prompt $" {
158                 fail "re-load generated corefile (bad file format)"
159                 # No use proceeding from here.
160                 return 0;
161             }
162             -re ": No such file or directory.*\r\n$gdb_prompt $" {
163                 fail "re-load generated corefile (file not found)"
164                 # No use proceeding from here.
165                 return 0;
166             }
167             -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
168                 fail "re-load generated corefile (incomplete note section)"
169             }
170             -re "Core was generated by .*\r\n$gdb_prompt $" {
171                 pass "re-load generated corefile"
172             }
173         }
174     return 1
175 }
176
177 if ![load_core $corefile] {
178     return
179 }
180
181 # FIXME: now what can we test about the thread state?
182 # We do not know for certain that there should be at least 
183 # three threads, because who knows what kind of many-to-one
184 # mapping various OS's may do?  Let's assume that there must
185 # be at least two threads:
186
187 gdb_test "info threads" ".*${nl}  2 ${horiz}${nl}\\* 1 .*" \
188         "corefile contains at least two threads"
189
190 # One thread in the corefile should be in the "thread2" function.
191
192 gdb_test "info threads" ".* thread2 .*" \
193         "a corefile thread is executing thread2"
194
195 # The thread2 thread should be marked as the current thread.
196
197 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
198         "thread2 is current thread in corefile"
199
200
201 # Test the uninitialized thread list.
202
203 if {"$core0file" != "" && [load_core $core0file]} {
204     set test "zeroed-threads cannot be listed"
205
206     if {!$libthread_db_seen} {
207         verbose -log "No libthread_db loaded - -Wl,-z,relro compilation?"
208         xfail $test
209     } else {
210         gdb_test "info threads" "Cannot find new threads: .*" $test
211     }
212 }