public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Pedro Alves <pedro@palves.net>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix Windows sharing_input_terminal hang
Date: Tue, 22 Aug 2023 18:43:57 +0300	[thread overview]
Message-ID: <83wmxnrsjm.fsf@gnu.org> (raw)
In-Reply-To: <20230822151332.4010554-1-pedro@palves.net> (message from Pedro Alves on Tue, 22 Aug 2023 16:13:32 +0100)

> From: Pedro Alves <pedro@palves.net>
> Date: Tue, 22 Aug 2023 16:13:32 +0100
> 
> After running a number of programs under Windows gdb and detaching
> them, I typed run in gdb, and got a hang, here:
> 
>  (top-gdb) bt
>  #0  sharing_input_terminal (pid=4672) at /home/pedro/gdb/src/gdb/mingw-hdep.c:388
>  #1  0x00007ff71a2d8678 in sharing_input_terminal (inf=0x23bf23dafb0) at /home/pedro/gdb/src/gdb/inflow.c:269
>  #2  0x00007ff71a2d887b in child_terminal_save_inferior (self=0x23bf23de060) at /home/pedro/gdb/src/gdb/inflow.c:423
>  #3  0x00007ff71a2c80c0 in inf_child_target::terminal_save_inferior (this=0x23bf23de060) at /home/pedro/gdb/src/gdb/inf-child.c:111
>  #4  0x00007ff71a429c0f in target_terminal_is_ours_kind (desired_state=target_terminal_state::is_ours_for_output) at /home/pedro/gdb/src/gdb/target.c:1037
>  #5  0x00007ff71a429e02 in target_terminal::ours_for_output () at /home/pedro/gdb/src/gdb/target.c:1094
>  #6  0x00007ff71a2ccc8e in post_create_inferior (from_tty=0) at /home/pedro/gdb/src/gdb/infcmd.c:245
>  #7  0x00007ff71a2cd431 in run_command_1 (args=0x0, from_tty=0, run_how=RUN_NORMAL) at /home/pedro/gdb/src/gdb/infcmd.c:502
>  #8  0x00007ff71a2cd58b in run_command (args=0x0, from_tty=0) at /home/pedro/gdb/src/gdb/infcmd.c:527
> 
> The problem is that the loop around GetConsoleProcessList looped
> forever, because there were exactly 10 processes to return.
> GetConsoleProcessList's documentation says:
> 
>   If the buffer is too small to hold all the valid process identifiers,
>   the return value is the required number of array elements. The
>   function will have stored no identifiers in the buffer. In this
>   situation, use the return value to allocate a buffer that is large
>   enough to store the entire list and call the function again.
> 
> In this case, the buffer wasn't too small, it was exactly the right
> size, so we should have broken out of the loop.  We didn't due to a
> "<" check that should have been "<=".

Such a lucky hang... ;-)

> That is fixed by this patch.

Thanks, LGTM.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>

      parent reply	other threads:[~2023-08-22 15:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22 15:13 Pedro Alves
2023-08-22 15:39 ` Tom Tromey
2023-08-22 15:43 ` Eli Zaretskii [this message]

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=83wmxnrsjm.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).