1 # Copyright 2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
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.
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.
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/>.
17 # This file was written by Michael Snyder (msnyder@redhat.com)
18 # This is a test for the gdb command "generate-core-file".
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
31 if [istarget "*-*-linux"] then {
32 set target_cflags "-D_MIT_POSIX_THREADS"
37 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
41 # Now we can proceed with the real testing.
43 # Start with a fresh gdb.
45 clean_restart ${testfile}
47 # regexp for "horizontal" text (i.e. doesn't include newline or
49 set horiz "\[^\n\r\]*"
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"
62 -re "Save a core file .*$gdb_prompt $" {
67 if { ! [ runto_main ] } then {
68 untested gcore-thread.exp
72 gdb_test_multiple "info threads" "threads are supported" {
73 -re ".* main .*$gdb_prompt $" {
74 # OK, threads are supported.
76 -re "${nl}$gdb_prompt $" {
77 unsupported "gdb does not support threads on this target"
82 # Make sure thread 1 is running
84 gdb_breakpoint "thread1"
85 gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
87 # Make sure thread 2 is running
89 gdb_breakpoint "thread2"
90 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
92 set escapedfilename [string_to_regexp $corefile]
94 gdb_test_multiple "gcore $corefile" "save a corefile" \
96 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
97 pass "save a corefile"
101 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
102 unsupported "save a corefile"
103 global core_supported
108 global core_supported
109 if {!$core_supported} {
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. */
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 $" {
124 -re "No symbol \"${symbol}\" in current context\\.\r\n$gdb_prompt $" {
126 # Do not do the verification.
132 if {"$core0file" != ""} {
133 gdb_test "gcore $core0file" "Saved corefile .*" "save a zeroed-threads corefile"
137 # Now restart gdb and load the corefile.
138 clean_restart ${testfile}
140 proc load_core { corefile } {
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.
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.
155 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
156 fail "re-load generated corefile (incomplete note section)"
158 -re "Core was generated by .*\r\n$gdb_prompt $" {
159 pass "re-load generated corefile"
165 if ![load_core $corefile] {
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:
175 gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \
176 "corefile contains at least two threads"
178 # One thread in the corefile should be in the "thread2" function.
180 gdb_test "info threads" ".* thread2 .*" \
181 "a corefile thread is executing thread2"
183 # The thread2 thread should be marked as the current thread.
185 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
186 "thread2 is current thread in corefile"
189 # Test the uninitialized thread list.
191 if {"$core0file" != "" && [load_core $core0file]} {
193 gdb_test "info threads" "Cannot find new threads: .*" "zeroed-threads cannot be listed"