This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFAv3 1/5] New cli-utils.h/.c function extract_info_print_args
- From: Philippe Waroquiers <philippe dot waroquiers at skynet dot be>
- To: Pedro Alves <palves at redhat dot com>, gdb-patches at sourceware dot org
- Date: Tue, 23 Oct 2018 23:59:25 +0200
- Subject: Re: [RFAv3 1/5] New cli-utils.h/.c function extract_info_print_args
- References: <20180923214209.985-1-philippe.waroquiers@skynet.be> <20180923214209.985-2-philippe.waroquiers@skynet.be> <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