From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v3 10/34] Make input_fd be per UI
Date: Fri, 06 May 2016 12:43:00 -0000 [thread overview]
Message-ID: <1462538104-19109-11-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1462538104-19109-1-git-send-email-palves@redhat.com>
And with that, we can switch the current UI to the UI whose input
descriptor woke up the event loop. IOW, if the user types in UI 2,
the event loop wakes up, switches to UI 2, and processes the input.
Next the user types in UI 3, the event loop wakes up and switches to
UI 3, etc.
gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* event-top.c (input_fd): Delete.
(stdin_event_handler): Switch to the UI whose input descriptor got
the event. Adjust to per-UI input_fd.
(gdb_setup_readline): Don't set the input_fd global. Adjust to
per-UI input_fd.
(gdb_disable_readline): Adjust to per-UI input_fd.
* event-top.h (input_fd): Delete declaration.
* linux-nat.c (linux_nat_terminal_inferior): Don't remove input_fd
from the event-loop here.
(linux_nat_terminal_ours): Don't register input_fd in the
event-loop here.
* main.c (captured_main): Adjust to per-UI input_fd.
* remote.c (remote_terminal_inferior): Don't remove input_fd from
the event-loop here.
(remote_terminal_ours): Don't register input_fd in the event-loop
here.
* target.c: Include top.h and event-top.h.
(target_terminal_inferior): Remove input_fd from the event-loop
here.
(target_terminal_ours): Register input_fd in the event-loop.
* top.h (struct ui) <input_fd>: New field.
---
gdb/event-top.c | 33 ++++++++++++++-------------------
gdb/event-top.h | 1 -
gdb/linux-nat.c | 2 --
gdb/main.c | 1 +
gdb/remote.c | 2 --
gdb/target.c | 16 ++++++++++++++++
gdb/top.h | 4 ++++
7 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 3e2f778..1d36b81 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -94,10 +94,6 @@ int async_command_editing_p;
asynchronous execution command. */
int exec_done_display_p = 0;
-/* This is the file descriptor for the input stream that GDB uses to
- read commands from. */
-int input_fd;
-
/* Used by the stdin event handler to compensate for missed stdin events.
Setting this to a non-zero value inside an stdin callback makes the callback
run again. */
@@ -503,12 +499,16 @@ get_command_line_buffer (void)
void
stdin_event_handler (int error, gdb_client_data client_data)
{
- struct ui *ui = current_ui;
+ struct ui *ui = (struct ui *) client_data;
+
+ /* Switch to the UI whose input descriptor woke up the event
+ loop. */
+ current_ui = ui;
if (error)
{
printf_unfiltered (_("error detected on stdin\n"));
- delete_file_handler (input_fd);
+ delete_file_handler (ui->input_fd);
/* If stdin died, we may as well kill gdb. */
quit_command ((char *) 0, stdin == ui->instream);
}
@@ -1270,18 +1270,11 @@ gdb_setup_readline (void)
/* Tell readline to use the same input stream that gdb uses. */
rl_instream = ui->instream;
- /* Get a file descriptor for the input stream, so that we can
- register it with the event loop. */
- input_fd = fileno (ui->instream);
-
- /* Now we need to create the event sources for the input file
- descriptor. */
- /* At this point in time, this is the only event source that we
- register with the even loop. Another source is going to be the
- target program (inferior), but that must be registered only when
- it actually exists (I.e. after we say 'run' or after we connect
- to a remote target. */
- add_file_handler (input_fd, stdin_event_handler, 0);
+ /* Now create the event source for this UI's input file descriptor.
+ Another source is going to be the target program (inferior), but
+ that must be registered only when it actually exists (I.e. after
+ we say 'run' or after we connect to a remote target. */
+ add_file_handler (ui->input_fd, stdin_event_handler, ui);
}
/* Disable command input through the standard CLI channels. Used in
@@ -1290,6 +1283,8 @@ gdb_setup_readline (void)
void
gdb_disable_readline (void)
{
+ struct ui *ui = current_ui;
+
/* FIXME - It is too heavyweight to delete and remake these every
time you run an interpreter that needs readline. It is probably
better to have the interpreters cache these, which in turn means
@@ -1304,5 +1299,5 @@ gdb_disable_readline (void)
#endif
gdb_rl_callback_handler_remove ();
- delete_file_handler (input_fd);
+ delete_file_handler (ui->input_fd);
}
diff --git a/gdb/event-top.h b/gdb/event-top.h
index 04956a5..4fe7737 100644
--- a/gdb/event-top.h
+++ b/gdb/event-top.h
@@ -57,7 +57,6 @@ extern void async_enable_stdin (void);
extern int async_command_editing_p;
extern int exec_done_display_p;
extern struct prompts the_prompts;
-extern int input_fd;
extern void (*after_char_processing_hook) (void);
extern int call_stdin_event_handler_again_p;
extern void gdb_readline_no_editing_callback (void *client_data);
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index b75153c..451df6c 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -4287,7 +4287,6 @@ linux_nat_terminal_inferior (struct target_ops *self)
if (!async_terminal_is_ours)
return;
- delete_file_handler (input_fd);
async_terminal_is_ours = 0;
set_sigint_trap ();
}
@@ -4313,7 +4312,6 @@ linux_nat_terminal_ours (struct target_ops *self)
return;
clear_sigint_trap ();
- add_file_handler (input_fd, stdin_event_handler, 0);
async_terminal_is_ours = 1;
}
diff --git a/gdb/main.c b/gdb/main.c
index 7d7b52a..d862759 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -508,6 +508,7 @@ captured_main (void *data)
saved_command_line = (char *) xstrdup ("");
ui->instream = stdin;
+ ui->input_fd = fileno (stdin);
#ifdef __MINGW32__
/* Ensure stderr is unbuffered. A Cygwin pty or pipe is implemented
diff --git a/gdb/remote.c b/gdb/remote.c
index 1f0d67c..501f3c6 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -5924,7 +5924,6 @@ remote_terminal_inferior (struct target_ops *self)
can go away. */
if (!remote_async_terminal_ours_p)
return;
- delete_file_handler (input_fd);
remote_async_terminal_ours_p = 0;
/* NOTE: At this point we could also register our selves as the
recipient of all input. Any characters typed could then be
@@ -5937,7 +5936,6 @@ remote_terminal_ours (struct target_ops *self)
/* See FIXME in remote_terminal_inferior. */
if (remote_async_terminal_ours_p)
return;
- add_file_handler (input_fd, stdin_event_handler, 0);
remote_async_terminal_ours_p = 1;
}
diff --git a/gdb/target.c b/gdb/target.c
index a9744c4..2d16c96 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -43,6 +43,8 @@
#include "agent.h"
#include "auxv.h"
#include "target-debug.h"
+#include "top.h"
+#include "event-top.h"
static void target_info (char *, int);
@@ -477,6 +479,8 @@ target_terminal_is_ours (void)
void
target_terminal_inferior (void)
{
+ struct ui *ui = current_ui;
+
/* A background resume (``run&'') should leave GDB in control of the
terminal. Use target_can_async_p, not target_is_async_p, since at
this point the target is not async yet. However, if sync_execution
@@ -484,6 +488,11 @@ target_terminal_inferior (void)
if (target_can_async_p () && !sync_execution)
return;
+ /* Always delete the current UI's input file handler, regardless of
+ terminal_state, because terminal_state is only valid for the main
+ UI. */
+ delete_file_handler (ui->input_fd);
+
if (terminal_state == terminal_is_inferior)
return;
@@ -503,6 +512,13 @@ target_terminal_inferior (void)
void
target_terminal_ours (void)
{
+ struct ui *ui = current_ui;
+
+ /* Always add the current UI's input file handler, regardless of
+ terminal_state, because terminal_state is only valid for the main
+ UI. */
+ add_file_handler (ui->input_fd, stdin_event_handler, ui);
+
if (terminal_state == terminal_is_ours)
return;
diff --git a/gdb/top.h b/gdb/top.h
index bb84097..c50c0c9 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -74,6 +74,10 @@ struct ui
interacting via a GUI. */
FILE *instream;
+ /* The file descriptor for the input stream, so that we can register
+ it with the event loop. */
+ int input_fd;
+
/* The fields below that start with "m_" are "private". They're
meant to be accessed through wrapper macros that make them look
like globals. */
--
2.5.5
next prev parent reply other threads:[~2016-05-06 12:43 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-06 12:35 [PATCH v3 00/34] Towards great frontend GDB consoles Pedro Alves
2016-05-06 12:35 ` [PATCH v3 14/34] Make command line editing (use of readline) be per UI Pedro Alves
2016-05-06 12:35 ` [PATCH v3 21/34] Replace the sync_execution global with a new enum prompt_state tristate Pedro Alves
2016-05-06 12:35 ` [PATCH v3 20/34] Make gdb_in_secondary_prompt_p() be per UI Pedro Alves
2016-05-06 12:35 ` [PATCH v3 02/34] [Ada catchpoints] Fix "warning: failed to get exception name: No definition of \"e.full_name\" in current context" Pedro Alves
2016-05-06 12:35 ` [PATCH v3 33/34] Make mi-break.exp always expect breakpoint commands output on the main UI Pedro Alves
2016-05-06 12:35 ` [PATCH v3 29/34] Add new command to create extra console/mi UI channels Pedro Alves
2016-05-26 18:34 ` Pedro Alves
2016-05-06 12:35 ` [PATCH v3 24/34] Push thread->control.command_interp to the struct thread_fsm Pedro Alves
2016-07-01 11:02 ` Thomas Preudhomme
[not found] ` <20144b4c-11ee-fc84-e3ad-b9992f14ce15@redhat.com>
2016-07-01 15:24 ` [PATCH] Build gdb.opt/inline-*.exp tests at -O0, rely on __attribute__((always_inline)) (was: Re: [PATCH v3 24/34] Push thread->control.command_interp to the struct thread_fsm) Thomas Preudhomme
2016-07-15 12:05 ` Thomas Preudhomme
2016-07-19 17:02 ` [PATCH] Build gdb.opt/inline-*.exp tests at -O0, rely on __attribute__((always_inline)) Pedro Alves
2016-07-20 16:35 ` Thomas Preudhomme
2016-05-06 12:35 ` [PATCH v3 16/34] Make target_terminal_inferior/ours almost nops on non-main UIs Pedro Alves
2016-05-06 12:35 ` [PATCH v3 15/34] Always process target events in the main UI Pedro Alves
2016-05-06 12:35 ` [PATCH v3 03/34] Introduce "struct ui" Pedro Alves
2016-05-06 12:35 ` [PATCH v3 01/34] Prepare gdb.python/mi-py-events.exp for Python/MI in separate channels Pedro Alves
2016-05-06 12:36 ` [PATCH v3 31/34] Add testing infrastruture bits for running with MI on a separate UI Pedro Alves
2016-06-28 20:19 ` Simon Marchi
2016-06-29 10:50 ` Pedro Alves
2016-06-30 11:12 ` [pushed] Fix gdbserver/MI testing regression (was: Re: [PATCH v3 31/34] Add testing infrastruture bits for running with MI on a separate UI) Pedro Alves
2016-06-30 12:10 ` gdbserver/ada testing broken (was: Re: [pushed] Fix gdbserver/MI testing regression) Pedro Alves
2016-07-04 20:40 ` gdbserver/ada testing broken Simon Marchi
2016-07-05 15:28 ` Joel Brobecker
2016-07-05 15:47 ` Joel Brobecker
2016-07-05 16:36 ` gdbserver/ada testing broken (was: Re: [pushed] Fix gdbserver/MI testing regression) Joel Brobecker
2016-07-05 17:19 ` gdbserver/ada testing broken Simon Marchi
2016-07-06 13:23 ` Joel Brobecker
2016-07-06 14:28 ` Simon Marchi
2016-07-19 17:11 ` Pedro Alves
2016-07-04 17:22 ` [pushed] Fix gdbserver/MI testing regression Simon Marchi
2016-05-06 12:40 ` [PATCH v3 11/34] Make out and error streams be per UI Pedro Alves
2016-05-06 12:40 ` [PATCH v3 23/34] New function should_print_stop_to_console Pedro Alves
2016-05-06 12:40 ` [PATCH v3 13/34] Make current_ui_out be per UI Pedro Alves
2016-05-06 12:41 ` [PATCH v3 06/34] Introduce interpreter factories Pedro Alves
2016-05-18 19:18 ` Simon Marchi
2016-05-26 18:11 ` Pedro Alves
2016-05-18 19:20 ` Simon Marchi
2016-05-26 18:08 ` Pedro Alves
2016-05-06 12:42 ` [PATCH v3 30/34] [DOC] Document support for running interpreters on separate UI channels Pedro Alves
2016-05-06 13:04 ` Eli Zaretskii
2016-05-26 11:11 ` Pedro Alves
2016-06-17 17:24 ` Pedro Alves
2016-06-17 20:02 ` Eli Zaretskii
2016-05-06 12:43 ` [PATCH v3 07/34] Make the intepreters output to all UIs Pedro Alves
2016-05-19 15:16 ` Simon Marchi
2016-05-26 18:12 ` Pedro Alves
2016-05-06 12:43 ` [PATCH v3 08/34] Always run async signal handlers in the main UI Pedro Alves
2016-05-19 19:28 ` Simon Marchi
2016-05-26 18:13 ` Pedro Alves
2016-05-26 18:15 ` Simon Marchi
2016-05-06 12:43 ` [PATCH v3 25/34] Only send sync execution command output to the UI that ran the command Pedro Alves
2016-05-06 12:43 ` [PATCH v3 28/34] Make stdin be per UI Pedro Alves
2016-05-06 12:43 ` [PATCH v3 12/34] Delete def_uiout Pedro Alves
2016-05-06 12:43 ` [PATCH v3 04/34] Make gdb_stdout&co be per UI Pedro Alves
2016-05-06 12:43 ` [PATCH v3 17/34] Introduce display_mi_prompt Pedro Alves
2016-05-06 12:43 ` [PATCH v3 05/34] Make the interpreters be per UI Pedro Alves
2016-05-18 17:51 ` Simon Marchi
2016-05-26 18:08 ` Pedro Alves
2016-05-06 12:43 ` Pedro Alves [this message]
2016-05-06 12:45 ` [PATCH v3 22/34] Fix for spurious prompts in secondary UIs Pedro Alves
2016-05-06 12:45 ` [PATCH v3 27/34] Handle UI's terminal closing Pedro Alves
2016-05-06 12:45 ` [PATCH v3 26/34] Make main_ui be heap allocated Pedro Alves
2016-05-06 12:45 ` [PATCH v3 34/34] Always switch fork child to the main UI Pedro Alves
2016-05-06 12:45 ` [PATCH v3 32/34] Send deleted watchpoint-scope output to all UIs Pedro Alves
2016-05-06 12:52 ` [PATCH v3 18/34] Make raw_stdout be per MI instance Pedro Alves
2016-05-06 12:53 ` [PATCH v3 09/34] Make instream be per UI Pedro Alves
2016-05-06 12:53 ` [PATCH v3 19/34] Simplify starting the command event loop Pedro Alves
2016-05-26 18:37 ` [PATCH v3 35/34] Add "new-ui console" tests Pedro Alves
2016-06-21 0:23 ` [pushed] Re: [PATCH v3 00/34] Towards great frontend GDB consoles Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1462538104-19109-11-git-send-email-palves@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox