From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by sourceware.org (Postfix) with ESMTPS id 51A233858D28 for ; Tue, 22 Aug 2023 15:13:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51A233858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-3feef504ccbso23438765e9.2 for ; Tue, 22 Aug 2023 08:13:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692717214; x=1693322014; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dBTnG9YWGFzNxp9fhgNUeIhqrtHmafX2fulPuKD8WyM=; b=U3NANK6yp8mycIsyg78uVd5qW/09MihJXax+1HXzKMoJx3N2WUPNlAQgXPo8Dgy98w EMS4vtRS2v9BHAwnegb3VRO61PyUU1vqWxaVWhxby/mYW4LVDS35AbTTlWsFxrKEUrcG nyQTjOQppGM/b4mpfpgx/cmPKE+y3PArtryEZmL8D9Dbypq54vLfG0ACSQ1sBYARggf3 5HKM1fnJKJ7w9IKNFIG5JzyNulSuIFdqXx+aZmzfVIHuWpzLDJJna3HJL2Lh9MzTLWQ7 5biqtX1r96B/HQKTmZdEbzu08a+CBq//DxMhORGaWJDh8q9MZIVABVNP2WH1mmkUUlAs G/Nw== X-Gm-Message-State: AOJu0YyzZ4oW1/66Da24b3Z28l80nlYHEqzmTh6WvH5i43Nm+/aQQJw2 btRq3zIIMkgFVpMRJAhMOUH+rtPC3pO4oVth X-Google-Smtp-Source: AGHT+IEh5dIcAp0GEnBovLRazjhlL8PQDv6Lohk4p9MOmD0QGqjO/GAlyfWLfd6btqnP+l2U3DLq0g== X-Received: by 2002:a05:600c:3486:b0:3fb:c9f4:1506 with SMTP id a6-20020a05600c348600b003fbc9f41506mr7709207wmq.1.1692717213648; Tue, 22 Aug 2023 08:13:33 -0700 (PDT) Received: from localhost ([2001:8a0:f90f:8600:1210:1829:770d:f735]) by smtp.gmail.com with UTF8SMTPSA id n3-20020a05600c3b8300b003fef5e76f2csm1229333wms.0.2023.08.22.08.13.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Aug 2023 08:13:33 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH] Fix Windows sharing_input_terminal hang Date: Tue, 22 Aug 2023 16:13:32 +0100 Message-Id: <20230822151332.4010554-1-pedro@palves.net> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,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: 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 "<=". That is fixed by this patch. Change-Id: I14e4909f2ac2fa83d0d9b6e64418b5831ac4e4e3 --- gdb/mingw-hdep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/mingw-hdep.c b/gdb/mingw-hdep.c index 75f63a3fe17..137a63eb244 100644 --- a/gdb/mingw-hdep.c +++ b/gdb/mingw-hdep.c @@ -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); base-commit: 11e3488d3f787d51196a115fd9c6085e57bd9626 -- 2.34.1