public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Metzger, Markus T" <markus.t.metzger@intel.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
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 10:42:33 +0000	[thread overview]
Message-ID: <DM8PR11MB57496DA3B5A98ECB083620E8DEEEA@DM8PR11MB5749.namprd11.prod.outlook.com> (raw)
In-Reply-To: <79f9ba63-e2c8-4a32-a310-6666d75cfae1@polymtl.ca>

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.

Now, that cannot happen today, since both linux_disable_pt and
linux_disable_bts return BTRACE_ERR_NONE.

>> @@ -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.


>>  {
>>    /* 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.


>> +    : ptid (_ptid), conf (_conf)
>> +    {}
>
>Did you take this style of leading underscore from somewhere?  I
>typically don't mind giving the same name to fields an constructor
>parameters, it works just fine.  Otherwise, I've seen others use
>trailing underscores.

I saw it in GDB.  I also saw (ptid_).  And, now that I searched for it,
I also see _foo_, __foo, __foo__.  Dropping the _.


>>  /* Teardown branch tracing.  */
>> @@ -14676,7 +14705,7 @@ void
>>  remote_target::teardown_btrace (struct btrace_target_info *tinfo)
>>  {
>>    /* We must not talk to the target during teardown.  */
>> -  xfree (tinfo);
>> +  delete tinfo;
>
>And it seems like this could take a btrace_target_info_up too?
>
>I just noticed that remote_target::teardown_btrace deletes the tinfo
>it receives, but x86_linux_nat_target::teardown_btrace doesn't.  Is that
>a bug / leak on the x86-linux-nat side?

The linux target leaves that to linux_disable_btrace().


I'll send a v2 patch with the changes you requested.

regards,
markus.
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

  reply	other threads:[~2023-09-07 10:43 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 [this message]
2023-09-07 13:54       ` Simon Marchi
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=DM8PR11MB57496DA3B5A98ECB083620E8DEEEA@DM8PR11MB5749.namprd11.prod.outlook.com \
    --to=markus.t.metzger@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    --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).