This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFAv3 1/5] New cli-utils.h/.c function extract_info_print_args


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]