diff options
author | Pedro Alves <palves@redhat.com> | 2016-08-09 22:45:40 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-08-09 22:50:45 +0100 |
commit | 3eb7562a983bab4c768983bcd85708852d171121 (patch) | |
tree | 9ceb489cbd1f48967e11a4a60d1f34d9b57ec007 /gdb/utils.c | |
parent | 80614914274f7166baea2ec656aec6a949869324 (diff) | |
download | gdb-3eb7562a983bab4c768983bcd85708852d171121.zip gdb-3eb7562a983bab4c768983bcd85708852d171121.tar.gz gdb-3eb7562a983bab4c768983bcd85708852d171121.tar.bz2 |
Fix PR gdb/20418 - Problems with synchronous commands and new-ui
When executing commands on a secondary UI running the MI interpreter,
some commands that should be synchronous are not. MI incorrectly
continues processing input right after the synchronous command is
sent, before the target stops.
The problem happens when we emit MI async events (=library-loaded,
etc.), and we go about restoring the previous terminal state, we end
up calling target_terminal_ours, which incorrectly always installs the
current UI's input_fd in the event loop... That is, code like this:
old_chain = make_cleanup_restore_target_terminal ();
target_terminal_ours_for_output ();
fprintf_unfiltered (mi->event_channel, "library-loaded");
...
do_cleanups (old_chain);
The fix is to move the add_file_handler/delete_file_handler calls out
of target_terminal_$foo, making these completely no-ops unless called
with the main UI as current UI.
gdb/ChangeLog:
2016-08-09 Pedro Alves <palves@redhat.com>
PR gdb/20418
* event-top.c (ui_register_input_event_handler)
(ui_unregister_input_event_handler): New functions.
(async_enable_stdin): Register input in the event loop.
(async_disable_stdin): Unregister input from the event loop.
(gdb_setup_readline): Register input in the event loop.
* infrun.c (check_curr_ui_sync_execution_done): Register input in
the event loop.
* target.c (target_terminal_inferior): Don't unregister input from
the event loop.
(target_terminal_ours): Don't register input in the event loop.
* target.h (target_terminal_inferior)
(target_terminal_ours_for_output, target_terminal_ours): Update
comments.
* top.h (ui_register_input_event_handler)
(ui_unregister_input_event_handler): New declarations.
* utils.c (ui_unregister_input_event_handler_cleanup)
(prepare_to_handle_input): New functions.
(defaulted_query, prompt_for_continue): Use
prepare_to_handle_input.
gdb/testsuite/ChangeLog:
2016-08-09 Pedro Alves <palves@redhat.com>
Simon Marchi <simon.marchi@ericsson.com>
PR gdb/20418
* gdb.mi/new-ui-mi-sync.c, gdb.mi/new-ui-mi-sync.exp: New files.
* lib/mi-support.exp (mi_expect_interrupt): Remove anchors.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index c70e99c..5188828 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1209,6 +1209,33 @@ compile_rx_or_error (regex_t *pattern, const char *rx, const char *message) return make_regfree_cleanup (pattern); } +/* A cleanup that simply calls ui_unregister_input_event_handler. */ + +static void +ui_unregister_input_event_handler_cleanup (void *ui) +{ + ui_unregister_input_event_handler ((struct ui *) ui); +} + +/* Set up to handle input. */ + +static struct cleanup * +prepare_to_handle_input (void) +{ + struct cleanup *old_chain; + + old_chain = make_cleanup_restore_target_terminal (); + target_terminal_ours (); + + ui_register_input_event_handler (current_ui); + if (current_ui->prompt_state == PROMPT_BLOCKED) + make_cleanup (ui_unregister_input_event_handler_cleanup, current_ui); + + make_cleanup_override_quit_handler (default_quit_handler); + + return old_chain; +} + /* This function supports the query, nquery, and yquery functions. @@ -1265,8 +1292,6 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) if (!confirm || server_command) return def_value; - old_chain = make_cleanup_restore_target_terminal (); - /* If input isn't coming from the user directly, just say what question we're asking, and then answer the default automatically. This way, important error messages don't get lost when talking to GDB @@ -1274,6 +1299,8 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) if (current_ui->instream != current_ui->stdin_stream || !input_interactive_p (current_ui)) { + old_chain = make_cleanup_restore_target_terminal (); + target_terminal_ours_for_output (); wrap_here (""); vfprintf_filtered (gdb_stdout, ctlstr, args); @@ -1291,6 +1318,7 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) { int res; + old_chain = make_cleanup_restore_target_terminal (); res = deprecated_query_hook (ctlstr, args); do_cleanups (old_chain); return res; @@ -1298,7 +1326,7 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) /* Format the question outside of the loop, to avoid reusing args. */ question = xstrvprintf (ctlstr, args); - make_cleanup (xfree, question); + old_chain = make_cleanup (xfree, question); prompt = xstrprintf (_("%s%s(%s or %s) %s"), annotation_level > 1 ? "\n\032\032pre-query\n" : "", question, y_string, n_string, @@ -1308,9 +1336,7 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) /* Used for calculating time spend waiting for user. */ gettimeofday (&prompt_started, NULL); - /* We'll need to handle input. */ - target_terminal_ours (); - make_cleanup_override_quit_handler (default_quit_handler); + prepare_to_handle_input (); while (1) { @@ -1882,10 +1908,7 @@ prompt_for_continue (void) beyond the end of the screen. */ reinitialize_more_filter (); - /* We'll need to handle input. */ - make_cleanup_restore_target_terminal (); - target_terminal_ours (); - make_cleanup_override_quit_handler (default_quit_handler); + prepare_to_handle_input (); /* Call gdb_readline_wrapper, not readline, in order to keep an event loop running. */ |