From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by sourceware.org (Postfix) with ESMTPS id 03A2A3824583 for ; Wed, 13 Jul 2022 22:24:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 03A2A3824583 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 f2so26115wrr.6 for ; Wed, 13 Jul 2022 15:24:58 -0700 (PDT) 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=xzE7ZZTUAVGDyfxUeHV/kP1KIAbZL2XYMouQdpE7U1A=; b=uU+B9euDxwAXh+r7y2YJbJq1vY0f/vTJQF0O8JGQGxBOtQIGxq1EfdmxvylDHe1YLS CX5u9yaAEJImaxS3LaOH4WumYmz4wOnQ9njXsN/Mx0DiYc3bpagyUSGD557Tcj7umxJ2 MmlJxJ2ZPh51HM5naCe0PhF5KVNjkqfde69e23qnTLHCBrw1goBNazK+yn/mntTq4Kfe MoL/p2dzxzO5ZjuKVEUtT9QKR7T0NTkkqNMGD2V0CE4N7jYvRMLENJ5VCOMKgqgo38aI Tu7RpsFHsXSyBjunSWSwEzmtklxpWQ+E5whXUxfVldCgWxTKpCIEK+v4W6PxH7JL7S88 2W4w== X-Gm-Message-State: AJIora9ZM6nKtBnLTEM4R6hD3YsB4ekRn8sDaXRloltqcEi9QdBID3UQ YNBcPyRvLo0h7wE+ScD6xgxxWy6Mj8s= X-Google-Smtp-Source: AGRyM1sRm/LLiTBdd94pk7rf0h4PdQGFpGHNebm2iYuZxU5Fkzrospv8kPUru8YaZH3uKcsOr2kHlw== X-Received: by 2002:adf:e6c9:0:b0:21d:7f65:f1e7 with SMTP id y9-20020adfe6c9000000b0021d7f65f1e7mr5155459wrm.151.1657751097007; Wed, 13 Jul 2022 15:24:57 -0700 (PDT) Received: from localhost ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id h6-20020a5d5486000000b0021b829d111csm12030332wrv.112.2022.07.13.15.24.55 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Jul 2022 15:24:56 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 10/29] gdbserver: Hide and don't detach pending clone children Date: Wed, 13 Jul 2022 23:24:14 +0100 Message-Id: <20220713222433.374898-11-pedro@palves.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220713222433.374898-1-pedro@palves.net> References: <20220713222433.374898-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Wed, 13 Jul 2022 22:25:01 -0000 This commit extends the logic added by these two commits from a while ago: #1 7b961964f866 (gdbserver: hide fork child threads from GDB), #2 df5ad102009c (gdb, gdbserver: detach fork child when detaching from fork parent) ... to handle thread clone events, which are very similar to (v)fork events. For #1, we want to hide clone children as well, so just update the comments. For #2, unlike (v)fork children, pending clone children aren't full processes, they're just threads, so don't detach them in handle_detach. linux-low.cc will take care of detaching them along with all other threads of the process, there's nothing special that needs to be done. Change-Id: I7f5901d07efda576a2522d03e183994e071b8ffc --- gdbserver/linux-low.cc | 5 +++-- gdbserver/linux-low.h | 36 ++++++++++++++++++++---------------- gdbserver/server.cc | 12 +++++++----- gdbserver/target.cc | 3 ++- gdbserver/target.h | 15 ++++++++------- 5 files changed, 40 insertions(+), 31 deletions(-) diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 895583e2a6d..3a95d820cde 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -6874,9 +6874,10 @@ linux_process_target::thread_pending_parent (thread_info *thread) } thread_info * -linux_process_target::thread_pending_child (thread_info *thread) +linux_process_target::thread_pending_child (thread_info *thread, + target_waitkind *kind) { - lwp_info *child = get_thread_lwp (thread)->pending_child (); + lwp_info *child = get_thread_lwp (thread)->pending_child (kind); if (child == nullptr) return nullptr; diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h index c81b93f1171..e7237bba3b3 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -313,7 +313,8 @@ class linux_process_target : public process_stratum_target #endif thread_info *thread_pending_parent (thread_info *thread) override; - thread_info *thread_pending_child (thread_info *thread) override; + thread_info *thread_pending_child (thread_info *thread, + target_waitkind *kind) override; bool supports_catch_syscall () override; @@ -732,8 +733,8 @@ struct pending_signal struct lwp_info { - /* If this LWP is a fork child that wasn't reported to GDB yet, return - its parent, else nullptr. */ + /* If this LWP is a fork/vfork/clone child that wasn't reported to + GDB yet, return its parent, else nullptr. */ lwp_info *pending_parent () const { if (this->fork_relative == nullptr) @@ -741,10 +742,10 @@ struct lwp_info gdb_assert (this->fork_relative->fork_relative == this); - /* In a fork parent/child relationship, the parent has a status pending and - the child does not, and a thread can only be in one such relationship - at most. So we can recognize who is the parent based on which one has - a pending status. */ + /* In a parent/child relationship, the parent has a status pending + and the child does not, and a thread can only be in one such + relationship at most. So we can recognize who is the parent + based on which one has a pending status. */ gdb_assert (!!this->status_pending_p != !!this->fork_relative->status_pending_p); @@ -754,24 +755,25 @@ struct lwp_info const target_waitstatus &ws = this->fork_relative->waitstatus; gdb_assert (ws.kind () == TARGET_WAITKIND_FORKED - || ws.kind () == TARGET_WAITKIND_VFORKED); + || ws.kind () == TARGET_WAITKIND_VFORKED + || ws.kind () == TARGET_WAITKIND_THREAD_CLONED); return this->fork_relative; } - /* If this LWP is the parent of a fork child we haven't reported to GDB yet, - return that child, else nullptr. */ - lwp_info *pending_child () const + /* If this LWP is the parent of a fork/vfork/clone child we haven't + reported to GDB yet, return that child, else nullptr. */ + lwp_info *pending_child (target_waitkind *kind) const { if (this->fork_relative == nullptr) return nullptr; gdb_assert (this->fork_relative->fork_relative == this); - /* In a fork parent/child relationship, the parent has a status pending and - the child does not, and a thread can only be in one such relationship - at most. So we can recognize who is the parent based on which one has - a pending status. */ + /* In a parent/child relationship, the parent has a status pending + and the child does not, and a thread can only be in one such + relationship at most. So we can recognize who is the parent + based on which one has a pending status. */ gdb_assert (!!this->status_pending_p != !!this->fork_relative->status_pending_p); @@ -780,8 +782,10 @@ struct lwp_info const target_waitstatus &ws = this->waitstatus; gdb_assert (ws.kind () == TARGET_WAITKIND_FORKED - || ws.kind () == TARGET_WAITKIND_VFORKED); + || ws.kind () == TARGET_WAITKIND_VFORKED + || ws.kind () == TARGET_WAITKIND_THREAD_CLONED); + *kind = ws.kind (); return this->fork_relative; } diff --git a/gdbserver/server.cc b/gdbserver/server.cc index fb7a1036320..3526e1d000e 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1344,8 +1344,9 @@ handle_detach (char *own_buf) continue; /* Only threads that have a pending fork event. */ - thread_info *child = target_thread_pending_child (thread); - if (child == nullptr) + target_waitkind kind; + thread_info *child = target_thread_pending_child (thread, &kind); + if (child == nullptr || kind == TARGET_WAITKIND_THREAD_CLONED) continue; process_info *fork_child_process = get_thread_process (child); @@ -1765,9 +1766,10 @@ handle_qxfer_threads_worker (thread_info *thread, struct buffer *buffer) gdb_byte *handle; bool handle_status = target_thread_handle (ptid, &handle, &handle_len); - /* If this is a fork or vfork child (has a fork parent), GDB does not yet - know about this process, and must not know about it until it gets the - corresponding (v)fork event. Exclude this thread from the list. */ + /* If this is a (v)fork/clone child (has a (v)fork/clone parent), + GDB does not yet know about this thread, and must not know about + it until it gets the corresponding (v)fork/clone event. Exclude + this thread from the list. */ if (target_thread_pending_parent (thread) != nullptr) return; diff --git a/gdbserver/target.cc b/gdbserver/target.cc index 70fec6d2078..ad32af0416e 100644 --- a/gdbserver/target.cc +++ b/gdbserver/target.cc @@ -808,7 +808,8 @@ process_stratum_target::thread_pending_parent (thread_info *thread) } thread_info * -process_stratum_target::thread_pending_child (thread_info *thread) +process_stratum_target::thread_pending_child (thread_info *thread, + target_waitkind *kind) { return nullptr; } diff --git a/gdbserver/target.h b/gdbserver/target.h index 33142363a02..0aa7db49c18 100644 --- a/gdbserver/target.h +++ b/gdbserver/target.h @@ -479,13 +479,14 @@ class process_stratum_target virtual bool thread_handle (ptid_t ptid, gdb_byte **handle, int *handle_len); - /* If THREAD is a fork child that was not reported to GDB, return its parent - else nullptr. */ + /* If THREAD is a fork/vfork/clone child that was not reported to + GDB, return its parent else nullptr. */ virtual thread_info *thread_pending_parent (thread_info *thread); - /* If THREAD is the parent of a fork child that was not reported to GDB, - return this child, else nullptr. */ - virtual thread_info *thread_pending_child (thread_info *thread); + /* If THREAD is the parent of a fork/vfork/clone child that was not + reported to GDB, return this child, else nullptr. */ + virtual thread_info *thread_pending_child (thread_info *thread, + target_waitkind *kind); /* Returns true if the target can software single step. */ virtual bool supports_software_single_step (); @@ -701,9 +702,9 @@ target_thread_pending_parent (thread_info *thread) } static inline thread_info * -target_thread_pending_child (thread_info *thread) +target_thread_pending_child (thread_info *thread, target_waitkind *kind) { - return the_target->thread_pending_child (thread); + return the_target->thread_pending_child (thread, kind); } int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len); -- 2.36.0