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

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