]>
Commit | Line | Data |
---|---|---|
3a58abaf AM |
1 | --- /dev/null 2008-05-02 23:36:22.370004160 +0200 |
2 | +++ gdb-6.8/gdb/testsuite/gdb.base/gcore-shmid0.exp 2008-05-03 22:36:56.000000000 +0200 | |
3 | @@ -0,0 +1,120 @@ | |
4 | +# Copyright 2007 Free Software Foundation, Inc. | |
5 | + | |
6 | +# This program is free software; you can redistribute it and/or modify | |
7 | +# it under the terms of the GNU General Public License as published by | |
8 | +# the Free Software Foundation; either version 2 of the License, or | |
9 | +# (at your option) any later version. | |
10 | +# | |
11 | +# This program is distributed in the hope that it will be useful, | |
12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | +# GNU General Public License for more details. | |
15 | +# | |
16 | +# You should have received a copy of the GNU General Public License | |
17 | +# along with this program; if not, write to the Free Software | |
18 | +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
19 | + | |
20 | +# Please email any bugs, comments, and/or additions to this file to: | |
21 | +# bug-gdb@prep.ai.mit.edu | |
22 | + | |
23 | +# Test GDB's handling of gcore for mapping with a name but zero inode. | |
24 | + | |
25 | +set testfile "gcore-shmid0" | |
26 | +set srcfile ${testfile}.c | |
27 | +set binfile ${objdir}/${subdir}/${testfile} | |
28 | + | |
29 | +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
30 | + untested gcore.exp | |
31 | + return -1 | |
32 | +} | |
33 | + | |
34 | +# Start with a fresh gdb. | |
35 | + | |
36 | +gdb_exit | |
37 | +gdb_start | |
38 | +gdb_reinitialize_dir $srcdir/$subdir | |
39 | +gdb_load ${binfile} | |
40 | + | |
41 | +# Does this gdb support gcore? | |
42 | +send_gdb "help gcore\n" | |
43 | +gdb_expect { | |
44 | + -re "Undefined command: .gcore.*$gdb_prompt $" { | |
45 | + # gcore command not supported -- nothing to test here. | |
46 | + unsupported "gdb does not support gcore on this target" | |
47 | + return -1; | |
48 | + } | |
49 | + -re "Save a core file .*$gdb_prompt $" { | |
50 | + pass "help gcore" | |
51 | + } | |
52 | + -re ".*$gdb_prompt $" { | |
53 | + fail "help gcore" | |
54 | + } | |
55 | + timeout { | |
56 | + fail "help gcore (timeout)" | |
57 | + } | |
58 | +} | |
59 | + | |
60 | +if { ! [ runto_main ] } then { | |
61 | + untested gcore-shmid0.exp | |
62 | + return -1 | |
63 | +} | |
64 | + | |
65 | +gdb_breakpoint "initialized" | |
66 | +gdb_breakpoint "unresolved" | |
67 | + | |
68 | +set test "Continue to initialized." | |
69 | +gdb_test_multiple "continue" $test { | |
70 | + -re "Breakpoint .*, initialized .* at .*\r\n$gdb_prompt $" { | |
71 | + pass $test | |
72 | + } | |
73 | + -re "Breakpoint .*, unresolved .* at .*\r\n$gdb_prompt $" { | |
74 | + unsupported $test | |
75 | + return -1 | |
76 | + } | |
77 | +} | |
78 | + | |
79 | +set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore-shmid0.test] | |
80 | + | |
81 | +set test "save a corefile" | |
82 | +gdb_test_multiple "gcore ${objdir}/${subdir}/gcore-shmid0.test" $test { | |
83 | + -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" { | |
84 | + pass $test | |
85 | + } | |
86 | + -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" { | |
87 | + unsupported $test | |
88 | + } | |
89 | + eof { | |
90 | + fail $test | |
91 | + } | |
92 | +} | |
93 | + | |
94 | +# Be sure to remove the handle first. | |
95 | +# But it would get removed even on a kill by GDB as the handle is already | |
96 | +# deleted, just it is still attached. | |
97 | +gdb_continue_to_end "finish" | |
98 | + | |
99 | +set test "core-file command" | |
100 | +gdb_test_multiple "core-file $objdir/$subdir/gcore-shmid0.test" $test { | |
101 | + -re ".* program is being debugged already.*y or n. $" { | |
102 | + # gdb_load may connect us to a gdbserver. | |
103 | + send_gdb "y\n" | |
104 | + exp_continue; | |
105 | + } | |
106 | + -re "Core was generated by .*\r\n\#0 .*\\\(\\\).*\r\n$gdb_prompt $" { | |
107 | + # The filename does not fit there anyway so do not check it. | |
108 | + pass $test | |
109 | + } | |
110 | + -re ".*registers from core file: File in wrong format.* $" { | |
111 | + fail "core-file command (could not read registers from core file)" | |
112 | + } | |
113 | +} | |
114 | + | |
115 | +set test "backtrace" | |
116 | +gdb_test_multiple "bt" $test { | |
117 | + -re "#0 *initialized \\\(\\\) at .*#1 .* main \\\(.*$gdb_prompt $" { | |
118 | + pass $test | |
119 | + } | |
120 | + -re "#0 *initialized \\\(\\\) at .*Cannot access memory at address .*$gdb_prompt $" { | |
121 | + fail $test | |
122 | + } | |
123 | +} | |
124 | --- /dev/null 2008-05-02 23:36:22.370004160 +0200 | |
125 | +++ gdb-6.8/gdb/testsuite/gdb.base/gcore-shmid0.c 2008-05-03 22:39:10.000000000 +0200 | |
126 | @@ -0,0 +1,95 @@ | |
127 | +/* Copyright 2007 Free Software Foundation, Inc. | |
128 | + | |
129 | + This file is part of GDB. | |
130 | + | |
131 | + This program is free software; you can redistribute it and/or modify | |
132 | + it under the terms of the GNU General Public License as published by | |
133 | + the Free Software Foundation; either version 2 of the License, or (at | |
134 | + your option) any later version. | |
135 | + | |
136 | + This program is distributed in the hope that it will be useful, but | |
137 | + WITHOUT ANY WARRANTY; without even the implied warranty of | |
138 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
139 | + General Public License for more details. | |
140 | + | |
141 | + You should have received a copy of the GNU General Public License | |
142 | + along with this program; if not, write to the Free Software | |
143 | + Foundation, Inc., 59 Temple Place - Suite 330, | |
144 | + Boston, MA 02111-1307, USA. */ | |
145 | + | |
146 | +/* | |
147 | + * Test GDB's handling of gcore for mapping with a name but zero inode. | |
148 | + */ | |
149 | + | |
150 | +#include <sys/ipc.h> | |
151 | +#include <sys/shm.h> | |
152 | +#include <stdio.h> | |
153 | +#include <errno.h> | |
154 | +#include <stdlib.h> | |
155 | +#include <unistd.h> | |
156 | +#include <assert.h> | |
157 | + | |
158 | +/* We need a backtrace through the stack. */ | |
159 | + | |
160 | +static void | |
161 | +initialized (void) | |
162 | +{ | |
163 | +} | |
164 | + | |
165 | +static void | |
166 | +unresolved (void) | |
167 | +{ | |
168 | +} | |
169 | + | |
170 | +int | |
171 | +main (void) | |
172 | +{ | |
173 | + int sid; | |
174 | + unsigned int *addr = (void *) -1L; | |
175 | + int try; | |
176 | + | |
177 | + /* The generated SID will cycle with an increment of 32768, try until it | |
178 | + * wraps to 0. */ | |
179 | + | |
180 | + for (try = 0; addr == (void *) -1L; try++) | |
181 | + { | |
182 | + /* At least kernel-2.6.25-8.fc9.x86_64 just never returns the value 0 by | |
183 | + shmget(2). */ | |
184 | + if (try > 0x10000) | |
185 | + { | |
186 | + printf ("Problem no longer reproducible on this kernel (try %d)\n", | |
187 | + try); | |
188 | + unresolved (); | |
189 | + exit (1); | |
190 | + } | |
191 | + | |
192 | + sid = shmget ((key_t) rand (), 0x1000, IPC_CREAT | IPC_EXCL | 0777); | |
193 | + if (sid == -1) | |
194 | + { | |
195 | + printf ("shmget (%d, 0x1000, IPC_CREAT): errno %d\n", 0, errno); | |
196 | + exit (1); | |
197 | + } | |
198 | + | |
199 | + /* Use SID only if it is 0, retry it otherwise. */ | |
200 | + | |
201 | + if (sid == 0) | |
202 | + { | |
203 | + addr = shmat (sid, NULL, SHM_RND); | |
204 | + if (addr == (void *) -1L) | |
205 | + { | |
206 | + printf ("shmat (%d, NULL, SHM_RND): errno %d\n", sid, | |
207 | + errno); | |
208 | + exit (1); | |
209 | + } | |
210 | + } | |
211 | + if (shmctl (sid, IPC_RMID, NULL) != 0) | |
212 | + { | |
213 | + printf ("shmctl (%d, IPC_RMID, NULL): errno %d\n", sid, errno); | |
214 | + exit (1); | |
215 | + } | |
216 | + } | |
217 | + | |
218 | + initialized (); | |
219 | + | |
220 | + return 0; | |
221 | +} |