From patchwork Mon Nov 13 15:04:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 79753 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 1EC0D38CA5D9 for ; Mon, 13 Nov 2023 15:07:12 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by sourceware.org (Postfix) with ESMTPS id 53F86388C550 for ; Mon, 13 Nov 2023 15:05:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 53F86388C550 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 53F86388C550 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887920; cv=none; b=G5tRIPH8OwKtHTxTyyX60TS3Su+vYNioMdnPrqzPUXvdLqFAdGdifgIvPF10Jx+JvzMObluJmSTw62tax3KWD04DGJnNA65+UBdK8iBQYcel8lSS9WNW4NQV6oP784a0s1n8c+/aV9an/pdEY9+aRZmWkvXgW5cvCdkN5l9oe0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887920; c=relaxed/simple; bh=WqmpImJQAR+WtVed2FQ+o6pqjeYIDpGutTdoz+WI+oc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=jPwFbjGsKqM8BeU/UVUsyobXA+yjJLFI0HydbysvQKo+O7Mw67AltLUHaAsuTEH85mjOEyRBGCrLvzRHe4C5hjrm5yfP4sVJyIg7uVXieve1oPuxjMlVyz1CJQIbiG7/YvHdFCx3SfcGDOMJkIog8RGOKHqcrdkDjVfUUdUhxT4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-408382da7f0so37693735e9.0 for ; Mon, 13 Nov 2023 07:05:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699887917; x=1700492717; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=otTtiQT5om/deyxvwi47aDrpmTQ7fAKKrPgkHd6tPmI=; b=oNj4YjrtFVPoxsBom+DgoqYaKfp+Dwvfjw43kBr7c5ELTdDLkpprdL+9GLgXaCYUAL vo/bw4ZhVy9xyMCNhNW8KORCvTNizuGP9s8+hdw/xdM6f5j3QTbJ6kGBR2GOhFEFk22V eFAhrApFEH6eMHIEYA8UwTgQCGhLDcXCzMkvGL0d47T33YDvcslV3zXpHVPovUDz82DQ NgCbYzgB9wgzMKwL1Q5Idd2GmEdM+7mbfYp87j3oRzNScZ9flyMAPPrC90DmRyXvS7Lz mntAKNBk+rbLcOENC0xlafUM6ID10CJ4db+ndpLc87f5Z8MfHUaI4ljliWL+aYAC185j FjeQ== X-Gm-Message-State: AOJu0Yyt4ROGqW4klycwQereD36jZmPyVyl2gI39EsL+Cp0S7rH0SSCK VgwBlGPXoDW2pdyqsAnotqdQBVhpMGg= X-Google-Smtp-Source: AGHT+IG1t9A29+1zPTuq17xAIA9cGcA40l0IpIwF0eLgkFPSPqvE6mAnAfMImqqW3x15vGqWInip8A== X-Received: by 2002:a5d:64ee:0:b0:32f:a48b:1e2b with SMTP id g14-20020a5d64ee000000b0032fa48b1e2bmr5391066wri.5.1699887916736; Mon, 13 Nov 2023 07:05:16 -0800 (PST) Received: from localhost ([2001:8a0:f91e:1a00:8060:1e54:fb28:9635]) by smtp.gmail.com with UTF8SMTPSA id a15-20020a5d456f000000b0032ddf2804ccsm5599010wrc.83.2023.11.13.07.05.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Nov 2023 07:05:16 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [FYI/pushed v4 09/25] gdbserver: Hide and don't detach pending clone children Date: Mon, 13 Nov 2023 15:04:11 +0000 Message-Id: <20231113150427.477431-10-pedro@palves.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231113150427.477431-1-pedro@palves.net> References: <20231113150427.477431-1-pedro@palves.net> MIME-Version: 1.0 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.30 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 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. Reviewed-By: Andrew Burgess Change-Id: I7f5901d07efda576a2522d03e183994e071b8ffc --- gdbserver/linux-low.cc | 5 +++-- gdbserver/linux-low.h | 15 ++++++++++----- gdbserver/server.cc | 12 +++++++----- gdbserver/target.cc | 3 ++- gdbserver/target.h | 16 +++++++++------- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 136a8b6c9a1..7a4f8758ae9 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -6951,9 +6951,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 94093dd4ed8..b5ff9391198 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; @@ -756,13 +757,15 @@ struct lwp_info const target_waitstatus &ws = this->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->relative; } /* 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 () const + reported to GDB yet, return that child and fill in KIND with the + matching waitkind, otherwise nullptr. */ + lwp_info *pending_child (target_waitkind *kind) const { if (this->relative == nullptr) return nullptr; @@ -781,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->relative; } diff --git a/gdbserver/server.cc b/gdbserver/server.cc index c24a5c9fb96..2a70ca63cbd 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1349,8 +1349,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); @@ -1771,9 +1772,10 @@ handle_qxfer_threads_worker (thread_info *thread, std::string *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 1c740bbf583..dbb4e2d9024 100644 --- a/gdbserver/target.cc +++ b/gdbserver/target.cc @@ -816,7 +816,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 8893e0a6a8b..0f1fd5906fb 100644 --- a/gdbserver/target.h +++ b/gdbserver/target.h @@ -478,13 +478,15 @@ 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 and fill in KIND with the + matching waitkind, otherwise 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 (); @@ -700,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); } /* Read LEN bytes from MEMADDR in the buffer MYADDR. Return 0 if the read