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