From patchwork Wed Jul 5 22:42:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72215 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 09D2338560A7 for ; Wed, 5 Jul 2023 22:43:19 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from gproxy4-pub.mail.unifiedlayer.com (gproxy4-pub.mail.unifiedlayer.com [69.89.23.142]) by sourceware.org (Postfix) with ESMTPS id 9D91E385771F for ; Wed, 5 Jul 2023 22:43:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D91E385771F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw11.mail.unifiedlayer.com (unknown [10.0.90.126]) by progateway6.mail.pro1.eigbox.com (Postfix) with ESMTP id EA8E010064DA5 for ; Wed, 5 Jul 2023 22:42:54 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id HBD4qLbQY82LXHBD4qGmFb; Wed, 05 Jul 2023 22:42:54 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=VNgYI/DX c=1 sm=1 tr=0 ts=64a5f1ee a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=ws7JD89P4LkA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=iRYVzAmSJ3hj9MqzegwA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=W3gP9XMSEZOOG9MVFvlOwY3hnHzYY0npfGLEnP/jThE=; b=saEx6YTSEuw9r5GHKbDDupGnZc aWdjgUJXxT4oGwuZBCTT8j0KRPisrEmLZoU6Wg7Az/TQ65tjOVIPDnmFYWEoXSWjAKFG/ZPNpAO6g CyjRXa100JFZcwGuLPdBgCgTb; Received: from 75-166-135-140.hlrn.qwest.net ([75.166.135.140]:56156 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qHBD4-001UC8-1t; Wed, 05 Jul 2023 16:42:54 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Pass unique_ptr to add_thread_with_info Date: Wed, 5 Jul 2023 16:42:47 -0600 Message-ID: <20230705224247.536013-1-tom@tromey.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.135.140 X-Source-L: No X-Exim-ID: 1qHBD4-001UC8-1t X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-135-140.hlrn.qwest.net (localhost.localdomain) [75.166.135.140]:56156 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3026.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This changes add_thread_with_info to accept a unique_ptr, making it clear that it takes ownership of the passed-in pointer. I can't test the AIX or Darwin changes, but I think they are relatively obvious. --- gdb/aix-thread.c | 2 +- gdb/darwin-nat.c | 3 ++- gdb/gdbthread.h | 7 +++++-- gdb/linux-thread-db.c | 3 ++- gdb/thread.c | 4 ++-- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index fbe80d656c2..4508ca9dca0 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -909,7 +909,7 @@ sync_threadlists (pid_t pid) thread = add_thread_with_info (proc_target, ptid_t (pid, 0, pbuf[pi].pthid), - priv); + private_thread_info_up (priv)); pi++; } diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 4cf2d9f387a..588e9e2a345 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -351,7 +351,8 @@ darwin_nat_target::check_new_threads (inferior *inf) pti->msg_state = DARWIN_RUNNING; /* Add the new thread. */ - add_thread_with_info (this, ptid_t (inf->pid, 0, new_id), pti); + add_thread_with_info (this, ptid_t (inf->pid, 0, new_id), + private_thread_info_up (pti)); new_thread_vec.push_back (pti); new_ix++; continue; diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 7135515bf45..8b5ec8abf01 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -222,6 +222,9 @@ struct private_thread_info virtual ~private_thread_info () = 0; }; +/* Unique pointer wrapper for private_thread_info. */ +typedef std::unique_ptr private_thread_info_up; + /* Threads are intrusively refcounted objects. Being the user-selected thread is normally considered an implicit strong reference and is thus not accounted in the refcount, unlike @@ -522,7 +525,7 @@ class thread_info : public refcounted_object, struct frame_id initiating_frame = null_frame_id; /* Private data used by the target vector implementation. */ - std::unique_ptr priv; + private_thread_info_up priv; /* Branch trace information for this thread. */ struct btrace_thread_info btrace {}; @@ -616,7 +619,7 @@ extern struct thread_info *add_thread_silent (process_stratum_target *targ, /* Same as add_thread, and sets the private info. */ extern struct thread_info *add_thread_with_info (process_stratum_target *targ, ptid_t ptid, - private_thread_info *); + private_thread_info_up); /* Delete thread THREAD and notify of thread exit. If the thread is currently not deletable, don't actually delete it but still tag it diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 71a81aa0cb9..7d9fd57da0c 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1366,7 +1366,8 @@ record_thread (struct thread_db_info *info, thread with this PTID, but it's marked exited, then the kernel reused the tid of an old thread. */ if (tp == NULL || tp->state == THREAD_EXITED) - tp = add_thread_with_info (info->process_target, ptid, priv); + tp = add_thread_with_info (info->process_target, ptid, + private_thread_info_up (priv)); else tp->priv.reset (priv); diff --git a/gdb/thread.c b/gdb/thread.c index 7f7f035b5ab..63ed87e9aa6 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -306,11 +306,11 @@ add_thread_silent (process_stratum_target *targ, ptid_t ptid) struct thread_info * add_thread_with_info (process_stratum_target *targ, ptid_t ptid, - private_thread_info *priv) + private_thread_info_up priv) { thread_info *result = add_thread_silent (targ, ptid); - result->priv.reset (priv); + result->priv = std::move (priv); if (print_thread_events) gdb_printf (_("[New %s]\n"), target_pid_to_str (ptid).c_str ());