1 # Copyright 2002, 2003, 2004, 2007, 2008, 2009, 2010
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".
27 # Single-threaded test case
28 set testfile "pthreads"
29 set srcfile ${testfile}.c
30 set binfile ${objdir}/${subdir}/gcore-${testfile}
32 if [istarget "*-*-linux"] then {
33 set target_cflags "-D_MIT_POSIX_THREADS"
38 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
42 # Now we can proceed with the real testing.
44 # Start with a fresh gdb.
48 gdb_reinitialize_dir $srcdir/$subdir
51 # regexp for "horizontal" text (i.e. doesn't include newline or
53 set horiz "\[^\n\r\]*"
58 set prev_timeout $timeout
61 send_gdb "help gcore\n"
63 -re "Undefined command: .gcore.*$gdb_prompt $" {
64 # gcore command not supported -- nothing to test here.
65 unsupported "gdb does not support gcore on this target"
68 -re "Save a core file .*$gdb_prompt $" {
71 -re ".*$gdb_prompt $" {
75 fail "help gcore (timeout)"
79 if { ! [ runto_main ] } then {
80 untested gcore-thread.exp
84 send_gdb "info threads\n"
86 -re ".* main .*$gdb_prompt $" {
87 # OK, threads are supported.
89 -re "${nl}$gdb_prompt $" {
90 unsupported "gdb does not support threads on this target"
95 # Make sure thread 1 is running
97 gdb_breakpoint "thread1"
98 gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
100 # Make sure thread 2 is running
102 gdb_breakpoint "thread2"
103 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
105 set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test]
107 gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \
110 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
111 pass "save a corefile"
112 global core_supported
115 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
116 unsupported "save a corefile"
117 global core_supported
122 global core_supported
123 if {!$core_supported} {
127 # Now restart gdb and load the corefile.
130 gdb_reinitialize_dir $srcdir/$subdir
133 send_gdb "core ${objdir}/${subdir}/gcore.test\n"
135 -re ".* is not a core dump:.*$gdb_prompt $" {
136 fail "re-load generated corefile (bad file format)"
137 # No use proceeding from here.
140 -re ".*: No such file or directory.*$gdb_prompt $" {
141 fail "re-load generated corefile (file not found)"
142 # No use proceeding from here.
145 -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
146 fail "re-load generated corefile (incomplete note section)"
148 -re "Core was generated by .*$gdb_prompt $" {
149 pass "re-load generated corefile"
151 -re ".*$gdb_prompt $" {
152 fail "re-load generated corefile"
155 fail "re-load generated corefile (timeout)"
159 # FIXME: now what can we test about the thread state?
160 # We do not know for certain that there should be at least
161 # three threads, because who knows what kind of many-to-one
162 # mapping various OS's may do? Let's assume that there must
163 # be at least two threads:
165 gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \
166 "corefile contains at least two threads"
168 # One thread in the corefile should be in the "thread2" function.
170 gdb_test "info threads" ".* thread2 .*" \
171 "a corefile thread is executing thread2"
173 # The thread2 thread should be marked as the current thread.
175 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
176 "thread2 is current thread in corefile"
178 set timeout $prev_timeout