public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Tom Tromey <tom@tromey.com>,
	Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 1/2] gdb: use gdb::unique_xmalloc_ptr<char> for docs in cmdpy_init
Date: Sat, 28 May 2022 11:10:59 +0100	[thread overview]
Message-ID: <877d66ezm4.fsf@redhat.com> (raw)
In-Reply-To: <87ilps6vg6.fsf@tromey.com>

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Andrew> Make use of gdb::unique_xmalloc_ptr<char> to hold the documentation
> Andrew> string in cmdpy_init (when creating a custom GDB command in Python).
> Andrew> I think this is all pretty straight forward, the only slight weirdness
> Andrew> is the removal of the call to free toward the end of this function.
>
> Andrew> Prior to this commit, if an exception was thrown after the GDB command
> Andrew> was created then we would (I think) end up freeing the documentation
> Andrew> string even though the command would remain registered with GDB, which
> Andrew> would surely lead to undefined behaviour.
>
> Andrew> After this commit we release the doc string at the point that we hand
> Andrew> it over to the command creation routines.  If we throw _after_ the
> Andrew> command has been created within GDB then the doc string will be left
> Andrew> live.  If we throw during the command creation itself (either from
> Andrew> add_prefix_cmd or add_cmd) then it is up to those functions to free
> Andrew> the doc string (I suspect we don't, but I think in general the
> Andrew> commands are pretty bad at cleaning up after themselves, so I don't
> Andrew> think this is a huge problem).
>
> This looks ok to me.
> Maybe an add_prefix_cmd overload that takes a unique_xmalloc_ptr would
> be the way to go eventually.

I agree being able to pass a unique_xmalloc_ptr to the commands would
improve things.

That said, I've pushed this patch as is for now, as I feel improving the
memory management for cmds is a bigger, separate, task.

Thanks,
Andrew


  reply	other threads:[~2022-05-28 10:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-17 10:51 [PATCH 0/2] Improve help test for commands defined in Python Andrew Burgess
2022-05-17 10:51 ` [PATCH 1/2] gdb: use gdb::unique_xmalloc_ptr<char> for docs in cmdpy_init Andrew Burgess
2022-05-26 17:43   ` Tom Tromey
2022-05-28 10:10     ` Andrew Burgess [this message]
2022-05-17 10:51 ` [PATCH 2/2] gdb/python: improve formatting of help text for user defined commands Andrew Burgess
2022-05-17 12:19   ` Eli Zaretskii
2022-05-17 22:41   ` Lancelot SIX
2022-05-18 10:19   ` Andrew Burgess
2022-05-18 12:09     ` Eli Zaretskii
2022-05-26 17:46     ` Tom Tromey
2022-05-28 10:11       ` Andrew Burgess
2022-05-31 21:54         ` Carl Love
2022-05-31 23:10           ` Carl Love
2022-06-03 18:05             ` Carl Love
2022-06-06 11:40               ` [PUSHED] gdb/testsuite: add missing skip_python_tests call in py-doc-reformat.exp Andrew Burgess
2022-06-07 16:08                 ` Carl Love

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=877d66ezm4.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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).