]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/gcore-thread.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / gcore-thread.exp
CommitLineData
6aba47ca 1# Copyright 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
a911c360
MS
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 2 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, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20# This file was written by Michael Snyder (msnyder@redhat.com)
21# This is a test for the gdb command "generate-core-file".
22
23if $tracelevel then {
24 strace $tracelevel
25}
26
27set prms_id 0
28set bug_id 0
29
30# Single-threaded test case
31set testfile "pthreads"
32set srcfile ${testfile}.c
19ac3974 33set binfile ${objdir}/${subdir}/gcore-${testfile}
a911c360 34
a911c360
MS
35if [istarget "*-*-linux"] then {
36 set target_cflags "-D_MIT_POSIX_THREADS"
37} else {
38 set target_cflags ""
39}
b5ab8ff3
DJ
40
41if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
a911c360
MS
42 return -1
43}
44
45# Now we can proceed with the real testing.
46
47# Start with a fresh gdb.
48
49gdb_exit
50gdb_start
51gdb_reinitialize_dir $srcdir/$subdir
52gdb_load ${binfile}
53
54# regexp for "horizontal" text (i.e. doesn't include newline or
55# carriage return)
56set horiz "\[^\n\r\]*"
57
58# regexp for newline
59set nl "\[\r\n\]+"
60
61set timeout 30
62
63send_gdb "help gcore\n"
64gdb_expect {
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 -re ".*$gdb_prompt $" {
74 fail "help gcore"
75 }
76 timeout {
77 fail "help gcore (timeout)"
78 }
79}
80
3ad13771 81if { ! [ runto_main ] } then {
b60f0898
JB
82 untested gcore-thread.exp
83 return -1
a911c360
MS
84}
85
86send_gdb "info threads\n"
87gdb_expect {
88 -re ".* main .*$gdb_prompt $" {
89 # OK, threads are supported.
90 }
91 -re "${nl}$gdb_prompt $" {
92 unsupported "gdb does not support threads on this target"
93 return -1;
94 }
95}
96
97# Make sure thread 1 is running
98delete_breakpoints
99gdb_breakpoint "thread1"
100gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
101
102# Make sure thread 2 is running
103delete_breakpoints
104gdb_breakpoint "thread2"
105gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
106
e0f353ce 107set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test]
a911c360 108# Drop corefile
7d605576
DJ
109gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \
110 "save a corefile" \
111{
112 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
113 pass "save a corefile"
114 global core_supported
115 set core_supported 1
116 }
117 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
118 unsupported "save a corefile"
119 global core_supported
120 set core_supported 0
121 }
122}
123
124global core_supported
125if {!$core_supported} {
126 return -1
127}
a911c360
MS
128
129# Now restart gdb and load the corefile.
130gdb_exit
131gdb_start
132gdb_reinitialize_dir $srcdir/$subdir
133gdb_load ${binfile}
134
135send_gdb "core ${objdir}/${subdir}/gcore.test\n"
136gdb_expect {
137 -re ".* is not a core dump:.*$gdb_prompt $" {
138 fail "re-load generated corefile (bad file format)"
139 # No use proceeding from here.
140 return;
141 }
142 -re ".*: No such file or directory.*$gdb_prompt $" {
143 fail "re-load generated corefile (file not found)"
144 # No use proceeding from here.
145 return;
146 }
147 -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
148 fail "re-load generated corefile (incomplete note section)"
149 }
150 -re "Core was generated by .*$gdb_prompt $" {
151 pass "re-load generated corefile"
152 }
153 -re ".*$gdb_prompt $" {
154 fail "re-load generated corefile"
155 }
156 timeout {
157 fail "re-load generated corefile (timeout)"
158 }
159}
160
161# FIXME: now what can we test about the thread state?
162# We do not know for certain that there should be at least
163# three threads, because who knows what kind of many-to-one
164# mapping various OS's may do? Let's assume that there must
165# be at least two threads:
166
167gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \
168 "corefile contains at least two threads"
169
170# One thread in the corefile should be in the "thread2" function.
171
172gdb_test "info threads" ".* thread2 .*" \
173 "a corefile thread is executing thread2"
174
175# The thread2 thread should be marked as the current thread.
176
177gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
178 "thread2 is current thread in corefile"
179