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

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