summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/attach-wait-input.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2014-07-09 15:59:02 +0100
committerPedro Alves <palves@redhat.com>2014-07-09 15:59:02 +0100
commit7180e04a36d812bbea2c280f2db33a7e8ce6b07b (patch)
tree6faeef54a13b3a432c270d02b1cd60d7b2602916 /gdb/testsuite/gdb.base/attach-wait-input.c
parent9a9a76082919371f4ceb571f6c9892325b80a2e0 (diff)
Fix "attach" command vs user input race
On async targets, a synchronous attach is done like this: #1 - target_attach is called (PTRACE_ATTACH is issued) #2 - a continuation is installed #3 - we go back to the event loop #4 - target reports stop (SIGSTOP), event loop wakes up, and attach continuation is called #5 - among other things, the continuation calls target_terminal_inferior, which removes stdin from the event loop Note that in #3, GDB is still processing user input. If the user is fast enough, e.g., with something like: echo -e "attach PID\nset xxx=1" | gdb ... then the "set" command is processed before the attach completes. We get worse behavior even, if input is a tty and therefore readline/editing is enabled, with e.g.,: (gdb) attach PID\nset xxx=1 we then crash readline/gdb, with: Attaching to program: attach-wait-input, process 14537 readline: readline_callback_read_char() called with no handler! Aborted $ Fix this by calling target_terminal_inferior before #3 above. The test covers both scenarios by running with editing/readline forced to both on and off. gdb/ 2014-07-09 Pedro Alves <palves@redhat.com> * infcmd.c (attach_command_post_wait): Don't call target_terminal_inferior here. (attach_command): Call it here instead. gdb/testsuite/ 2014-07-09 Pedro Alves <palves@redhat.com> * gdb.base/attach-wait-input.exp: New file. * gdb.base/attach-wait-input.c: New file.
Diffstat (limited to 'gdb/testsuite/gdb.base/attach-wait-input.c')
-rw-r--r--gdb/testsuite/gdb.base/attach-wait-input.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/attach-wait-input.c b/gdb/testsuite/gdb.base/attach-wait-input.c
new file mode 100644
index 0000000000..bddf2e1828
--- /dev/null
+++ b/gdb/testsuite/gdb.base/attach-wait-input.c
@@ -0,0 +1,40 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2014 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>
+
+volatile int should_exit = 0;
+int mypid;
+
+static void
+setup_done (void)
+{
+}
+
+int
+main (void)
+{
+ unsigned int counter = 1;
+
+ mypid = getpid ();
+ setup_done ();
+
+ for (counter = 0; !should_exit && counter < 100; counter++)
+ sleep (1);
+ return 0;
+}