This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Fix "attach" command vs user input race [Re: Regression for attach from stdin [Re: [pushed] Re: [PATCH v6 0/2] enable target-async by default]]
- From: Doug Evans <dje at google dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: Mark Wielaard <mjw at redhat dot com>, Jan Kratochvil <jan dot kratochvil at redhat dot com>, gdb-patches at sourceware dot org
- Date: Mon, 7 Jul 2014 09:39:16 -0700
- Subject: Re: [PATCH] Fix "attach" command vs user input race [Re: Regression for attach from stdin [Re: [pushed] Re: [PATCH v6 0/2] enable target-async by default]]
- Authentication-results: sourceware.org; auth=none
- References: <1400878753-24688-1-git-send-email-palves at redhat dot com> <538739A2 dot 2050105 at redhat dot com> <20140701162830 dot GA25877 at host2 dot jankratochvil dot net> <1404291574 dot 3766 dot 35 dot camel at bordewijk dot wildebeest dot org> <53B3CDCC dot 9050502 at redhat dot com> <53B57911 dot 10304 at redhat dot com> <53B6B0B8 dot 2050702 at redhat dot com>
Pedro Alves writes:
> gdb/
> 2014-07-04 Pedro Alves <palves@redhat.com>
>
> * infcmd.c (attach_command_post_wait): Don't call
> target_terminal_inferior here.
> (attach_command): Call it here instead.
> [...]
> diff --git a/gdb/infcmd.c b/gdb/infcmd.c
> index c4bb401..76ab12b 100644
> --- a/gdb/infcmd.c
> +++ b/gdb/infcmd.c
> @@ -2381,9 +2381,6 @@ attach_command_post_wait (char *args, int from_tty, int async_exec)
>
> post_create_inferior (¤t_target, from_tty);
>
> - /* Install inferior's terminal modes. */
> - target_terminal_inferior ();
> -
> if (async_exec)
> {
> /* The user requested an `attach&', so be sure to leave threads
> @@ -2495,9 +2492,11 @@ attach_command (char *args, int from_tty)
> shouldn't refer to attach_target again. */
> attach_target = NULL;
>
> - /* Set up the "saved terminal modes" of the inferior
> - based on what modes we are starting it with. */
> + /* Set up the "saved terminal modes" of the inferior based on what
> + modes we are starting it with, and remove stdin from the event
> + loop. */
> target_terminal_init ();
> + target_terminal_inferior ();
>
> /* Set up execution context to know that we should return from
> wait_for_inferior as soon as the target reports a stop. */
Our nomenclature here is problematic. I always do a double take when
I see attach and target_terminal_foo mentioned in the same sentence.
Bleah.
For the case at hand, and at least until we have something more
readable, can I ask for a slight change here?
target_terminal_inferior can do a lot more than just "remove stdin
from the event loop", thus as a reader I'm left being unsure
if there aren't still more bugs here.
Plus, while I can see how to map the comment to the code in the patch,
"Set up the "saved terminal modes" of the inferior based on what
modes we are starting it with"
-->
target_terminal_init ();
and
"remove stdin from the event loop"
-->
target_terminal_inferior ();
If I look at the result after the patch,
combining the two steps into one sentence doesn't help clarify
things given that target_terminal_inferior can do more than just
"remove stdin from the event loop".
E.g., this is a marginal improvement:
/* Set up the "saved terminal modes" of the inferior based on what
modes we are starting it with. */
target_terminal_init ();
/* And remove stdin from the event loop. */
target_terminal_inferior ();
But I'm hoping for more text in the second comment to explain things
better.