From: Pedro Alves <palves@redhat.com>
To: Christian Biesinger <cbiesinger@google.com>
Cc: gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Change some arguments to gdb::string_view instead of name+len
Date: Tue, 01 Oct 2019 19:10:00 -0000 [thread overview]
Message-ID: <b96e101c-37d3-c5f0-dbe3-9ac89c61e805@redhat.com> (raw)
In-Reply-To: <CAPTJ0XHCohWOX-XR1MLT6BWSF7wHv6uCXyiqQqCoGO+uZftSGA@mail.gmail.com>
On 10/1/19 7:27 PM, Christian Biesinger via gdb-patches wrote:
> On Tue, Oct 1, 2019 at 1:23 PM Pedro Alves <palves@redhat.com> wrote:
>>
>> On 10/1/19 6:33 PM, Christian Biesinger via gdb-patches wrote:
>>> - if (linkage_name[len] != '\0')
>>> + /* Don't use string_view::operator[] because we are accessing beyond
>>> + the size of the string_view, which is technically unsupported. */
>>> + if (linkage_name.data ()[linkage_name.length ()] != '\0')
>>> {
>>> char *alloc_name;
>>
>> It's more than just unsupported, it's undefined behavior. If we're promising
>> the string_view interface, then it's supposedly valid to pass in a string_view
>> that happens to point just at the end of a page, with the one-past-the-end
>> byte living in an unmapped page. Dereferencing the one-past-end byte in
>> that case SIGSEGVs.
>
> That's true (though also a pre-existing issue).
>
>>> - if (ms_type == mst_file_text && startswith (name, "__gnu_compiled"))
>>> + if (ms_type == mst_file_text && startswith (name.data (), "__gnu_compiled"))
>>> return (NULL);
>>>
>>
>> This, via startswith also assumes that name.data() is a null-terminated
>> string.
>
> Ah yes. I'll add a startswith version that takes string_views.
>
>> I wonder whether we should have a zstring_view type. like string_view, but
>> assumes/requires null-terminated.
>
> How does that solve anything? This function can (apparently) take
> non-null terminated strings, so zstring_view wouldn't work?
Ah, right.
Hmm.
I wonder then, I assume that the caller up the stack should know whether
the string was originally null terminated? I wonder about tweaking the
interface to pass that info down somehow.
Are those cases the ones where you call strlen at the caller?
Like, the interface could be:
/* ... If LEN is -1, then LINKAGE_NAME is a null-terminated string.
Otherwise, LINKAGE_NAME is a pointer to a string of LEN length,
and not null-terminated. ... */
void
symbol_set_names (struct general_symbol_info *gsymbol,
const char *linkage_name, int len, int copy_name,
struct objfile_per_bfd_storage *per_bfd)
{
So effectively, you'd be pushing the strlen call down to
symbol_set_names.
This goes against the idea of using string_view here, though...
Thanks,
Pedro Alves
next prev parent reply other threads:[~2019-10-01 19:10 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-29 5:34 Christian Biesinger via gdb-patches
2019-09-30 14:28 ` Tom Tromey
2019-09-30 14:38 ` Pedro Alves
2019-09-30 16:23 ` Tom Tromey
2019-09-30 19:33 ` Christian Biesinger via gdb-patches
2019-09-30 19:33 ` [PATCH v2] " Christian Biesinger via gdb-patches
2019-09-30 19:46 ` [PATCH v3] " Christian Biesinger via gdb-patches
2019-09-30 20:02 ` [PATCH v4] " Christian Biesinger via gdb-patches
2019-10-01 17:18 ` Tom Tromey
2019-10-01 17:26 ` Christian Biesinger via gdb-patches
2019-10-01 17:26 ` [PATCH] " Christian Biesinger via gdb-patches
2019-10-01 17:33 ` Christian Biesinger via gdb-patches
2019-10-01 18:23 ` Pedro Alves
2019-10-01 18:27 ` Christian Biesinger via gdb-patches
2019-10-01 18:31 ` Christian Biesinger via gdb-patches
2019-10-01 19:10 ` Pedro Alves [this message]
2019-10-01 19:30 ` Christian Biesinger via gdb-patches
2019-10-02 14:45 ` Pedro Alves
2019-10-02 18:44 ` Christian Biesinger via gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b96e101c-37d3-c5f0-dbe3-9ac89c61e805@redhat.com \
--to=palves@redhat.com \
--cc=cbiesinger@google.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox