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

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