Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Eli Zaretskii via Gdb-patches <gdb-patches@sourceware.org>
To: Roy Qu <royqh1979@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: the redirected stdin/out/err for new console is wrong when the gdb's stdin/out/err is already redirected
Date: Fri, 02 Oct 2020 15:17:06 +0300	[thread overview]
Message-ID: <83blhkg6v1.fsf@gnu.org> (raw)
In-Reply-To: <CAKjWZNWC3ZsR-D8ZPMS5qdhBg5WeWv0p=D9ncdAQua9aKYbSMg@mail.gmail.com> (message from Roy Qu on Tue, 29 Sep 2020 07:48:18 +0800)

[Please use Reply All to reply, so that the list is CC'ed.]

> From: Roy Qu <royqh1979@gmail.com>
> Date: Tue, 29 Sep 2020 07:48:18 +0800
> 
> Yes, (HANLDE)0 is the same as NULL. 
> 
> These code will get running when we want to run/start the inferior  and at least one of inferior's
> STDIN/STDOUT/STDERR is to be redirected.  
>    si.hStdInput / si.hStdOutput/ si.hStdError are the handle for STDIN/STDOUT/STDERR you want the child
> process ( console window) to use.    
> 
> Let's the following old code for the STDOUT:
> 
>       if (fd_out >= 0)
> si.hStdOutput = (HANDLE) _get_osfhandle (fd_out);
>       else if (tty != INVALID_HANDLE_VALUE)
> si.hStdOutput = tty;
>       else
> si.hStdOutput =  GetStdHandle (STD_OUTPUT_HANDLE)  ;
> 
> If the inferior process's STDOUT is to be redirected,  fd_out will be a valid file_descriptor (>0) to the
> redirected source, and  _get_osfhandle will
> get its corresponding windows handle.
> If the STDOUT is not to be redirected (else if)   , tty is from get_inferior_io_terminal(), which should the
> inferior's current  tty's handle; (I'm not sure
> if here is correct, because STDIN/STDOUT/STDERR should be 3 HANDLEs, but here we use the same
> one)
> If the STDOUT is not to be redirected and we don't have a valid tty already (else ), then we should let the
> inferior use new console STDOUT ( output to the screen).
> 
> But here the following old code is wrong:
> si.hStdOutput =  GetStdHandle (STD_OUTPUT_HANDLE)  ; 
> It tries to fetch the main gdb's currrent STDOUT handle and let the inferior to use it. If the main gdb's
> STDOUT is not redirected, that's ok.
> If the main gdb's STDOUT is already redirected, this will get the inferior's STDOUT redirected too, that's
> wrong.
> 
> the new code:
>   si.hStdOutput = NULL;
> will let inferior's STDOUT use the console's default output handle (output to its console's screen). That's
> what we want.
> 
> Logic of the code for STDIN/STDERR is the same.That's ALL

Thanks.

My hesitation is that I don't see the significance of NULL as the
standard handle documented in the MS docs of CreateProcess.  What am I
missing there?

Another potential issue is whether, when GDB's standard output was
redirected, we might want stdout of the inferior to be redirected to
the same file/device.  In your case, that is definitely not so, but I
wonder if there are other use cases where the desired behavior could
be different?  Running the test suite, perhaps?

  parent reply	other threads:[~2020-10-02 12:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-28 12:21 Roy Qu via Gdb-patches
2020-09-28 12:40 ` Eli Zaretskii via Gdb-patches
     [not found]   ` <CAKjWZNWC3ZsR-D8ZPMS5qdhBg5WeWv0p=D9ncdAQua9aKYbSMg@mail.gmail.com>
2020-10-02 12:17     ` Eli Zaretskii via Gdb-patches [this message]
     [not found]       ` <CAKjWZNXxSfSKEcXMfK4P4NJtWtaP0t84k5W1VUEDqX5ofXLa6A@mail.gmail.com>
2020-10-02 14:49         ` Eli Zaretskii via Gdb-patches
     [not found]           ` <CAKjWZNXKFTKV7SsN066+bY-ocB32EC1gSSwbKO_Nqu9Dj8qzbQ@mail.gmail.com>
2020-10-02 19:50             ` Eli Zaretskii via Gdb-patches
2020-10-06 13:13               ` Roy Qu via Gdb-patches

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=83blhkg6v1.fsf@gnu.org \
    --to=gdb-patches@sourceware.org \
    --cc=eliz@gnu.org \
    --cc=royqh1979@gmail.com \
    /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