From: Simon Marchi <simon.marchi@polymtl.ca>
To: "Metzger, Markus T" <markus.t.metzger@intel.com>
Cc: "vries@gcc.gnu.org" <vries@gcc.gnu.org>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH 2/2] gdb: c++ify btrace_target_info
Date: Thu, 7 Sep 2023 09:54:05 -0400 [thread overview]
Message-ID: <a9f7c3bb-0370-4604-90dc-4aaccbf5b3af@polymtl.ca> (raw)
In-Reply-To: <DM8PR11MB57496DA3B5A98ECB083620E8DEEEA@DM8PR11MB5749.namprd11.prod.outlook.com>
On 9/7/23 06:42, Metzger, Markus T wrote:
> Hello Simon,
>
> Thanks for your review.
>
>>> if (errcode == BTRACE_ERR_NONE)
>>> - xfree (tinfo);
>>> + delete gtinfo;
>>
>> A question about this, even if it's not introduced by this patch... if
>> errcode is not BTRACE_ERR_NONE, who deletes gtinfo?
>
> It would be leaked. Since tracing couldn't be disabled, it would still
> be in use, so leaking it seems better than deleting an in-use object
> and risking either crash or data corruption.
I'm not sure I follow. Even if something fails when trying to disable
btrace (like a call to the OS fails for an unknown reason), GDB can
still decide it doesn't want to do tracing / consume btrace data and get
rid of the object.
> Now, that cannot happen today, since both linux_disable_pt and
> linux_disable_bts return BTRACE_ERR_NONE.
Ok, well if these operations can't fail I think they should not return
an error code (for the same reason I wrote below about hypothetical
scenarios).
>>> @@ -100,6 +101,15 @@ struct btrace_target_info
>>> struct btrace_tinfo_pt pt;
>>> } variant;
>>> #endif /* HAVE_LINUX_PERF_EVENT_H */
>>> +
>>> +
>>> + linux_btrace_target_info (ptid_t _ptid, const struct btrace_config &_conf)
>>> + : ptid (_ptid), conf (_conf), variant ({})
>>> + {}
>>> +
>>> + linux_btrace_target_info (ptid_t _ptid)
>>> + : ptid (_ptid), conf ({}), variant ({})
>>
>> It's probably not needed to explicitly initialize conf and variant.
>
> That's an interesting question. My interpretation is that not specifying a
> ctor-initializer would leave things undefined*, whereas supplying an empty
> aggregate would zero-initialize everything.
>
> *we'd default-construct conf, which has an implicitly defined default
> constructor, which then default-constructs all the data members, and so on,
> until we reach plain integers, on which no initialization is performed.
Ok, replied to that in my response to v2.
>>> {
>>> /* The ptid of the traced thread. */
>>> ptid_t ptid;
>>>
>>> /* The obtained branch trace configuration. */
>>> struct btrace_config conf;
>>
>> So, these two fields are common to both btrace_target_info sub-classes.
>> Do you intend to move them to the base class? That would allow getting
>> rid of some (all?) casts in remote.c.
>
> No. I think it's better to leave the base class empty to give full freedom
> to targets.
Do you have an actual case of btrace target that wouldn't use these
fields? My stance on it is: this is all internal GDB code, it's not an
API we expose. I don't think we should complicate things for
hypothetical scenarios, when we always have the freedom to re-work
things later if need be. I think it makes more sense to keep things
simple for what we have today.
Simon
next prev parent reply other threads:[~2023-09-07 13:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-06 7:47 [PATCH 1/2] gdb, btrace: move xml parsing into remote.c Markus Metzger
2023-09-06 7:47 ` [PATCH 2/2] gdb: c++ify btrace_target_info Markus Metzger
2023-09-06 13:21 ` Simon Marchi
2023-09-07 10:42 ` Metzger, Markus T
2023-09-07 13:54 ` Simon Marchi [this message]
2023-09-08 9:32 ` Metzger, Markus T
2023-09-06 12:46 ` [PATCH 1/2] gdb, btrace: move xml parsing into remote.c 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=a9f7c3bb-0370-4604-90dc-4aaccbf5b3af@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).