2002-01-08 Michael Snyder <msnyder@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / gcore-thread.exp
1 # Copyright 2002 Free Software Foundation, Inc.
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
23 if $tracelevel then {
24 strace $tracelevel
25 }
26
27 set prms_id 0
28 set bug_id 0
29
30 # Single-threaded test case
31 set testfile "pthreads"
32 set srcfile ${testfile}.c
33 set binfile ${objdir}/${subdir}/${testfile}
34
35 set built_binfile 0
36 if [istarget "*-*-linux"] then {
37 set target_cflags "-D_MIT_POSIX_THREADS"
38 } else {
39 set target_cflags ""
40 }
41 set why_msg "unrecognized error"
42 foreach lib {-lpthreads -lpthread -lthread} {
43 set options "debug"
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"
50 break
51 }
52 ".*cannot open -lpthread.*" {
53 set why_msg "missing runtime threads library"
54 }
55 ".*Can't find library for -lpthread.*" {
56 set why_msg "missing runtime threads library"
57 }
58 {^$} {
59 pass "successfully compiled posix threads test case"
60 set built_binfile 1
61 break
62 }
63 }
64 }
65 if {$built_binfile == "0"} {
66 unsupported "Couldn't compile ${srcfile}, ${why_msg}"
67 return -1
68 }
69
70 # Now we can proceed with the real testing.
71
72 # Start with a fresh gdb.
73
74 gdb_exit
75 gdb_start
76 gdb_reinitialize_dir $srcdir/$subdir
77 gdb_load ${binfile}
78
79 # regexp for "horizontal" text (i.e. doesn't include newline or
80 # carriage return)
81 set horiz "\[^\n\r\]*"
82
83 # regexp for newline
84 set nl "\[\r\n\]+"
85
86 set timeout 30
87
88 send_gdb "help gcore\n"
89 gdb_expect {
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"
93 return -1;
94 }
95 -re "Save a core file .*$gdb_prompt $" {
96 pass "help gcore"
97 }
98 -re ".*$gdb_prompt $" {
99 fail "help gcore"
100 }
101 timeout {
102 fail "help gcore (timeout)"
103 }
104 }
105
106 if { ! [ runto main ] } then {
107 gdb_suppress_entire_file "Run to main failed, so all tests in this file will automatically fail."
108 }
109
110 send_gdb "info threads\n"
111 gdb_expect {
112 -re ".* main .*$gdb_prompt $" {
113 # OK, threads are supported.
114 }
115 -re "${nl}$gdb_prompt $" {
116 unsupported "gdb does not support threads on this target"
117 return -1;
118 }
119 }
120
121 # Make sure thread 1 is running
122 delete_breakpoints
123 gdb_breakpoint "thread1"
124 gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
125
126 # Make sure thread 2 is running
127 delete_breakpoints
128 gdb_breakpoint "thread2"
129 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
130
131 # Drop corefile
132 gdb_test "gcore ${objdir}/${subdir}/gcore.test" \
133 "Saved corefile ${objdir}/${subdir}/gcore.test" \
134 "save a corefile"
135
136 # Now restart gdb and load the corefile.
137 gdb_exit
138 gdb_start
139 gdb_reinitialize_dir $srcdir/$subdir
140 gdb_load ${binfile}
141
142 send_gdb "core ${objdir}/${subdir}/gcore.test\n"
143 gdb_expect {
144 -re ".* is not a core dump:.*$gdb_prompt $" {
145 fail "re-load generated corefile (bad file format)"
146 # No use proceeding from here.
147 return;
148 }
149 -re ".*: No such file or directory.*$gdb_prompt $" {
150 fail "re-load generated corefile (file not found)"
151 # No use proceeding from here.
152 return;
153 }
154 -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
155 fail "re-load generated corefile (incomplete note section)"
156 }
157 -re "Core was generated by .*$gdb_prompt $" {
158 pass "re-load generated corefile"
159 }
160 -re ".*$gdb_prompt $" {
161 fail "re-load generated corefile"
162 }
163 timeout {
164 fail "re-load generated corefile (timeout)"
165 }
166 }
167
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:
173
174 gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \
175 "corefile contains at least two threads"
176
177 # One thread in the corefile should be in the "thread2" function.
178
179 gdb_test "info threads" ".* thread2 .*" \
180 "a corefile thread is executing thread2"
181
182 # The thread2 thread should be marked as the current thread.
183
184 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
185 "thread2 is current thread in corefile"
186
This page took 0.034982 seconds and 4 git commands to generate.