From patchwork Mon Dec 12 20:30:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 61832 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95B1238493C7 for ; Mon, 12 Dec 2022 20:32:46 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by sourceware.org (Postfix) with ESMTPS id 1F700384D6DF for ; Mon, 12 Dec 2022 20:31:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1F700384D6DF 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-f49.google.com with SMTP id h11so13424003wrw.13 for ; Mon, 12 Dec 2022 12:31:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RorRIdRMqs/GP09Gq3d45yPx/QWaw9Aj+y1BitxpsCQ=; b=a4fstHPcdbqR7mh+F1dGTCcXzmuzVeKaAhmjUt4/6Z5OSfnSaWvf2rUdZgLA45t9lK EW351DUT5CRsAcDDTUu2UB0FDKgeNvo5vZz6+8h7wIN6NuM8xt8RgME+0IReN53PIR50 3r2fAMHy3ADSK+VpjDujFy3yDahpicDnzeYuiJYwQMWbjEa3zEtPqwNZlYCr8jgItk9r afs/wIy6plZKABbyuWb86lZaBO29mEdKZDReJxRC3P/YM/+9ZA0V9s90clQ4L4B5G61s syVPYw46r+9BIo94dkvn3bXSB5LUNdkKycoc35rzW1FaTd95MAST7IRl/SZ2QycSP2GN 2P5Q== X-Gm-Message-State: ANoB5plpjmRB/U6d1/MsYVTwHYi582cTAgbnyfsiRnc03AIuE2FVlp6Q VvTHeV9PobAD2GJRsZleumnoaMCgvgr7ZA== X-Google-Smtp-Source: AA0mqf5Ed0uK4ljyBCB2NRoo91bcfp0Lh4vrGO3bVcs74yFPOH+Uo+g6iCpw2TUvO0S9dPQ/JBqXsg== X-Received: by 2002:a5d:4892:0:b0:241:6654:62f1 with SMTP id g18-20020a5d4892000000b00241665462f1mr9772533wrq.49.1670877072829; Mon, 12 Dec 2022 12:31:12 -0800 (PST) Received: from localhost ([2001:8a0:f912:6700:afd9:8b6d:223f:6170]) by smtp.gmail.com with ESMTPSA id v1-20020a5d6781000000b002422b462975sm9598606wru.34.2022.12.12.12.31.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Dec 2022 12:31:12 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 11/31] gdbserver: Hide and don't detach pending clone children Date: Mon, 12 Dec 2022 20:30:41 +0000 Message-Id: <20221212203101.1034916-12-pedro@palves.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20221212203101.1034916-1-pedro@palves.net> References: <20221212203101.1034916-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-10.3 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 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+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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 Reviewed-By: Andrew Burgess --- 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 d755cda0e44..a7c310260ca 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -6940,9 +6940,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 69a34fb96fc..c9f9db71e09 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -315,7 +315,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; @@ -734,8 +735,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) @@ -743,10 +744,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); @@ -756,24 +757,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); @@ -782,8 +784,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 5b07c4e4388..07a3319d114 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 168b843d2ec..4584e9b3a8e 100644 --- a/gdbserver/target.cc +++ b/gdbserver/target.cc @@ -814,7 +814,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 8a0d9f42f7d..e2e818b130b 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);