1 # Copyright 2002, 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Michael Snyder (msnyder@redhat.com)
17 # This is a test for the gdb command "generate-core-file".
26 # Single-threaded test case
27 set testfile "pthreads"
28 set srcfile ${testfile}.c
29 set binfile ${objdir}/${subdir}/gcore-${testfile}
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.
47 gdb_reinitialize_dir $srcdir/$subdir
50 # regexp for "horizontal" text (i.e. doesn't include newline or
52 set horiz "\[^\n\r\]*"
59 send_gdb "help gcore\n"
61 -re "Undefined command: .gcore.*$gdb_prompt $" {
62 # gcore command not supported -- nothing to test here.
63 unsupported "gdb does not support gcore on this target"
66 -re "Save a core file .*$gdb_prompt $" {
69 -re ".*$gdb_prompt $" {
73 fail "help gcore (timeout)"
77 if { ! [ runto_main ] } then {
78 untested gcore-thread.exp
82 send_gdb "info threads\n"
84 -re ".* main .*$gdb_prompt $" {
85 # OK, threads are supported.
87 -re "${nl}$gdb_prompt $" {
88 unsupported "gdb does not support threads on this target"
93 # Make sure thread 1 is running
95 gdb_breakpoint "thread1"
96 gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
98 # Make sure thread 2 is running
100 gdb_breakpoint "thread2"
101 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
103 set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test]
105 gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \
108 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
109 pass "save a corefile"
110 global core_supported
113 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
114 unsupported "save a corefile"
115 global core_supported
120 global core_supported
121 if {!$core_supported} {
125 # Now restart gdb and load the corefile.
128 gdb_reinitialize_dir $srcdir/$subdir
131 send_gdb "core ${objdir}/${subdir}/gcore.test\n"
133 -re ".* is not a core dump:.*$gdb_prompt $" {
134 fail "re-load generated corefile (bad file format)"
135 # No use proceeding from here.
138 -re ".*: No such file or directory.*$gdb_prompt $" {
139 fail "re-load generated corefile (file not found)"
140 # No use proceeding from here.
143 -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
144 fail "re-load generated corefile (incomplete note section)"
146 -re "Core was generated by .*$gdb_prompt $" {
147 pass "re-load generated corefile"
149 -re ".*$gdb_prompt $" {
150 fail "re-load generated corefile"
153 fail "re-load generated corefile (timeout)"
157 # FIXME: now what can we test about the thread state?
158 # We do not know for certain that there should be at least
159 # three threads, because who knows what kind of many-to-one
160 # mapping various OS's may do? Let's assume that there must
161 # be at least two threads:
163 gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \
164 "corefile contains at least two threads"
166 # One thread in the corefile should be in the "thread2" function.
168 gdb_test "info threads" ".* thread2 .*" \
169 "a corefile thread is executing thread2"
171 # The thread2 thread should be marked as the current thread.
173 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
174 "thread2 is current thread in corefile"