Blame SOURCES/gdb-6.3-mapping-zero-inode-test.patch

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