• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修訂8ffdba260ca757521c815782a0fe01fedc84849a (tree)
時間2015-07-14 18:55:05
作者Pedro Alves <palves@redh...>
CommiterPedro Alves

Log Message

Add test that exercises the inferior being killed while stopped under GDB

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 previous patches.

gdb/testsuite/ChangeLog:
2015-07-14 Pedro Alves <palves@redhat.com>

* gdb.base/killed-outside.exp: New file.
* gdb.base/killed-outside.c: New file.

Change Summary

差異

--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
1+2015-07-14 Pedro Alves <palves@redhat.com>
2+
3+ * gdb.base/killed-outside.exp: New file.
4+ * gdb.base/killed-outside.c: New file.
5+
16 2015-07-10 Jan Kratochvil <jan.kratochvil@redhat.com>
27
38 * gdb.asm/asm-source.exp (f at main): Stop at gdbasm_enter.
--- /dev/null
+++ b/gdb/testsuite/gdb.base/killed-outside.c
@@ -0,0 +1,34 @@
1+/* This testcase is part of GDB, the GNU debugger.
2+
3+ Copyright 2015 Free Software Foundation, Inc.
4+
5+ This program is free software; you can redistribute it and/or modify
6+ it under the terms of the GNU General Public License as published by
7+ the Free Software Foundation; either version 3 of the License, or
8+ (at your option) any later version.
9+
10+ This program is distributed in the hope that it will be useful,
11+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ GNU General Public License for more details.
14+
15+ You should have received a copy of the GNU General Public License
16+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
17+
18+#include <sys/types.h>
19+#include <unistd.h>
20+
21+pid_t pid;
22+
23+static void
24+done (void)
25+{
26+}
27+
28+int
29+main (int argc, char **argv)
30+{
31+ pid = getpid ();
32+ done ();
33+ return 0;
34+}
--- /dev/null
+++ b/gdb/testsuite/gdb.base/killed-outside.exp
@@ -0,0 +1,130 @@
1+# Copyright 2015 Free Software Foundation, Inc.
2+
3+# This program is free software; you can redistribute it and/or modify
4+# it under the terms of the GNU General Public License as published by
5+# the Free Software Foundation; either version 3 of the License, or
6+# (at your option) any later version.
7+#
8+# This program is distributed in the hope that it will be useful,
9+# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+# GNU General Public License for more details.
12+#
13+# You should have received a copy of the GNU General Public License
14+# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+# Test that GDB doesn't get badly wedged if the inferior is killed
17+# from outside GDB (with SIGKILL) while the program is stopped.
18+
19+standard_testfile
20+
21+# Get the value of variable VAR in the inferior. MSG is used as the
22+# test message.
23+
24+proc get_value {var msg} {
25+ global expect_out
26+ global gdb_prompt
27+ global decimal
28+
29+ set value -1
30+ gdb_test_multiple "print $var" "$msg" {
31+ -re ".*= ($decimal).*\r\n$gdb_prompt $" {
32+ set value $expect_out(1,string)
33+ pass "$msg"
34+ }
35+ }
36+ return ${value}
37+}
38+
39+# Runs the program until a breakpoint, deletes all breakpoints, and
40+# then kills the inferior from _outside_ GDB, with SIGKILL. Runs CMDS
41+# afterwards, to make sure GDB copes with the inferior disappearing,
42+# and then quits GDB.
43+
44+proc test {cmds_after_kill} {
45+ global binfile
46+ global gdb_prompt
47+ global decimal
48+
49+ clean_restart ${binfile}
50+
51+ if ![runto done] {
52+ return
53+ }
54+
55+ # So that "continue" doesn't try a step over, etc.
56+ delete_breakpoints
57+
58+ set testpid [get_value "pid" "get pid of inferior"]
59+ if { $testpid == -1 } {
60+ return -1
61+ }
62+
63+ remote_exec target "kill -9 ${testpid}"
64+
65+ # Give it some time to die.
66+ sleep 2
67+
68+ uplevel 1 $cmds_after_kill
69+
70+ # Make sure we can quit.
71+ set msg "quit GDB"
72+ gdb_test_multiple "quit" $msg {
73+ -re "Quit anyway\\? \\(y or n\\) $" {
74+ send_gdb "y\n"
75+ exp_continue
76+ }
77+ eof {
78+ pass $msg
79+ }
80+ }
81+}
82+
83+if {[prepare_for_testing "failed to prepare" $testfile $srcfile $options] == -1} {
84+ return -1
85+}
86+
87+# The actual output GDB prints in response to commands after the
88+# inferior is gone isn't very well defined, and will depend on target.
89+# What we're trying to make sure is that GDB doesn't internal error or
90+# get wedged.
91+
92+# Try simply continuing.
93+with_test_prefix "continue" {
94+ test {
95+ # Try stepping the program. Stepping may need to read/write
96+ # registers, unlike continue.
97+ gdb_test "continue" ".*"
98+
99+ # Try listing threads afterwards. It's probably what the user
100+ # will do after an error.
101+ gdb_test "info threads" ".*"
102+ }
103+}
104+
105+# Try stepping the program. Stepping may go through diferent code
106+# paths in the target backends.
107+with_test_prefix "stepi" {
108+ test {
109+ gdb_test "si" ".*"
110+ gdb_test "info threads" ".*"
111+ }
112+}
113+
114+# Try fetching registers explicitly, which should cover the error many
115+# other commands would trigger.
116+with_test_prefix "registers" {
117+ test {
118+ gdb_test "flushregs" ".*"
119+ gdb_test "info threads" ".*"
120+ }
121+}
122+
123+# Try only listing threads explicitly, first thing, which is another
124+# operation GDB may or not decide to do itself and is likely to be
125+# what a user would try after error too.
126+with_test_prefix "info threads" {
127+ test {
128+ gdb_test "info threads" ".*"
129+ }
130+}