From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gPuDGZ3TIGIjWgAAWB0awg (envelope-from ) for ; Thu, 03 Mar 2022 09:41:33 -0500 Received: by simark.ca (Postfix, from userid 112) id 667A21F3CA; Thu, 3 Mar 2022 09:41:33 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RDNS_DYNAMIC autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id C6C241F0D2 for ; Thu, 3 Mar 2022 09:41:32 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 897E23857C6C for ; Thu, 3 Mar 2022 14:41:32 +0000 (GMT) Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by sourceware.org (Postfix) with ESMTPS id 5FF1F3857C6B for ; Thu, 3 Mar 2022 14:40:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5FF1F3857C6B 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-wr1-f44.google.com with SMTP id u10so6544577wra.9 for ; Thu, 03 Mar 2022 06:40:33 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UdmlSt0KvBNOQ+wQqGTsufFboSs3AZrnzOSOiIpTaJA=; b=m4kLeiKjheDADxfuFNY4jJIswvzvKi19uLbC6t1D/NJcF6iQWLqMAaVEpsIHsZ5W8s SRo1TB+01A+bJOCT6G5z1+N/285e8Dl6OIiPeV0P+hAxIAILWDEGjKobSpG8JTk+Lyew DSC4EqGDjUVDYGgETzDz28plZt+6pzJREfzO5S2eooxyNZV5PdcqgYBEYPXGS5j/5ECg +b5b2D62H2kzPI8Eti622erfdwt5QwsusuLVbArx9W+vWLdUqxVgIPg8AdSp4BuM0RZ5 ix7r860djF4SCWafhgjAXMqKDChLvbD4qMkLRHzhInr4rSR1FNcQV/EFAfeLwwouM4bX 8W8A== X-Gm-Message-State: AOAM530k5Dz5PiiNsJqPcEqZnzyZ7GPqzYGxML92oj5+Axjnq3I6v5lx 3vlb4LLN1XQTmnYtfeU6wEKlLnCkxRM= X-Google-Smtp-Source: ABdhPJxbhygFvwJacvhVFIuCofeXRlubo7BOxDONDWmnM5clZjRra/5spbuucd1vq9nXZGjqLg4oFQ== X-Received: by 2002:adf:d1c2:0:b0:1f0:435a:14ae with SMTP id b2-20020adfd1c2000000b001f0435a14aemr5672052wrd.404.1646318431696; Thu, 03 Mar 2022 06:40:31 -0800 (PST) Received: from localhost ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id e15-20020a5d6d0f000000b001ef7dca67fasm2565013wrq.114.2022.03.03.06.40.30 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Mar 2022 06:40:30 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 04/11] gdb: Reorganize linux_nat_filter_event Date: Thu, 3 Mar 2022 14:40:13 +0000 Message-Id: <20220303144020.3601082-5-pedro@palves.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220303144020.3601082-1-pedro@palves.net> References: <20220303144020.3601082-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Reorganize linux-nat.c:linux_nat_filter_event such that all the handling for events for LWPs not in the LWP list is together. This helps make a following patch clearer. The comments and debug messages have also been tweaked - the end goal is to have them synchronized with the gdbserver counterpart. Change-Id: I8586d8dcd76d8bd3795145e3056fc660e3b2cd22 --- gdb/linux-nat.c | 75 ++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 13682fcff43..1555d3a79e3 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -2776,46 +2776,51 @@ linux_nat_filter_event (int lwpid, int status) lp = find_lwp_pid (ptid_t (lwpid)); - /* Check for stop events reported by a process we didn't already - know about - anything not already in our LWP list. - - If we're expecting to receive stopped processes after - fork, vfork, and clone events, then we'll just add the - new one to our list and go back to waiting for the event - to be reported - the stopped process might be returned - from waitpid before or after the event is. - - But note the case of a non-leader thread exec'ing after the - leader having exited, and gone from our lists. The non-leader - thread changes its tid to the tgid. */ - - if (WIFSTOPPED (status) && lp == NULL - && (WSTOPSIG (status) == SIGTRAP && event == PTRACE_EVENT_EXEC)) + /* Check for events reported by anything not in our LWP list. */ + if (lp == nullptr) { - /* A multi-thread exec after we had seen the leader exiting. */ - linux_nat_debug_printf ("Re-adding thread group leader LWP %d.", lwpid); + if (WIFSTOPPED (status)) + { + if (WSTOPSIG (status) == SIGTRAP && event == PTRACE_EVENT_EXEC) + { + /* A non-leader thread exec'ed after we've seen the + leader zombie, and removed it from our lists (in + check_zombie_leaders). The non-leader thread changes + its tid to the tgid. */ + linux_nat_debug_printf + ("Re-adding thread group leader LWP %d after exec.", + lwpid); - lp = add_lwp (ptid_t (lwpid, lwpid)); - lp->stopped = 1; - lp->resumed = 1; - add_thread (linux_target, lp->ptid); - } + lp = add_lwp (ptid_t (lwpid, lwpid)); + lp->stopped = 1; + lp->resumed = 1; + add_thread (linux_target, lp->ptid); + } + else + { + /* A process we are controlling has forked and the new + child's stop was reported to us by the kernel. Save + its PID and go back to waiting for the fork event to + be reported - the stopped process might be returned + from waitpid before or after the fork event is. */ + linux_nat_debug_printf + ("Saving LWP %d status %s in stopped_pids list", + lwpid, status_to_str (status).c_str ()); + add_to_pid_list (&stopped_pids, lwpid, status); + } + } + else + { + /* Don't report an event for the exit of an LWP not in our + list, i.e. not part of any inferior we're debugging. + This can happen if we detach from a program we originally + forked and then it exits. */ + } - if (WIFSTOPPED (status) && !lp) - { - linux_nat_debug_printf ("saving LWP %ld status %s in stopped_pids list", - (long) lwpid, status_to_str (status).c_str ()); - add_to_pid_list (&stopped_pids, lwpid, status); - return; + if (lp == nullptr) + return; } - /* Make sure we don't report an event for the exit of an LWP not in - our list, i.e. not part of the current process. This can happen - if we detach from a program we originally forked and then it - exits. */ - if (!WIFSTOPPED (status) && !lp) - return; - /* This LWP is stopped now. (And if dead, this prevents it from ever being continued.) */ lp->stopped = 1; -- 2.26.2