From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 24B513858D1E for ; Fri, 8 Sep 2023 14:31:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 24B513858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 388EVGYc019450 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 8 Sep 2023 10:31:21 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 388EVGYc019450 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1694183481; bh=h9wYzPziClJYGBHlPCcCl241wSdS4SH1y3x6hpUjM4I=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=WSLSMiu22HL3qqSnQAZ/v5aFGxGurFZyKQX5Yq7VepL1dvBWX3WkOMBi1cYOsaG1S S2vGTkkzBmqBpGoUMioGQ7cn4+W1BG+dsHqk5nUK1+yVWo8zSTpnzmWYPt+CL8VGXg CgIPkyA1wQ1XMBL3HfFq1Ud1Yph52P+YOWZNUVz8= Received: from [172.16.0.192] (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id EDBEE1E092; Fri, 8 Sep 2023 10:31:15 -0400 (EDT) Message-ID: <0d7782da-940c-40da-a511-4f8a36b5455c@polymtl.ca> Date: Fri, 8 Sep 2023 10:31:15 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] gdb: c++ify btrace_target_info Content-Language: fr To: Markus Metzger , gdb-patches@sourceware.org Cc: vries@gcc.gnu.org References: <20230908105319.1963979-1-markus.t.metzger@intel.com> From: Simon Marchi In-Reply-To: <20230908105319.1963979-1-markus.t.metzger@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 8 Sep 2023 14:31:16 +0000 X-Spam-Status: No, score=-3037.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 9/8/23 06:53, Markus Metzger wrote: > Following the example of private_thread_info and private_inferior, turn > struct btrace_target_info into a small class hierarchy. IIUC, you turned btrace_tinfo_bts and btrace_tinfo_pt into a single class, since they were identical? That seems fine to me. > > Fixes PR gdb/30751. > --- > gdb/nat/linux-btrace.c | 159 +++++++++++++++++-------------------- > gdb/nat/linux-btrace.h | 60 ++++---------- > gdb/remote.c | 24 ++---- > gdbsupport/btrace-common.h | 18 ++++- > 4 files changed, 112 insertions(+), 149 deletions(-) > > diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c > index c5b3f1c93cf..672b25063de 100644 > --- a/gdb/nat/linux-btrace.c > +++ b/gdb/nat/linux-btrace.c > @@ -277,7 +277,7 @@ perf_event_sample_ok (const struct perf_event_sample *sample) > part at the end and its upper part at the beginning of the buffer. */ > > static std::vector * > -perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin, > +perf_event_read_bts (btrace_target_info *tinfo, const uint8_t *begin, > const uint8_t *end, const uint8_t *start, size_t size) > { > std::vector *btrace = new std::vector; > @@ -447,12 +447,19 @@ diagnose_perf_event_open_fail () > error (_("Failed to start recording: %s"), safe_strerror (errno)); > } > > +/* Get the linux version of a btrace_target_info. */ > + > +static linux_btrace_target_info * > +get_linux_btrace_target_info (btrace_target_info *gtinfo) > +{ > + return gdb::checked_static_cast (gtinfo); > +} > + > /* Enable branch tracing in BTS format. */ > > static struct btrace_target_info * > linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf) > { > - struct btrace_tinfo_bts *bts; > size_t size, pages; > __u64 data_offset; > int pid, pg; > @@ -460,31 +467,29 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf) > if (!cpu_supports_bts ()) > error (_("BTS support has been disabled for the target cpu.")); > > - gdb::unique_xmalloc_ptr tinfo > - (XCNEW (btrace_target_info)); > - tinfo->ptid = ptid; > + std::unique_ptr tinfo > + { new linux_btrace_target_info { ptid } }; We recently added a gdb::make_unique function, it would make sense to you use it here (it will eventually become std::make_unique once we migrate to C++ 14). So this could be written as: auto tinfo = gdb::make_unique (ptid); Same for linux_enable_pt. > diff --git a/gdbsupport/btrace-common.h b/gdbsupport/btrace-common.h > index e287c93a6c1..b4defdea84c 100644 > --- a/gdbsupport/btrace-common.h > +++ b/gdbsupport/btrace-common.h > @@ -214,7 +214,23 @@ struct btrace_data > }; > > /* Target specific branch trace information. */ > -struct btrace_target_info; > +struct btrace_target_info > +{ > + btrace_target_info (ptid_t ptid) : ptid (ptid) > + {} > + > + btrace_target_info (ptid_t ptid, btrace_config conf) > + : ptid (ptid), conf (conf) > + {} > + > + /* The ptid of this thread. */ > + ptid_t ptid {}; > + > + /* The obtained branch trace configuration. */ > + btrace_config conf {}; > + > + virtual ~btrace_target_info () = default; Move the destructor just below the constructors. With those fixed: Approved-By: Simon Marchi Simon