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

Christian Biesinger via gdb-patches gdb-patches@sourceware.org
Tue Oct 1 17:26:00 GMT 2019


On Tue, Oct 1, 2019 at 12:18 PM Tom Tromey <tom@tromey.com> wrote:
>
> >>>>> "Christian" == Christian Biesinger via gdb-patches <gdb-patches@sourceware.org> writes:
>
> Christian> [This version also replaces an instance of strcmp with string_view's
> Christian> operator==, so that the length is correctly respected]
>
> Thanks.
>
> Unfortunately I found / remembered another weirdness.
>
> Christian> -  if (linkage_name[len] != '\0')
> Christian> +  if (linkage_name[linkage_name.length ()] != '\0')
>
> This code let the caller pass in a possibly-unterminated string, and
> then made a local copy with the terminating \0 in that case.
>
> However, this was always a bad idea, and now is probably a libstdc++
> debug-mode assertion failure (<- just guessing but if it isn't, it
> should be!).

Well, gdb::string_view (and libstdc++ in g++ 8 and 10) does have this:
      constexpr const _CharT&
      operator[](size_type __pos) const
      {
// TODO: Assert to restore in a way compatible with the constexpr.
// __glibcxx_assert(__pos < this->_M_len);

So I'm going to change it to .data()[]. Sending a new patch in a second.

Christian



More information about the Gdb-patches mailing list