Re: [PATCH] Change some arguments to gdb::string_view instead of name+len

Tom Tromey
2019-09-30T14:28:19Z

>>>>> "Christian" == Christian Biesinger via gdb-patches <gdb-patches@sourceware.org> writes:

Christian> Just some code cleanup. This change has a few benefits:
Christian> - Shorter argument list in the functions
Christian> - If the caller needs to calculate the string, they no longer
Christian> need to explicitly call strlen
Christian> - It is easy to pass std::string to this (done in one place
Christian> currently)

Christian> This also updates a couple of places that were passing 0/1 to
Christian> a bool parameter.

Thanks for doing this. I think it is a nice cleanup.

Christian> -minimal_symbol_reader::record_full (const char *name, int name_len,
[...]

Christian> if (name[0] == get_symbol_leading_char (m_objfile->obfd))
Christian> {
Christian> - ++name;
Christian> - --name_len;
Christian> + name = gdb::string_view (name.data() + 1, name.length () - 1);

This could probably use the substr method.

Christian> if (symtab_create_debug >= 2)
Christian> printf_unfiltered ("Recording minsym: %-21s %18s %4d %s\n",
Christian> - mst_str (ms_type), hex_string (address), section, name);
Christian> + mst_str (ms_type), hex_string (address), section,
Christian> + name.data ());

This part made me hesitate a bit, because it seems to be at odds with
the idea that an arbitrary string view can be passed in -- for all we
know the string isn't \0-terminated, and this will cause bad behavior.

On the other hand, this error already existed, and is only used for
logging.

Maybe safest is just to transform it to a std::string here?

Tom