2003-08-07 Elena Zannoni <ezannoni@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / gcore-thread.exp
1 # Copyright 2002, 2003 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 if [istarget "*-*-linux"] then {
36 set target_cflags "-D_MIT_POSIX_THREADS"
37 } else {
38 set target_cflags ""
39 }
40
41 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
42 return -1
43 }
44
45 # Now we can proceed with the real testing.
46
47 # Start with a fresh gdb.
48
49 gdb_exit
50 gdb_start
51 gdb_reinitialize_dir $srcdir/$subdir
52 gdb_load ${binfile}
53
54 # regexp for "horizontal" text (i.e. doesn't include newline or
55 # carriage return)
56 set horiz "\[^\n\r\]*"
57
58 # regexp for newline
59 set nl "\[\r\n\]+"
60
61 set timeout 30
62
63 send_gdb "help gcore\n"
64 gdb_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
81 if { ! [ runto main ] } then {
82 gdb_suppress_entire_file "Run to main failed, so all tests in this file will automatically fail."
83 }
84
85 send_gdb "info threads\n"
86 gdb_expect {
87 -re ".* main .*$gdb_prompt $" {
88 # OK, threads are supported.
89 }
90 -re "${nl}$gdb_prompt $" {
91 unsupported "gdb does not support threads on this target"
92 return -1;
93 }
94 }
95
96 # Make sure thread 1 is running
97 delete_breakpoints
98 gdb_breakpoint "thread1"
99 gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
100
101 # Make sure thread 2 is running
102 delete_breakpoints
103 gdb_breakpoint "thread2"
104 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
105
106 set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test]
107 # Drop corefile
108 gdb_test "gcore ${objdir}/${subdir}/gcore.test" \
109 "Saved corefile ${escapedfilename}" \
110 "save a corefile"
111
112 # Now restart gdb and load the corefile.
113 gdb_exit
114 gdb_start
115 gdb_reinitialize_dir $srcdir/$subdir
116 gdb_load ${binfile}
117
118 send_gdb "core ${objdir}/${subdir}/gcore.test\n"
119 gdb_expect {
120 -re ".* is not a core dump:.*$gdb_prompt $" {
121 fail "re-load generated corefile (bad file format)"
122 # No use proceeding from here.
123 return;
124 }
125 -re ".*: No such file or directory.*$gdb_prompt $" {
126 fail "re-load generated corefile (file not found)"
127 # No use proceeding from here.
128 return;
129 }
130 -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
131 fail "re-load generated corefile (incomplete note section)"
132 }
133 -re "Core was generated by .*$gdb_prompt $" {
134 pass "re-load generated corefile"
135 }
136 -re ".*$gdb_prompt $" {
137 fail "re-load generated corefile"
138 }
139 timeout {
140 fail "re-load generated corefile (timeout)"
141 }
142 }
143
144 # FIXME: now what can we test about the thread state?
145 # We do not know for certain that there should be at least
146 # three threads, because who knows what kind of many-to-one
147 # mapping various OS's may do? Let's assume that there must
148 # be at least two threads:
149
150 gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \
151 "corefile contains at least two threads"
152
153 # One thread in the corefile should be in the "thread2" function.
154
155 gdb_test "info threads" ".* thread2 .*" \
156 "a corefile thread is executing thread2"
157
158 # The thread2 thread should be marked as the current thread.
159
160 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
161 "thread2 is current thread in corefile"
162
This page took 0.135692 seconds and 4 git commands to generate.