public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Christian Biesinger <cbiesinger@google.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: Simon Marchi <simon.marchi@efficios.com>,
	gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 1/4] gdb: add intern method to objfile_per_bfd_storage
Date: Tue, 23 Mar 2021 16:53:49 +0100	[thread overview]
Message-ID: <CAPTJ0XHwRfak_OFiaeJwCAJfbHHXqNbDXfZYgNa4HnJRG7Tn=Q@mail.gmail.com> (raw)
In-Reply-To: <13c62035-c0e2-06cf-aeb7-4ae515b90c27@polymtl.ca>

On Tue, Mar 23, 2021 at 4:49 PM Simon Marchi <simon.marchi@polymtl.ca> wrote:
>
> On 2021-03-23 10:47 a.m., Christian Biesinger via Gdb-patches wrote:
> > On Mon, Mar 22, 2021 at 8:34 PM Simon Marchi via Gdb-patches
> > <gdb-patches@sourceware.org> wrote:
> >>
> >> From: Simon Marchi <simon.marchi@polymtl.ca>
> >>
> >> This allows factoring out the internal implementation details that are
> >> currently in the two objfile::intern methods.
> >>
> >> gdb/ChangeLog:
> >>
> >>         * objfiles.h (struct objfile_per_bfd_storage) <intern>: New
> >>         method.
> >>         (struct objfile) <intern>: Use
> >>         objfile::objfile_per_bfd_storage::intern.
> >>
> >> Change-Id: Ifd54026c5efaeffafac9b84ff84c199acc7ce78a
> >> ---
> >>  gdb/objfiles.h | 13 ++++++++++---
> >>  1 file changed, 10 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/gdb/objfiles.h b/gdb/objfiles.h
> >> index 41f8fc913d8..d9aa06636f5 100644
> >> --- a/gdb/objfiles.h
> >> +++ b/gdb/objfiles.h
> >> @@ -270,6 +270,14 @@ struct objfile_per_bfd_storage
> >>
> >>    ~objfile_per_bfd_storage ();
> >>
> >> +  /* Intern STRING in this object's string cache and return the unique copy.
> >> +     The copy has the same lifetime as this object.  */
> >> +
> >> +  const char *intern (gdb::string_view str)
> >> +  {
> >> +    return (const char *) string_cache.insert (str.data (), str.size () + 1);
> >
> > Is this guaranteed to be nullterminated even without calling c_str()?
> >
> > Christian
>
> From what I remember from last time something like this came up (I can't
> remember the context) is that we'd only use string_view for strings that
> are null-terminated, even though string_view doesn't guarantee it.  Is
> that the case?  Or is it a bad use case for string_view?

Hm, I'm not sure we concluded that in the general case. It came up
specifically for general_symbol_info::compute_and_set_names, which can
handle the case where it may or may not be nullterminated depending on
a parameter. IMO you should at least comment that the string view must
be nullterminated here.

> In this particular case, callers of this intern method have a C string
> and an std::string, so we know they are null-terminated.

OK, makes sense.

Christian

  reply	other threads:[~2021-03-23 15:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 19:34 [PATCH 0/4] Small Misc psymtabs / objfile cleanups Simon Marchi
2021-03-22 19:34 ` [PATCH 1/4] gdb: add intern method to objfile_per_bfd_storage Simon Marchi
2021-03-23 14:47   ` Christian Biesinger
2021-03-23 15:48     ` Simon Marchi
2021-03-23 15:53       ` Christian Biesinger [this message]
2021-03-23 16:08         ` Simon Marchi
2021-04-01 17:44       ` Tom Tromey
2021-04-02 15:38         ` Simon Marchi
2021-03-22 19:34 ` [PATCH 2/4] gdb: use std::string in partial_symtab::partial_symtab / allocate_symtab Simon Marchi
2021-04-01 17:43   ` Tom Tromey
2021-03-22 19:34 ` [PATCH 3/4] gdb: pass objfile_per_bfd_storage instead of objfile to partial_symtab Simon Marchi
2021-04-01 17:47   ` Tom Tromey
2021-04-02 15:42     ` Simon Marchi
2021-03-22 19:34 ` [PATCH 4/4] gdb: remove objfile parameter from get_objfile_bfd_data Simon Marchi
2021-04-01 17:52   ` Tom Tromey
2021-04-02 15:52     ` Simon Marchi

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='CAPTJ0XHwRfak_OFiaeJwCAJfbHHXqNbDXfZYgNa4HnJRG7Tn=Q@mail.gmail.com' \
    --to=cbiesinger@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    --cc=simon.marchi@polymtl.ca \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).