1 Index: gdb-6.8.50.20090302/gdb/testsuite/gdb.base/gcore-shmid0.exp
2 ===================================================================
3 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4 +++ gdb-6.8.50.20090302/gdb/testsuite/gdb.base/gcore-shmid0.exp 2009-06-29 16:24:36.000000000 +0200
6 +# Copyright 2007, 2009 Free Software Foundation, Inc.
8 +# This program is free software; you can redistribute it and/or modify
9 +# it under the terms of the GNU General Public License as published by
10 +# the Free Software Foundation; either version 2 of the License, or
11 +# (at your option) any later version.
13 +# This program is distributed in the hope that it will be useful,
14 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
15 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 +# GNU General Public License for more details.
18 +# You should have received a copy of the GNU General Public License
19 +# along with this program; if not, write to the Free Software
20 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 +# Test GDB's handling of gcore for mapping with a name but zero inode.
24 +if { [prepare_for_testing gcore-shmid0.exp gcore-shmid0] } {
28 +# Does this gdb support gcore?
29 +set test "help gcore"
30 +gdb_test_multiple $test $test {
31 + -re "Undefined command: .gcore.*$gdb_prompt $" {
32 + # gcore command not supported -- nothing to test here.
33 + unsupported "gdb does not support gcore on this target"
36 + -re "Save a core file .*$gdb_prompt $" {
41 +if { ! [ runto_main ] } then {
42 + untested gcore-shmid0.exp
46 +gdb_breakpoint "initialized"
47 +gdb_breakpoint "unresolved"
49 +set test "Continue to initialized."
50 +gdb_test_multiple "continue" $test {
51 + -re "Breakpoint .*, initialized .* at .*\r\n$gdb_prompt $" {
54 + -re "Breakpoint .*, unresolved .* at .*\r\n$gdb_prompt $" {
60 +set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore-shmid0.test]
62 +set test "save a corefile"
63 +gdb_test_multiple "gcore ${objdir}/${subdir}/gcore-shmid0.test" $test {
64 + -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
67 + -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
72 +# Be sure to remove the handle first.
73 +# But it would get removed even on a kill by GDB as the handle is already
74 +# deleted, just it is still attached.
75 +gdb_continue_to_end "finish"
77 +set test "core-file command"
78 +gdb_test_multiple "core-file $objdir/$subdir/gcore-shmid0.test" $test {
79 + -re ".* program is being debugged already.*y or n. $" {
80 + # gdb_load may connect us to a gdbserver.
84 + -re "Core was generated by .*\r\n\#0 .*\\\(\\\).*\r\n$gdb_prompt $" {
85 + # The filename does not fit there anyway so do not check it.
88 + -re ".*registers from core file: File in wrong format.* $" {
89 + fail "core-file command (could not read registers from core file)"
94 +gdb_test_multiple "bt" $test {
95 + -re "#0 *initialized \\\(\\\) at .*#1 .* main \\\(.*$gdb_prompt $" {
98 + -re "#0 *initialized \\\(\\\) at .*Cannot access memory at address .*$gdb_prompt $" {
102 Index: gdb-6.8.50.20090302/gdb/testsuite/gdb.base/gcore-shmid0.c
103 ===================================================================
104 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
105 +++ gdb-6.8.50.20090302/gdb/testsuite/gdb.base/gcore-shmid0.c 2009-06-29 16:22:49.000000000 +0200
107 +/* Copyright 2007, 2009 Free Software Foundation, Inc.
109 + This file is part of GDB.
111 + This program is free software; you can redistribute it and/or modify
112 + it under the terms of the GNU General Public License as published by
113 + the Free Software Foundation; either version 2 of the License, or (at
114 + your option) any later version.
116 + This program is distributed in the hope that it will be useful, but
117 + WITHOUT ANY WARRANTY; without even the implied warranty of
118 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
119 + General Public License for more details.
121 + You should have received a copy of the GNU General Public License
122 + along with this program; if not, write to the Free Software
123 + Foundation, Inc., 59 Temple Place - Suite 330,
124 + Boston, MA 02111-1307, USA. */
127 + * Test GDB's handling of gcore for mapping with a name but zero inode.
130 +#include <sys/ipc.h>
131 +#include <sys/shm.h>
138 +/* The same test running in a parallel testsuite may steal us the zero SID,
139 + even if we never get any EEXIST. Just try a while. */
141 +#define TIMEOUT_SEC 10
157 + unsigned int *addr = (void *) -1L;
158 + int attempt, round = 0;
159 + time_t ts_start, ts;
161 + if (time (&ts_start) == (time_t) -1)
163 + printf ("time (): %m\n");
167 + /* The generated SID will cycle with an increment of 32768, attempt until it
170 + for (attempt = 0; addr == (void *) -1L; attempt++)
172 + /* kernel-2.6.25-8.fc9.x86_64 just never returns the value 0 by
173 + shmget(2). shmget returns SID range 0..1<<31 in steps of 32768,
174 + 0x1000 should be enough but wrap the range it to be sure. */
176 + if (attempt > 0x21000)
178 + if (time (&ts) == (time_t) -1)
180 + printf ("time (): %m\n");
184 + if (ts >= ts_start && ts < ts_start + TIMEOUT_SEC)
191 + printf ("Problem is not reproducible on this kernel (attempt %d, "
192 + "round %d))\n", attempt, round);
197 + sid = shmget ((key_t) rand (), 0x1000, IPC_CREAT | IPC_EXCL | 0777);
200 + if (errno == EEXIST)
203 + printf ("shmget (%d, 0x1000, IPC_CREAT): errno %d\n", 0, errno);
207 + /* Use SID only if it is 0, retry it otherwise. */
211 + addr = shmat (sid, NULL, SHM_RND);
212 + if (addr == (void *) -1L)
214 + printf ("shmat (%d, NULL, SHM_RND): errno %d\n", sid,
219 + if (shmctl (sid, IPC_RMID, NULL) != 0)
221 + printf ("shmctl (%d, IPC_RMID, NULL): errno %d\n", sid, errno);