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

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