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

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