|
|
7a6771 |
Index: gdb-7.6.50.20130731-cvs/gdb/testsuite/gdb.base/gcore-shmid0.exp
|
|
|
7a6771 |
===================================================================
|
|
|
7a6771 |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
|
|
7a6771 |
+++ gdb-7.6.50.20130731-cvs/gdb/testsuite/gdb.base/gcore-shmid0.exp 2013-08-02 22:24:04.747745133 +0200
|
|
|
7a6771 |
@@ -0,0 +1,101 @@
|
|
|
7a6771 |
+# Copyright 2007, 2009 Free Software Foundation, Inc.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+# This program is free software; you can redistribute it and/or modify
|
|
|
7a6771 |
+# it under the terms of the GNU General Public License as published by
|
|
|
7a6771 |
+# the Free Software Foundation; either version 2 of the License, or
|
|
|
7a6771 |
+# (at your option) any later version.
|
|
|
7a6771 |
+#
|
|
|
7a6771 |
+# This program is distributed in the hope that it will be useful,
|
|
|
7a6771 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7a6771 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
7a6771 |
+# GNU General Public License for more details.
|
|
|
7a6771 |
+#
|
|
|
7a6771 |
+# You should have received a copy of the GNU General Public License
|
|
|
7a6771 |
+# along with this program; if not, write to the Free Software
|
|
|
7a6771 |
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+# Test GDB's handling of gcore for mapping with a name but zero inode.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+if { [prepare_for_testing gcore-shmid0.exp gcore-shmid0] } {
|
|
|
7a6771 |
+ return -1
|
|
|
7a6771 |
+}
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+# Does this gdb support gcore?
|
|
|
7a6771 |
+set test "help gcore"
|
|
|
7a6771 |
+gdb_test_multiple $test $test {
|
|
|
7a6771 |
+ -re "Undefined command: .gcore.*$gdb_prompt $" {
|
|
|
7a6771 |
+ # gcore command not supported -- nothing to test here.
|
|
|
7a6771 |
+ unsupported "gdb does not support gcore on this target"
|
|
|
7a6771 |
+ return -1;
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ -re "Save a core file .*$gdb_prompt $" {
|
|
|
7a6771 |
+ pass $test
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+}
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+if { ! [ runto_main ] } then {
|
|
|
7a6771 |
+ untested gcore-shmid0.exp
|
|
|
7a6771 |
+ return -1
|
|
|
7a6771 |
+}
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+gdb_breakpoint "initialized"
|
|
|
7a6771 |
+gdb_breakpoint "unresolved"
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+set oldtimeout $timeout
|
|
|
7a6771 |
+set timeout [expr $oldtimeout + 120]
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+set test "Continue to initialized."
|
|
|
7a6771 |
+gdb_test_multiple "continue" $test {
|
|
|
7a6771 |
+ -re "Breakpoint .*, initialized .* at .*\r\n$gdb_prompt $" {
|
|
|
7a6771 |
+ pass $test
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ -re "Breakpoint .*, unresolved .* at .*\r\n$gdb_prompt $" {
|
|
|
7a6771 |
+ set timeout $oldtimeout
|
|
|
7a6771 |
+ unsupported $test
|
|
|
7a6771 |
+ return -1
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+}
|
|
|
7a6771 |
+set timeout $oldtimeout
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore-shmid0.test]
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+set test "save a corefile"
|
|
|
7a6771 |
+gdb_test_multiple "gcore ${objdir}/${subdir}/gcore-shmid0.test" $test {
|
|
|
7a6771 |
+ -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
|
|
|
7a6771 |
+ pass $test
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
|
|
|
7a6771 |
+ unsupported $test
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+}
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+# Be sure to remove the handle first.
|
|
|
7a6771 |
+# But it would get removed even on a kill by GDB as the handle is already
|
|
|
7a6771 |
+# deleted, just it is still attached.
|
|
|
7a6771 |
+gdb_continue_to_end "finish"
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+set test "core-file command"
|
|
|
7a6771 |
+gdb_test_multiple "core-file $objdir/$subdir/gcore-shmid0.test" $test {
|
|
|
7a6771 |
+ -re ".* program is being debugged already.*y or n. $" {
|
|
|
7a6771 |
+ # gdb_load may connect us to a gdbserver.
|
|
|
7a6771 |
+ send_gdb "y\n"
|
|
|
7a6771 |
+ exp_continue;
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ -re "Core was generated by .*\r\n\#0 .*\\\(\\\).*\r\n$gdb_prompt $" {
|
|
|
7a6771 |
+ # The filename does not fit there anyway so do not check it.
|
|
|
7a6771 |
+ pass $test
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ -re ".*registers from core file: File in wrong format.* $" {
|
|
|
7a6771 |
+ fail "core-file command (could not read registers from core file)"
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+}
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+set test "backtrace"
|
|
|
7a6771 |
+gdb_test_multiple "bt" $test {
|
|
|
7a6771 |
+ -re "#0 *initialized \\\(\\\) at .*#1 .* main \\\(.*$gdb_prompt $" {
|
|
|
7a6771 |
+ pass $test
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ -re "#0 *initialized \\\(\\\) at .*Cannot access memory at address .*$gdb_prompt $" {
|
|
|
7a6771 |
+ fail $test
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+}
|
|
|
7a6771 |
Index: gdb-7.6.50.20130731-cvs/gdb/testsuite/gdb.base/gcore-shmid0.c
|
|
|
7a6771 |
===================================================================
|
|
|
7a6771 |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
|
|
7a6771 |
+++ gdb-7.6.50.20130731-cvs/gdb/testsuite/gdb.base/gcore-shmid0.c 2013-08-02 22:22:17.573599496 +0200
|
|
|
7a6771 |
@@ -0,0 +1,128 @@
|
|
|
7a6771 |
+/* Copyright 2007, 2009 Free Software Foundation, Inc.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ This file is part of GDB.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
7a6771 |
+ it under the terms of the GNU General Public License as published by
|
|
|
7a6771 |
+ the Free Software Foundation; either version 2 of the License, or (at
|
|
|
7a6771 |
+ your option) any later version.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ This program is distributed in the hope that it will be useful, but
|
|
|
7a6771 |
+ WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7a6771 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
7a6771 |
+ General Public License for more details.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ You should have received a copy of the GNU General Public License
|
|
|
7a6771 |
+ along with this program; if not, write to the Free Software
|
|
|
7a6771 |
+ Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
7a6771 |
+ Boston, MA 02111-1307, USA. */
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+/*
|
|
|
7a6771 |
+ * Test GDB's handling of gcore for mapping with a name but zero inode.
|
|
|
7a6771 |
+ */
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+#include <sys/ipc.h>
|
|
|
7a6771 |
+#include <sys/shm.h>
|
|
|
7a6771 |
+#include <stdio.h>
|
|
|
7a6771 |
+#include <errno.h>
|
|
|
7a6771 |
+#include <stdlib.h>
|
|
|
7a6771 |
+#include <unistd.h>
|
|
|
7a6771 |
+#include <assert.h>
|
|
|
7a6771 |
+#include <time.h>
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+/* The same test running in a parallel testsuite may steal us the zero SID,
|
|
|
7a6771 |
+ even if we never get any EEXIST. Just try a while. */
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+#define TIMEOUT_SEC 10
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+static volatile int v;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+static void
|
|
|
7a6771 |
+initialized (void)
|
|
|
7a6771 |
+{
|
|
|
7a6771 |
+ v++;
|
|
|
7a6771 |
+}
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+static void
|
|
|
7a6771 |
+unresolved (void)
|
|
|
7a6771 |
+{
|
|
|
7a6771 |
+ v++;
|
|
|
7a6771 |
+}
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+int
|
|
|
7a6771 |
+main (void)
|
|
|
7a6771 |
+{
|
|
|
7a6771 |
+ int sid;
|
|
|
7a6771 |
+ unsigned int *addr = (void *) -1L;
|
|
|
7a6771 |
+ int attempt, round = 0;
|
|
|
7a6771 |
+ time_t ts_start, ts;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ if (time (&ts_start) == (time_t) -1)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ printf ("time (): %m\n");
|
|
|
7a6771 |
+ exit (1);
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ /* The generated SID will cycle with an increment of 32768, attempt until it
|
|
|
7a6771 |
+ * wraps to 0. */
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ for (attempt = 0; addr == (void *) -1L; attempt++)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ /* kernel-2.6.25-8.fc9.x86_64 just never returns the value 0 by
|
|
|
7a6771 |
+ shmget(2). shmget returns SID range 0..1<<31 in steps of 32768,
|
|
|
7a6771 |
+ 0x1000 should be enough but wrap the range it to be sure. */
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ if (attempt > 0x21000)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ if (time (&ts) == (time_t) -1)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ printf ("time (): %m\n");
|
|
|
7a6771 |
+ exit (1);
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ if (ts >= ts_start && ts < ts_start + TIMEOUT_SEC)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ attempt = 0;
|
|
|
7a6771 |
+ round++;
|
|
|
7a6771 |
+ continue;
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ printf ("Problem is not reproducible on this kernel (attempt %d, "
|
|
|
7a6771 |
+ "round %d)\n", attempt, round);
|
|
|
7a6771 |
+ unresolved ();
|
|
|
7a6771 |
+ exit (1);
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ sid = shmget ((key_t) rand (), 0x1000, IPC_CREAT | IPC_EXCL | 0777);
|
|
|
7a6771 |
+ if (sid == -1)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ if (errno == EEXIST)
|
|
|
7a6771 |
+ continue;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ printf ("shmget (%d, 0x1000, IPC_CREAT): errno %d\n", 0, errno);
|
|
|
7a6771 |
+ exit (1);
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ /* Use SID only if it is 0, retry it otherwise. */
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ if (sid == 0)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ addr = shmat (sid, NULL, SHM_RND);
|
|
|
7a6771 |
+ if (addr == (void *) -1L)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ printf ("shmat (%d, NULL, SHM_RND): errno %d\n", sid,
|
|
|
7a6771 |
+ errno);
|
|
|
7a6771 |
+ exit (1);
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ if (shmctl (sid, IPC_RMID, NULL) != 0)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ printf ("shmctl (%d, IPC_RMID, NULL): errno %d\n", sid, errno);
|
|
|
7a6771 |
+ exit (1);
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ initialized ();
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ return 0;
|
|
|
7a6771 |
+}
|