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
4 +# Copyright 2007 Free Software Foundation, Inc.
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.
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.
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.
20 +# Please email any bugs, comments, and/or additions to this file to:
21 +# bug-gdb@prep.ai.mit.edu
23 +# Test GDB's handling of gcore for mapping with a name but zero inode.
25 +set testfile "gcore-shmid0"
26 +set srcfile ${testfile}.c
27 +set binfile ${objdir}/${subdir}/${testfile}
29 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34 +# Start with a fresh gdb.
38 +gdb_reinitialize_dir $srcdir/$subdir
41 +# Does this gdb support gcore?
42 +send_gdb "help gcore\n"
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"
49 + -re "Save a core file .*$gdb_prompt $" {
52 + -re ".*$gdb_prompt $" {
56 + fail "help gcore (timeout)"
60 +if { ! [ runto_main ] } then {
61 + untested gcore-shmid0.exp
65 +gdb_breakpoint "initialized"
66 +gdb_breakpoint "unresolved"
68 +set test "Continue to initialized."
69 +gdb_test_multiple "continue" $test {
70 + -re "Breakpoint .*, initialized .* at .*\r\n$gdb_prompt $" {
73 + -re "Breakpoint .*, unresolved .* at .*\r\n$gdb_prompt $" {
79 +set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore-shmid0.test]
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 $" {
86 + -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
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"
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.
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.
110 + -re ".*registers from core file: File in wrong format.* $" {
111 + fail "core-file command (could not read registers from core file)"
115 +set test "backtrace"
116 +gdb_test_multiple "bt" $test {
117 + -re "#0 *initialized \\\(\\\) at .*#1 .* main \\\(.*$gdb_prompt $" {
120 + -re "#0 *initialized \\\(\\\) at .*Cannot access memory at address .*$gdb_prompt $" {
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
127 +/* Copyright 2007 Free Software Foundation, Inc.
129 + This file is part of GDB.
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.
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.
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. */
147 + * Test GDB's handling of gcore for mapping with a name but zero inode.
150 +#include <sys/ipc.h>
151 +#include <sys/shm.h>
158 +/* We need a backtrace through the stack. */
174 + unsigned int *addr = (void *) -1L;
177 + /* The generated SID will cycle with an increment of 32768, try until it
180 + for (try = 0; addr == (void *) -1L; try++)
182 + /* At least kernel-2.6.25-8.fc9.x86_64 just never returns the value 0 by
186 + printf ("Problem no longer reproducible on this kernel (try %d)\n",
192 + sid = shmget ((key_t) rand (), 0x1000, IPC_CREAT | IPC_EXCL | 0777);
195 + printf ("shmget (%d, 0x1000, IPC_CREAT): errno %d\n", 0, errno);
199 + /* Use SID only if it is 0, retry it otherwise. */
203 + addr = shmat (sid, NULL, SHM_RND);
204 + if (addr == (void *) -1L)
206 + printf ("shmat (%d, NULL, SHM_RND): errno %d\n", sid,
211 + if (shmctl (sid, IPC_RMID, NULL) != 0)
213 + printf ("shmctl (%d, IPC_RMID, NULL): errno %d\n", sid, errno);