From: Simon Marchi <simon.marchi@polymtl.ca>
To: Markus Metzger <markus.t.metzger@intel.com>, gdb-patches@sourceware.org
Cc: vries@gcc.gnu.org
Subject: Re: [PATCH v3] gdb: c++ify btrace_target_info
Date: Fri, 8 Sep 2023 10:31:15 -0400 [thread overview]
Message-ID: <0d7782da-940c-40da-a511-4f8a36b5455c@polymtl.ca> (raw)
In-Reply-To: <20230908105319.1963979-1-markus.t.metzger@intel.com>
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<btrace_block> *
> -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_block> *btrace = new std::vector<btrace_block>;
> @@ -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<linux_btrace_target_info *> (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<btrace_target_info> tinfo
> - (XCNEW (btrace_target_info));
> - tinfo->ptid = ptid;
> + std::unique_ptr<linux_btrace_target_info> 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<linux_btrace_target_info> (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.marchi@efficios.com>
Simon
next prev parent reply other threads:[~2023-09-08 14:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-08 10:53 Markus Metzger
2023-09-08 14:31 ` Simon Marchi [this message]
2023-09-11 6:18 ` Metzger, Markus T
2023-09-11 9:17 ` Andrew Burgess
2023-09-11 9:53 ` Metzger, Markus T
2023-09-11 14:25 ` Andrew Burgess
2023-09-11 15:27 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0d7782da-940c-40da-a511-4f8a36b5455c@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=markus.t.metzger@intel.com \
--cc=vries@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).