From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by sourceware.org (Postfix) with ESMTPS id 89F62384144C for ; Mon, 20 Jun 2022 22:54:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 89F62384144C 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-f48.google.com with SMTP id g4so16475044wrh.11 for ; Mon, 20 Jun 2022 15:54:40 -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=BlOxxU5u23Ipd9IkGZwN7d7TXGWPMwptb10MZEN2LhU=; b=U9sYvgLmlK5euQ7F5qnqKRZqnWcARB9n+z/BofRbFBgkGhUUK9aUwjd3B5/nKBXq7x tOGUONHsQWmt4v0+Sbj4YHnN4HmWXaABR4/6tZSfiznOz4JpRxpcWc+2raLN1iPiUwOX N1r+/+uV2PCLBNUlrnmFHd5kmHOQMa/2bq5BFirXgk/NPZcJCPeKpFxmZOeSI1IW49nr k3JO+Bta8qLM4tbJ+wFsRlk1YIHoLVmG/lFu07p2Vw1GAfwfH3CK8Pk4enJsQCLcfp29 orCGaMtVSeOoM4AZY2hNp+o36K7rt4V9TDU/5wwDySXozPCcUv3QR49RNVJK+PgflC3l u1/Q== X-Gm-Message-State: AJIora8hYrg3hvUExoBncqsf4ZMiQpj4m/2uZH2R226RtVLvFDPAsEg6 2CBk/Ek2VqA76G3Kzu6QHLU44jnkjCQ= X-Google-Smtp-Source: AGRyM1t0Vd/SCzIro1L0WP2VvSwv8CwO4TQzspQQ4v1pTAcGFVD0BoSXw5p4vbvKwL0lITVBtMyMZA== X-Received: by 2002:adf:dbc1:0:b0:219:e994:6ba7 with SMTP id e1-20020adfdbc1000000b00219e9946ba7mr25370082wrj.229.1655765678240; Mon, 20 Jun 2022 15:54:38 -0700 (PDT) Received: from localhost ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id k17-20020a5d6e91000000b0021a39f5ba3bsm13697677wrz.7.2022.06.20.15.54.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Jun 2022 15:54:37 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 07/25] Thread options & clone events (native Linux) Date: Mon, 20 Jun 2022 23:54:01 +0100 Message-Id: <20220620225419.382221-8-pedro@palves.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220620225419.382221-1-pedro@palves.net> References: <20220620225419.382221-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.8 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: Mon, 20 Jun 2022 22:54:42 -0000 This commit teaches the native Linux target about the GDB_TO_CLONE thread option. It's actually simpler to just continue reporting all clone events unconditionally to the core. There's never any harm in reporting a clone event when the option is disabled. All we need to do is copy the thread options from clone parent to clone child, and report support for the option, otherwise GDB falls back to use target_thread_events(). Change-Id: If271f20320d864f074d8ac0d531cc1a323da847f Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19675 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27830 --- gdb/linux-nat.c | 26 +++++++++++++++++++++++++- gdb/linux-nat.h | 3 +++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 138632667e4..a446a755242 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -1863,6 +1863,8 @@ linux_nat_target::follow_clone (ptid_t child_ptid) lwp_info *new_lp = add_lwp (child_ptid); new_lp->stopped = 1; + thread_info *new_thr = nullptr; + /* If the thread_db layer is active, let it record the user level thread id and status, and add the thread to GDB's list. */ @@ -1871,12 +1873,19 @@ linux_nat_target::follow_clone (ptid_t child_ptid) /* The process is not using thread_db. Add the LWP to GDB's list. */ target_post_attach (new_lp->ptid.lwp ()); - add_thread (linux_target, new_lp->ptid); + new_thr = add_thread (linux_target, new_lp->ptid); } + else + new_thr = find_thread_ptid (linux_target, new_lp->ptid); + + gdb_assert (new_thr != nullptr); /* We just created NEW_LP so it cannot yet contain STATUS. */ gdb_assert (new_lp->status == 0); + /* Copy parent options to the child. */ + new_thr->set_thread_options (inferior_thread ()->thread_options ()); + if (!pull_pid_from_list (&stopped_pids, child_ptid.lwp (), &new_lp->status)) internal_error (__FILE__, __LINE__, _("no saved status for clone lwp")); @@ -4397,6 +4406,21 @@ linux_nat_target::thread_events (int enable) report_thread_events = enable; } +bool +linux_nat_target::supports_set_thread_options (gdb_thread_options options) +{ + constexpr gdb_thread_options supported_options = GDB_TO_CLONE; + return ((options & supported_options) == options); +} + +void +linux_nat_target::set_thread_options (thread_info *thr, + gdb_thread_options options) +{ + /* Nothing to do. target_set_thread_options already recorded the + options in THR. */ +} + linux_nat_target::linux_nat_target () { /* We don't change the stratum; this target will sit at diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h index 683173dbd38..b848c9bac6a 100644 --- a/gdb/linux-nat.h +++ b/gdb/linux-nat.h @@ -82,6 +82,9 @@ class linux_nat_target : public inf_ptrace_target void thread_events (int) override; + bool supports_set_thread_options (gdb_thread_options options) override; + void set_thread_options (thread_info *, gdb_thread_options) override; + bool can_async_p () override; bool supports_non_stop () override; -- 2.36.0