diff options
author | Pedro Alves <palves@redhat.com> | 2016-06-21 01:11:51 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-06-21 01:11:51 +0100 |
commit | 3b12939dfc2399200f243851fd55d0e392b64165 (patch) | |
tree | fdf4224894c12434bb05d438874f1951d1539d4c /gdb/mi | |
parent | Make gdb_in_secondary_prompt_p() be per UI (diff) | |
download | binutils-gdb-3b12939dfc2399200f243851fd55d0e392b64165.tar.gz binutils-gdb-3b12939dfc2399200f243851fd55d0e392b64165.tar.bz2 binutils-gdb-3b12939dfc2399200f243851fd55d0e392b64165.zip |
Replace the sync_execution global with a new enum prompt_state tristate
When sync_execution (a boolean) is true, it means we're running a
foreground command -- we hide the prompt stop listening to input, give
the inferior the terminal, then go to the event loop waiting for the
target to stop.
With multiple independent UIs, we need to track whether each UI is
synchronously blocked waiting for the target. IOW, if you do
"continue" in one console, that console stops accepting commands, but
you should still be free to type other commands in the others
consoles.
Just simply making sync_execution be per-UI alone not sufficient,
because of this in fetch_inferior_event:
/* If the inferior was in sync execution mode, and now isn't,
restore the prompt (a synchronous execution command has finished,
and we're ready for input). */
if (current_ui->async && was_sync && !sync_execution)
observer_notify_sync_execution_done ();
We'd have to record at entry the "was_sync" state for each UI, not
just of the current UI.
This patch instead replaces the sync_execution flag by a per-UI
tristate flag indicating the command line prompt state:
enum prompt_state
{
/* The command line is blocked simulating synchronous execution.
This is used to implement the foreground execution commands
('run', 'continue', etc.). We won't display the prompt and
accept further commands until the execution is actually over. */
PROMPT_BLOCKED,
/* The command finished; display the prompt before returning back to
the top level. */
PROMPT_NEEDED,
/* We've displayed the prompt already, ready for input. */
PROMPTED,
;
I think the end result is _much_ clearer than the current code, and,
it addresses the original motivation too.
gdb/ChangeLog:
2016-06-21 Pedro Alves <palves@redhat.com>
* annotate.c: Include top.h.
(async_background_execution_p): Delete.
(print_value_flags): Check the UI's prompt state rather then
async_background_execution_p.
* event-loop.c (start_event_loop): Set the prompt state to
PROMPT_NEEDED.
* event-top.c (display_gdb_prompt, async_enable_stdin)
(async_disable_stdin): Check the current UI's prompt state instead
of the sync_execution global.
(command_line_handler): Set the prompt state to PROMPT_NEEDED
before running a command, and display the prompt if still needed
afterwards.
* infcall.c (struct call_thread_fsm) <waiting_ui>: New field.
(new_call_thread_fsm): New parameter 'waiting_ui'. Store it.
(call_thread_fsm_should_stop): Set the prompt state to
PROMPT_NEEDED.
(run_inferior_call): Adjust to temporarily set the prompt state to
PROMPT_BLOCKED instead of using the sync_execution global.
(call_function_by_hand_dummy): Pass the current UI to
new_call_thread_fsm.
* infcmd.c: Include top.h.
(continue_1): Check the current UI's prompt state instead of the
sync_execution global.
(continue_command): Validate global execution state before calling
prepare_execution_command.
(step_1): Call all_uis_check_sync_execution_done.
(attach_post_wait): Don't call async_enable_stdin here. Remove
reference to sync_execution.
* infrun.c (sync_execution): Delete global.
(follow_fork_inferior)
(reinstall_readline_callback_handler_cleanup): Check the current
UI's prompt state instead of the sync_execution global.
(check_curr_ui_sync_execution_done)
(all_uis_check_sync_execution_done): New functions.
(fetch_inferior_event): Call all_uis_check_sync_execution_done
instead of trying to determine whether the global sync execution
changed.
(handle_no_resumed): Check the prompt state of all UIs.
(normal_stop): Emit the no unwait-for even to all PROMPT_BLOCKED
UIs. Emit the "Switching to" notification to all UIs. Enable
stdin in all UIs.
* infrun.h (sync_execution): Delete.
(all_uis_check_sync_execution_done): Declare.
* main.c (captured_command_loop): Don't call
interp_pre_command_loop if the prompt is blocked.
(catch_command_errors, catch_command_errors_const): Adjust.
(captured_main): Set the initial prompt state to PROMPT_NEEDED.
* mi/mi-interp.c (display_mi_prompt): Set the prompt state to
PROMPTED.
(mi_interpreter_resume): Don't clear sync_execution. Remove hack
comment.
(mi_execute_command_input_handler): Set the prompt state to
PROMPT_NEEDED before executing the command, and only display the
prompt if the prompt state is PROMPT_NEEDED afterwards.
(mi_on_resume_1): Adjust to check the prompt state.
* target.c (target_terminal_inferior): Adjust to check the prompt
state.
* top.c (wait_sync_command_done, maybe_wait_sync_command_done)
(execute_command): Check the current UI's prompt state instead of
sync_execution.
* top.h (enum prompt_state): New.
(struct ui) <prompt_state>: New field.
(ALL_UIS): New macro.
Diffstat (limited to 'gdb/mi')
-rw-r--r-- | gdb/mi/mi-interp.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index 4376ffa06a8..5db61e14f1f 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -93,8 +93,11 @@ static int report_initial_inferior (struct inferior *inf, void *closure); static void display_mi_prompt (struct mi_interp *mi) { + struct ui *ui = current_ui; + fputs_unfiltered ("(gdb) \n", mi->raw_stdout); gdb_flush (mi->raw_stdout); + ui->prompt_state = PROMPTED; } /* Returns the INTERP's data cast as mi_interp if INTERP is an MI, and @@ -169,13 +172,6 @@ mi_interpreter_resume (void *data) ui->call_readline = gdb_readline_no_editing_callback; ui->input_handler = mi_execute_command_input_handler; - /* FIXME: This is a total hack for now. PB's use of the MI - implicitly relies on a bug in the async support which allows - asynchronous commands to leak through the commmand loop. The bug - involves (but is not limited to) the fact that sync_execution was - erroneously initialized to 0. Duplicate by initializing it thus - here... */ - sync_execution = 0; gdb_stdout = mi->out; /* Route error and log output through the MI. */ @@ -315,6 +311,9 @@ static void mi_execute_command_input_handler (char *cmd) { struct mi_interp *mi = as_mi_interp (top_level_interpreter ()); + struct ui *ui = current_ui; + + ui->prompt_state = PROMPT_NEEDED; mi_execute_command_wrapper (cmd); @@ -323,7 +322,7 @@ mi_execute_command_input_handler (char *cmd) to go back to the event loop and will output the prompt in the 'synchronous_command_done' observer when the target next stops. */ - if (!sync_execution) + if (ui->prompt_state == PROMPT_NEEDED) display_mi_prompt (mi); } @@ -1139,12 +1138,10 @@ mi_on_resume_1 (struct mi_interp *mi, ptid_t ptid) if (!running_result_record_printed && mi_proceeded) { running_result_record_printed = 1; - /* This is what gdb used to do historically -- printing prompt even if - it cannot actually accept any input. This will be surely removed - for MI3, and may be removed even earlier. SYNC_EXECUTION is - checked here because we only need to emit a prompt if a - synchronous command was issued when the target is async. */ - if (!target_can_async_p () || sync_execution) + /* This is what gdb used to do historically -- printing prompt + even if it cannot actually accept any input. This will be + surely removed for MI3, and may be removed even earlier. */ + if (current_ui->prompt_state == PROMPT_BLOCKED) fputs_unfiltered ("(gdb) \n", mi->raw_stdout); } gdb_flush (mi->raw_stdout); |