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: Pedro Alves <palves at redhat dot com>
- To: Philippe Waroquiers <philippe dot waroquiers at skynet dot be>, gdb-patches at sourceware dot org
- Date: Wed, 24 Oct 2018 18:03:05 +0100
- 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> <1540331965.12106.8.camel@skynet.be>
On 10/23/2018 10:59 PM, Philippe Waroquiers wrote:
> On Mon, 2018-10-22 at 15:15 +0100, Pedro Alves wrote:
>> +/* 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).
Ah.
> 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) ?
Keep the function's interface, but use xstrprintf instead
of 'xstrdup + string_printf' then.
Thanks,
Pedro Alves