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

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