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

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