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

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