From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) by sourceware.org (Postfix) with ESMTPS id A6933385841F for ; Thu, 24 Feb 2022 14:23:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A6933385841F Received: by mail-qv1-xf2b.google.com with SMTP id w7so3789859qvr.3 for ; Thu, 24 Feb 2022 06:23:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=taSrGcxpRANwiGyPlm5GlXLjNw0EiXuEwWo7oJ76Zh4=; b=GWT8/efP3ctkpRQmvt/czpr3/YWNB9OrOOnL3eTAjkWV9NdgQj9kbbTOX1hne4wont 25BaVFTqiuMvhO1z83jo/iy5LTxpzYf6JeX/d4ZetT4zgYWuIFizyM361KMVwHdgHnEH yAnmUYcHQAX0PVGDXBHwVaO4lb63/Ofr6tv7jFso0gqGruxO+DNFFWWb0W7dv/5NLY08 XzcUODidJfphnR14OoAPbLLPVACXAN3npfJgTKK0LWJeV3bZeLrBPIfQXAWFfgNvl7GG GVbFFESdORbOjtT1GIz4+UjAbw/dKNzwp8YhWCBy2HSjMhXv3Sd6kPziZfT6xj6j1yxw 82jA== X-Gm-Message-State: AOAM531uKVZgbtBs4aesj2Q4/RnwOgjR2CxM4/86ML5i9ubwKV4QqNeo 4b6Z0jUReLH1bSfRNo814u6pCfJCWVw= X-Google-Smtp-Source: ABdhPJzCCN7hxFpwOQSY3YTDwrDaeutjwsdTDmOkzxPuo35IcY5BoMf10wXxgdusk0BC20zfYHDEaQ== X-Received: by 2002:ac8:48d3:0:b0:2d1:f334:4d70 with SMTP id l19-20020ac848d3000000b002d1f3344d70mr2534187qtr.366.1645712605501; Thu, 24 Feb 2022 06:23:25 -0800 (PST) Received: from localhost.localdomain (173-246-5-136.qc.cable.ebox.net. [173.246.5.136]) by smtp.gmail.com with ESMTPSA id 17sm1328005qka.119.2022.02.24.06.23.24 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 24 Feb 2022 06:23:24 -0800 (PST) From: Philippe Blain To: gdb-patches@sourceware.org Cc: Dominique Quatravaux , Sam Warner , Louis-He <1726110778@qq.com>, Simon Marchi Subject: [RFC][PATCH v3 1/1][PR gdb/24069] gdb/darwin: skip over WIFSTOPPED wait4 status Date: Thu, 24 Feb 2022 09:23:21 -0500 Message-Id: <20220224142321.585-2-levraiphilippeblain@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220224142321.585-1-levraiphilippeblain@gmail.com> References: <20220216141540.96514-1-levraiphilippeblain@gmail.com> <20220224142321.585-1-levraiphilippeblain@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Feb 2022 14:23:28 -0000 From: Dominique Quatravaux On modern Darwin's, there appears to be a new circumstance in which a MACH_NOTIFY_DEAD_NAME message can be received, and which was not previously accounted for: to signal the WIFSTOPPED condition in the debuggee. In that case the debuggee is not dead yet (and in fact, counting it as dead would cause a zombie leak - A process in such a state reparents to PID 1, but cannot be killed). - Read and ignore such messages (counting on the next exception message to let us know of the inferior's new state again) - Refactor logging so as to clearly distinguish between the MACH_NOTIFY_DEAD_NAME cases (WIFEXITED, WIFSTOPPED, signal, or something else), and warn in the last case Co-authored-by: Louis-He <1726110778@qq.com> Co-authored-by: Philippe Blain ChangeLog: 2022-02-05 Dominique Quatravaux PR gdb/24609 * gdb/darwin-nat.c (darwin_nat_target::decode_message): Also check for WIFSTOPPED upon MACH_NOTIFY_DEAD_NAME. --- gdb/darwin-nat.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index d96ce1a6c65..1adc6bd8bff 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -1063,7 +1063,7 @@ darwin_nat_target::decode_message (mach_msg_header_t *hdr, } else if (hdr->msgh_id == 0x48) { - /* MACH_NOTIFY_DEAD_NAME: notification for exit. */ + /* MACH_NOTIFY_DEAD_NAME: notification for exit *or* WIFSTOPPED. */ int res; res = darwin_decode_notify_message (hdr, &inf); @@ -1103,15 +1103,33 @@ darwin_nat_target::decode_message (mach_msg_header_t *hdr, return minus_one_ptid; } if (WIFEXITED (wstatus)) - status->set_exited (WEXITSTATUS (wstatus)); - else + { + status->set_exited (WEXITSTATUS (wstatus)); + inferior_debug (4, _("darwin_wait: pid=%d exit, status=0x%x\n"), + res_pid, wstatus); + } + else if (WIFSTOPPED (wstatus)) + { + /* Ignore stopped state, it will be handled by the next exception */ + status->set_ignore (); + inferior_debug (4, _("darwin_wait: pid %d received WIFSTOPPED\n"), + res_pid); + return minus_one_ptid; + } + else if (WIFSIGNALED (wstatus)) { status->set_signalled (gdb_signal_from_host (WTERMSIG (wstatus))); + inferior_debug (4, _("darwin_wait: pid=%d received signal %d\n"), + res_pid, status->sig()); + } + else + { + status->set_ignore (); + warning (_("Unexpected wait status after MACH_NOTIFY_DEAD_NAME " + "notification: 0x%x"), wstatus); + return minus_one_ptid; } - - inferior_debug (4, _("darwin_wait: pid=%d exit, status=0x%x\n"), - res_pid, wstatus); /* Looks necessary on Leopard and harmless... */ wait4 (inf->pid, &wstatus, 0, NULL); -- 2.29.2