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