From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6B1rJa3TIGIjWgAAWB0awg (envelope-from ) for ; Thu, 03 Mar 2022 09:41:49 -0500 Received: by simark.ca (Postfix, from userid 112) id 969481F3CA; Thu, 3 Mar 2022 09:41:49 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.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 F32FD1F0D2 for ; Thu, 3 Mar 2022 09:41:48 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B479B3857C6A for ; Thu, 3 Mar 2022 14:41:48 +0000 (GMT) Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by sourceware.org (Postfix) with ESMTPS id 8B9483857C73 for ; Thu, 3 Mar 2022 14:40:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8B9483857C73 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-f48.google.com with SMTP id q20so947503wmq.1 for ; Thu, 03 Mar 2022 06:40:35 -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=cG4AosBEPTOWPnoOpzRQb+03uKDVXZWf8lvROcMCwBI=; b=kZ9ky1OmktgCKJu+8auTnc6uT8YVcX2mwMqVF9KSJl793Hj0DdgFwedPMLXpE13+9I lMf6Hoe2qJqrawrSCYr6mpcCF/WD3lOpVznPV/tlg6oAxaN5aK6E4hn9394cdFFiVEUL q+V9yt1hqlEF8rOaBJYhD4pik67VYH8WVO1c7DV4y96W08s2uG6wc2QYqSGt9Buwqrg5 57SscvTnritD96NSp2Bd0qLqjQsYLiO1H0rR6YAHIrglDn94uARpmF+HQYHxWBCoOjXz eSTm2MEsAnu+ilgeh9T395W4B0DemXJ1M0UCgn9O3Q92dayM2RZFxGyMPpS81n7gHGWA cN+Q== X-Gm-Message-State: AOAM533y3yeF3GbG+jb9HODqiRZ96u63Nn69vLvySlFl39zje9DwXvQi OMWqcn9efxIufcgjYUSSdD0Vs+BFNqQ= X-Google-Smtp-Source: ABdhPJyOXAXfqrvAUjZW/npNcZcPVyKGue1d4ROutTe6EW9d6o5Z6JS5tXUmwIqQeF14PuyQ6/IX5g== X-Received: by 2002:a7b:cb46:0:b0:37b:dd79:e1c4 with SMTP id v6-20020a7bcb46000000b0037bdd79e1c4mr3939536wmj.39.1646318433941; Thu, 03 Mar 2022 06:40:33 -0800 (PST) Received: from localhost ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id f186-20020a1c38c3000000b00382a9b91515sm6931464wma.37.2022.03.03.06.40.32 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Mar 2022 06:40:32 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 05/11] gdbserver: Reorganize linux_process_target::filter_event Date: Thu, 3 Mar 2022 14:40:14 +0000 Message-Id: <20220303144020.3601082-6-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-low.cc:linux_process_target::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 to have them synchronized with the GDB counterpart. Change-Id: If9019635f63a846607cfda44b454b4254a404019 --- gdbserver/linux-low.cc | 76 ++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index e7c01420ae3..2d14a0254c7 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -2148,46 +2148,50 @@ linux_process_target::filter_event (int lwpid, int wstat) child = 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 (because - check_zombie_leaders deleted it). The non-leader thread - changes its tid to the tgid. */ - - if (WIFSTOPPED (wstat) && child == NULL && WSTOPSIG (wstat) == SIGTRAP - && linux_ptrace_get_extended_event (wstat) == PTRACE_EVENT_EXEC) + /* Check for events reported by anything not in our LWP list. */ + if (child == nullptr) { - ptid_t child_ptid; - - /* A multi-thread exec after we had seen the leader exiting. */ - threads_debug_printf ("Re-adding thread group leader LWP %d after exec.", - lwpid); + if (WIFSTOPPED (wstat)) + { + if (WSTOPSIG (wstat) == SIGTRAP + && linux_ptrace_get_extended_event (wstat) == 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. */ + threads_debug_printf + ("Re-adding thread group leader LWP %d after exec.", + lwpid); - child_ptid = ptid_t (lwpid, lwpid); - child = add_lwp (child_ptid); - child->stopped = 1; - switch_to_thread (child->thread); - } + child = add_lwp (ptid_t (lwpid, lwpid)); + child->stopped = 1; + switch_to_thread (child->thread); + } + 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. */ + threads_debug_printf + ("Saving LWP %d status %s in stopped_pids list", + lwpid, status_to_str (wstat).c_str ()); + add_to_pid_list (&stopped_pids, lwpid, wstat); + } + } + 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 we didn't find a process, one of two things presumably happened: - - A process we started and then detached from has exited. Ignore it. - - A process we are controlling has forked and the new child's stop - was reported to us by the kernel. Save its PID. */ - if (child == NULL && WIFSTOPPED (wstat)) - { - add_to_pid_list (&stopped_pids, lwpid, wstat); - return; + if (child == nullptr) + return; } - else if (child == NULL) - return; thread = get_lwp_thread (child); -- 2.26.2