From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 61F2C3858D28 for ; Tue, 22 Aug 2023 15:43:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61F2C3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYTXd-0000jR-8g; Tue, 22 Aug 2023 11:43:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=XMTsWzk/A8xTtrxB5Ncd0nGhJzrBeto5jB+snEtCiiA=; b=TqyKXNPTH0uk JLq8/w7Kqd3/ttkVknA4y6GkmyVqqXLtD5yWsXRE0qtvC999QTgSvdMY4oRXDjH0jbkrirQTsWF/p v1Ik+P5J0LYkmnrVHUnOmEl0g3IkQspzROIaIBPqBJg3EMdbDiK+ub7i8Ng87xTgYOSVnwZOOJLiA y0i7cjs2m8yyQtXB+WNyc/ZSp3/JskdqjRUh+rnu4kUpdcT0asKoy0lHdCZ4pxKLLo8gg+peXCAXa e5htq7ItusuIhQWW1xS3iOX8/ACVf7IoR8oYTxJiJzmoEsJ+ON0+AvgK81vwJTF8rZ6OXqpix587d T6R0fnRBFbIRkz6Y2gPWIg==; Date: Tue, 22 Aug 2023 18:43:57 +0300 Message-Id: <83wmxnrsjm.fsf@gnu.org> From: Eli Zaretskii To: Pedro Alves Cc: gdb-patches@sourceware.org In-Reply-To: <20230822151332.4010554-1-pedro@palves.net> (message from Pedro Alves on Tue, 22 Aug 2023 16:13:32 +0100) Subject: Re: [PATCH] Fix Windows sharing_input_terminal hang References: <20230822151332.4010554-1-pedro@palves.net> X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > From: Pedro Alves > 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