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

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