diff options
author | Pedro Alves <palves@redhat.com> | 2015-01-14 11:51:06 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2015-01-14 11:51:06 +0000 |
commit | 6c400b59d574782afdb26eb6c021f28c31bb9f1c (patch) | |
tree | d702270f4bee3579f4bea7bbc3a9c85bcaf4ab82 /gdb/infrun.c | |
parent | e02c96a79949824bbe1da22ddfc6b50d362fb552 (diff) | |
download | gdb-6c400b59d574782afdb26eb6c021f28c31bb9f1c.zip gdb-6c400b59d574782afdb26eb6c021f28c31bb9f1c.tar.gz gdb-6c400b59d574782afdb26eb6c021f28c31bb9f1c.tar.bz2 |
PR cli/17828: -batch -ex r breaks terminal
Commit d3d4baed (PR python/17372 - Python hangs when displaying
help()) had the side effect of causing 'gdb -batch' to leave the
terminal in the wrong state if the program was run. E.g,.
$ echo 'main(){*(int*)0=0;}' | gcc -x c -; ./gdb/gdb -batch -ex r ./a.out
Program received signal SIGSEGV, Segmentation fault.
0x00000000004004ff in main ()
$
If you start typing the next command, seemingly nothing happens - GDB
left the terminal with echo disabled.
The issue is that that "r" ends up in fetch_inferior_event, which
calls reinstall_readline_callback_handler_cleanup, which causes
readline to prep the terminal (raw, echo disabled). But "-batch"
causes GDB to exit before the top level event loop is first started,
and then nothing de-preps the terminal.
The reinstall_readline_callback_handler_cleanup function's intro
comment mentions:
"Need to do this as we go back to the event loop, ready to process
further input."
but the implementation forgets the case of when the interpreter is
sync, which indicates we won't return to the event loop yet, or as in
the case of -batch, we have not started it yet.
The fix is to not install the readline callback in that case.
For the test, in this case, checking that command echo still works is
sufficient. Comparing stty output before/after running GDB is even
better. Because stty may not be available, the test tries both ways.
In any case, since expect's spawn (what we use to start gdb) creates a
new pseudo tty, another expect spawn or tcl exec after GDB exits would
not see the wrong terminal settings. So instead, the test spawns a
shell and runs stty and GDB in it.
Tested on x86_64 Fedora 20.
gdb/
2015-01-14 Pedro Alves <palves@redhat.com>
PR cli/17828
* infrun.c (reinstall_readline_callback_handler_cleanup): Don't
reinstall if the interpreter is sync.
gdb/testsuite/
2015-01-14 Pedro Alves <palves@redhat.com>
PR cli/17828
* gdb.base/batch-preserve-term-settings.c: New file.
* gdb.base/batch-preserve-term-settings.exp: New file.
Diffstat (limited to 'gdb/infrun.c')
-rw-r--r-- | gdb/infrun.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/gdb/infrun.c b/gdb/infrun.c index 105862a..11dcc0e 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -3178,6 +3178,16 @@ wait_for_inferior (void) static void reinstall_readline_callback_handler_cleanup (void *arg) { + if (!interpreter_async) + { + /* We're not going back to the top level event loop yet. Don't + install the readline callback, as it'd prep the terminal, + readline-style (raw, noecho) (e.g., --batch). We'll install + it the next time the prompt is displayed, when we're ready + for input. */ + return; + } + if (async_command_editing_p && !sync_execution) gdb_rl_callback_handler_reinstall (); } |