1 # Copyright 2002 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Michael Snyder (msnyder@redhat.com)
21 # This is a test for the gdb command "generate-core-file".
30 # Single-threaded test case
31 set testfile "pthreads"
32 set srcfile ${testfile}.c
33 set binfile ${objdir}/${subdir}/${testfile}
36 if [istarget "*-*-linux"] then {
37 set target_cflags "-D_MIT_POSIX_THREADS"
41 set why_msg "unrecognized error"
42 foreach lib {-lpthreads -lpthread -lthread} {
44 lappend options "incdir=${objdir}/${subdir}"
45 lappend options "libs=$lib"
46 set ccout [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $options]
47 switch -regexp -- $ccout {
48 ".*no posix threads support.*" {
49 set why_msg "missing threads include file"
52 ".*cannot open -lpthread.*" {
53 set why_msg "missing runtime threads library"
55 ".*Can't find library for -lpthread.*" {
56 set why_msg "missing runtime threads library"
59 pass "successfully compiled posix threads test case"
65 if {$built_binfile == "0"} {
66 unsupported "Couldn't compile ${srcfile}, ${why_msg}"
70 # Now we can proceed with the real testing.
72 # Start with a fresh gdb.
76 gdb_reinitialize_dir $srcdir/$subdir
79 # regexp for "horizontal" text (i.e. doesn't include newline or
81 set horiz "\[^\n\r\]*"
88 send_gdb "help gcore\n"
90 -re "Undefined command: .gcore.*$gdb_prompt $" {
91 # gcore command not supported -- nothing to test here.
92 unsupported "gdb does not support gcore on this target"
95 -re "Save a core file .*$gdb_prompt $" {
98 -re ".*$gdb_prompt $" {
102 fail "help gcore (timeout)"
106 if { ! [ runto main ] } then {
107 gdb_suppress_entire_file "Run to main failed, so all tests in this file will automatically fail."
110 send_gdb "info threads\n"
112 -re ".* main .*$gdb_prompt $" {
113 # OK, threads are supported.
115 -re "${nl}$gdb_prompt $" {
116 unsupported "gdb does not support threads on this target"
121 # Make sure thread 1 is running
123 gdb_breakpoint "thread1"
124 gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
126 # Make sure thread 2 is running
128 gdb_breakpoint "thread2"
129 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
132 gdb_test "gcore ${objdir}/${subdir}/gcore.test" \
133 "Saved corefile ${objdir}/${subdir}/gcore.test" \
136 # Now restart gdb and load the corefile.
139 gdb_reinitialize_dir $srcdir/$subdir
142 send_gdb "core ${objdir}/${subdir}/gcore.test\n"
144 -re ".* is not a core dump:.*$gdb_prompt $" {
145 fail "re-load generated corefile (bad file format)"
146 # No use proceeding from here.
149 -re ".*: No such file or directory.*$gdb_prompt $" {
150 fail "re-load generated corefile (file not found)"
151 # No use proceeding from here.
154 -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
155 fail "re-load generated corefile (incomplete note section)"
157 -re "Core was generated by .*$gdb_prompt $" {
158 pass "re-load generated corefile"
160 -re ".*$gdb_prompt $" {
161 fail "re-load generated corefile"
164 fail "re-load generated corefile (timeout)"
168 # FIXME: now what can we test about the thread state?
169 # We do not know for certain that there should be at least
170 # three threads, because who knows what kind of many-to-one
171 # mapping various OS's may do? Let's assume that there must
172 # be at least two threads:
174 gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \
175 "corefile contains at least two threads"
177 # One thread in the corefile should be in the "thread2" function.
179 gdb_test "info threads" ".* thread2 .*" \
180 "a corefile thread is executing thread2"
182 # The thread2 thread should be marked as the current thread.
184 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
185 "thread2 is current thread in corefile"