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

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