From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 6/6] Add test that exercises the inferior being killed while stopped under GDB
Date: Fri, 06 Mar 2015 20:27:00 -0000 [thread overview]
Message-ID: <1425671886-7798-7-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1425671886-7798-1-git-send-email-palves@redhat.com>
This exercises the case of the inferior disappearing while GDB is
debugging it, such as something doing "kill -9 PID" while the program
is stopped under GDB or GDBserver. This triggered a set of internal
errors, fixed by the previous patches.
gdb/testsuite/ChangeLog:
2015-03-06 Pedro Alves <palves@redhat.com>
* gdb.base/killed-outside.exp: New file.
* gdb.base/killed-outside.c: New file.
---
gdb/testsuite/gdb.base/killed-outside.c | 34 ++++++++
gdb/testsuite/gdb.base/killed-outside.exp | 130 ++++++++++++++++++++++++++++++
2 files changed, 164 insertions(+)
create mode 100644 gdb/testsuite/gdb.base/killed-outside.c
create mode 100644 gdb/testsuite/gdb.base/killed-outside.exp
diff --git a/gdb/testsuite/gdb.base/killed-outside.c b/gdb/testsuite/gdb.base/killed-outside.c
new file mode 100644
index 0000000..f0e9eda
--- /dev/null
+++ b/gdb/testsuite/gdb.base/killed-outside.c
@@ -0,0 +1,34 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 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 3 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, see <http://www.gnu.org/licenses/>. */
+
+#include <sys/types.h>
+#include <unistd.h>
+
+pid_t pid;
+
+static void
+done (void)
+{
+}
+
+int
+main (int argc, char **argv)
+{
+ pid = getpid ();
+ done ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/killed-outside.exp b/gdb/testsuite/gdb.base/killed-outside.exp
new file mode 100644
index 0000000..1e8c0d3
--- /dev/null
+++ b/gdb/testsuite/gdb.base/killed-outside.exp
@@ -0,0 +1,130 @@
+# Copyright 2015 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 3 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, see <http://www.gnu.org/licenses/>.
+
+# Test that GDB doesn't get badly wedged if the inferior is killed
+# from outside GDB (with SIGKILL) while the program is stopped.
+
+standard_testfile
+
+# Get the value of variable VAR in the inferior. MSG is used as the
+# test message.
+
+proc get_value {var msg} {
+ global expect_out
+ global gdb_prompt
+ global decimal
+
+ set value -1
+ gdb_test_multiple "print $var" "$msg" {
+ -re ".*= ($decimal).*\r\n$gdb_prompt $" {
+ set value $expect_out(1,string)
+ pass "$msg"
+ }
+ }
+ return ${value}
+}
+
+# Runs the program until a breakpoint, deletes all breakpoints, and
+# then kills the inferior from _outside_ GDB, with SIGKILL. Runs CMDS
+# afterwards, to make sure GDB copes with the inferior disappearing,
+# and then quits GDB.
+
+proc test {cmds_after_kill} {
+ global binfile
+ global gdb_prompt
+ global decimal
+
+ clean_restart ${binfile}
+
+ if ![runto done] {
+ return
+ }
+
+ # So that "continue" doesn't try a step over, etc.
+ delete_breakpoints
+
+ set testpid [get_value "pid" "get pid of inferior"]
+ if { $testpid == -1 } {
+ return -1
+ }
+
+ remote_exec target "kill -9 ${testpid}"
+
+ # Give it some time to die.
+ sleep 2
+
+ uplevel 1 $cmds_after_kill
+
+ # Make sure we can quit.
+ set msg "quit GDB"
+ gdb_test_multiple "quit" $msg {
+ -re "Quit anyway\\? \\(y or n\\) $" {
+ send_gdb "y\n"
+ exp_continue
+ }
+ eof {
+ pass $msg
+ }
+ }
+}
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile $options] == -1} {
+ return -1
+}
+
+# The actual output GDB prints in response to commands after the
+# inferior is gone isn't very well defined, and will depend on target.
+# What we're trying to make sure is that GDB doesn't internal error or
+# get wedged.
+
+# Try simply continuing.
+with_test_prefix "continue" {
+ test {
+ # Try stepping the program. Stepping may need to read/write
+ # registers, unlike continue.
+ gdb_test "continue" ".*"
+
+ # Try listing threads afterwards. It's probably what the user
+ # will do after an error.
+ gdb_test "info threads" ".*"
+ }
+}
+
+# Try stepping the program. Stepping may go through diferent code
+# paths in the target backends.
+with_test_prefix "stepi" {
+ test {
+ gdb_test "si" ".*"
+ gdb_test "info threads" ".*"
+ }
+}
+
+# Try fetching registers explicitly, which should cover the error many
+# other commands would trigger.
+with_test_prefix "registers" {
+ test {
+ gdb_test "flushregs" ".*"
+ gdb_test "info threads" ".*"
+ }
+}
+
+# Try only listing threads explicitly, first thing, which is another
+# operation GDB may or not decide to do itself and is likely to be
+# what a user would try after error too.
+with_test_prefix "info threads" {
+ test {
+ gdb_test "info threads" ".*"
+ }
+}
--
1.9.3
next prev parent reply other threads:[~2015-03-06 20:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-06 19:58 [PATCH 0/6] Fix problems if inferior disappears while being debugged Pedro Alves
2015-03-06 19:58 ` [PATCH 1/6] Move throw_perror_with_name to common/ Pedro Alves
2015-03-06 19:58 ` [PATCH 4/6] native/Linux: internal error if inferior disappears after stopped by breakpoint Pedro Alves
2015-03-19 12:37 ` [pushed] native/Linux: internal error if resume is short-circuited (Re: [PATCH 4/6] native/Linux: internal error if inferior disappears after stopped by breakpoint) Pedro Alves
2015-03-19 12:49 ` [pushed] gdbserver/Linux: unbreak thread event randomization (Re: [pushed] native/Linux: internal error if resume is short-circuited) Pedro Alves
2015-03-19 16:14 ` [PATCH] gdbserver/Linux: Unbreak non-stop (Re: [pushed] gdbserver/Linux: unbreak thread event randomization) Pedro Alves
2015-03-19 16:54 ` [pushed] " Pedro Alves
2015-03-06 19:58 ` [PATCH 3/6] Fix race exposed by gdb.threads/killed.exp Pedro Alves
2015-03-19 17:39 ` Pedro Alves
2015-03-06 19:58 ` [PATCH 5/6] gdbserver/Linux: internal error when killing a process that is already gone Pedro Alves
2015-03-06 19:58 ` [PATCH 2/6] Introduce throw_ptrace_error Pedro Alves
2015-03-06 21:04 ` Mark Kettenis
2015-03-06 21:40 ` Pedro Alves
2015-03-08 20:30 ` Mark Kettenis
2015-03-08 21:48 ` Pedro Alves
2015-03-10 14:53 ` Mark Kettenis
2015-03-11 15:44 ` Pedro Alves
2015-03-19 17:33 ` [pushed] Fix race exposed by gdb.threads/killed.exp (Re: [PATCH 2/6] Introduce throw_ptrace_error) Pedro Alves
2015-03-06 20:27 ` Pedro Alves [this message]
2015-07-14 10:22 ` [PATCH 6/6] Add test that exercises the inferior being killed while stopped under GDB Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1425671886-7798-7-git-send-email-palves@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox