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

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