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

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