Skip to content

Commit

Permalink
Fix Windows sharing_input_terminal hang
Browse files Browse the repository at this point in the history
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
 loongson#1  0x00007ff71a2d8678 in sharing_input_terminal (inf=0x23bf23dafb0) at /home/pedro/gdb/src/gdb/inflow.c:269
 loongson#2  0x00007ff71a2d887b in child_terminal_save_inferior (self=0x23bf23de060) at /home/pedro/gdb/src/gdb/inflow.c:423
 loongson#3  0x00007ff71a2c80c0 in inf_child_target::terminal_save_inferior (this=0x23bf23de060) at /home/pedro/gdb/src/gdb/inf-child.c:111
 loongson#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
 loongson#5  0x00007ff71a429e02 in target_terminal::ours_for_output () at /home/pedro/gdb/src/gdb/target.c:1094
 loongson#6  0x00007ff71a2ccc8e in post_create_inferior (from_tty=0) at /home/pedro/gdb/src/gdb/infcmd.c:245
 loongson#7  0x00007ff71a2cd431 in run_command_1 (args=0x0, from_tty=0, run_how=RUN_NORMAL) at /home/pedro/gdb/src/gdb/infcmd.c:502
 loongson#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 "<=".  That is fixed by this patch.

Approved-By: Tom Tromey <[email protected]>
Reviewed-By: Eli Zaretskii <[email protected]>
Change-Id: I14e4909f2ac2fa83d0d9b6e64418b5831ac4e4e3
  • Loading branch information
palves committed Aug 23, 2023
1 parent cdb090c commit 2c9d782
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion gdb/mingw-hdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ sharing_input_terminal (int pid)
len = GetConsoleProcessList (results.data (), results.size ());
/* Note that LEN == 0 is a failure, but we can treat it the same
as a "no". */
if (len < results.size ())
if (len <= results.size ())
break;

results.resize (len);
Expand Down

0 comments on commit 2c9d782

Please sign in to comment.