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