From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: Pedro Alves <palves@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [RFAv3 1/5] New cli-utils.h/.c function extract_info_print_args
Date: Tue, 23 Oct 2018 21:59:00 -0000 [thread overview]
Message-ID: <1540331965.12106.8.camel@skynet.be> (raw)
In-Reply-To: <e42bab21-24f6-d8c6-9f1b-1d600a187114@redhat.com>
On Mon, 2018-10-22 at 15:15 +0100, Pedro Alves wrote:
> Hi Philippe,
>
> Finally managed to read through the series.
>
> I have a few comments throughout the series, but nothing very serious.
Thanks for the comments, I will submit a new version soon (once I have
double checked I properly handled all the comments).
One question below ...
> +/* See documentation in cli-utils.h. */
> > +
> > +const char*
> > +info_print_args_help (const char* prefix,
> > + const char* entity_kind)
> While at it, why return a copy of the string, instead of returning
> the std::string directly?
The returned value is used as argument to add_prefix_cmd,
that expects a char * that must stay valid when the std::string is destroyed.
So, at the call site, I cannot use info_print_args_help (...).c_str (),
as this gives a memory corruption (confirmed by valgrind).
So, I have done:
+const char *
+info_print_args_help (const char *prefix,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â const char *entity_kind)
+{
+Â Â /*Â Â Note : this returns a string allocated with xstrdup, as this
+Â Â Â Â Â Â is typically used as argument to add_prefix_cmd, which needs a
+      string that stays valid after destruction of the std::string.  */
+Â Â return xstrdup
+Â Â Â Â (string_printf (_("\
+%sIf NAMEREGEXP is provided, only prints the %s whose name\n   \
....
Does this sound ok, or is there a better way to do (e.g. at the call site) ?
Thanks
Philippe
next prev parent reply other threads:[~2018-10-23 21:59 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-23 21:42 [RFAv3 0/5] info [args|functions|locals|variables] [-q] [-t TYPEREGEXP] [NAMEREGEXP] Philippe Waroquiers
2018-09-23 21:42 ` [RFAv3 5/5] Add a test case for info args|functions|locals|variables " Philippe Waroquiers
2018-10-22 14:19 ` Pedro Alves
2018-10-23 22:05 ` Philippe Waroquiers
2018-10-24 17:18 ` Pedro Alves
2018-09-23 21:42 ` [RFAv3 1/5] New cli-utils.h/.c function extract_info_print_args Philippe Waroquiers
2018-10-22 14:16 ` Pedro Alves
2018-10-23 21:59 ` Philippe Waroquiers [this message]
2018-10-24 17:03 ` Pedro Alves
2018-09-23 21:42 ` [RFAv3 2/5] Add [-q] [-t TYPEREGEXP] [NAMEREGEXP] args to info [args|functions|locals|variables] Philippe Waroquiers
2018-10-22 14:16 ` Pedro Alves
2018-09-23 21:42 ` [RFAv3 4/5] Announce changes in NEWS " Philippe Waroquiers
2018-09-24 6:59 ` Eli Zaretskii
2018-09-23 21:42 ` [RFAv3 3/5] Document changes " Philippe Waroquiers
2018-09-24 7:03 ` Eli Zaretskii
2018-10-22 14:17 ` Pedro Alves
2018-10-02 18:17 ` [RFAv3 0/5] info [args|functions|locals|variables] [-q] [-t TYPEREGEXP] [NAMEREGEXP] Philippe Waroquiers
2018-10-11 19:56 ` PING^2 " Philippe Waroquiers
2018-10-18 19:37 ` PING^3 " Philippe Waroquiers
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=1540331965.12106.8.camel@skynet.be \
--to=philippe.waroquiers@skynet.be \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.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