From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by sourceware.org (Postfix) with ESMTPS id 6A39B385BF9E for ; Tue, 23 Mar 2021 15:54:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6A39B385BF9E Received: by mail-qk1-x72f.google.com with SMTP id c3so14812687qkc.5 for ; Tue, 23 Mar 2021 08:54:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zbJZxGl5JtwCSPSvyGw6890UoreEgg9EjVk++I7frL4=; b=eMgvByiKS2aAVLTc41gLlPHsAvSrUXDW16Hb9R435kkVIsOecV6pwPV1k+3OTxJh5m 3gsrhKpPiig7CH0tbfSPi9JgHSgm+iq3rKx5Tokx8gOtkm5U5YPwNyJc3ggs+PseyD8M GvtMWO0qbMTCHnSOx08/RSeMCizngWtWsX6gx4gDJG8SZaLnsPQ6iVG2EbkbBVmI+jNq V+YJ4IJCVeAysza9nBuGzFc6acGoBLpXCma7y8WhNbBRD10zT2MpzvIaufHPyjqvNI3k qr2lGGwtCQA2s3PSki3i7k3G26IRV5OdU60n0FSWqKkvw00XtI82mhBpEYpR4JfuiIhI SAOQ== X-Gm-Message-State: AOAM533JXCoSssM0eSEj0qrNuxE+l7InwptEvcJHwwPJaF5KBxr43fqk gVXPPtS/F2DhrgqoiaKDaOmhsm5slgvwUXj2ZtkjmGw0uctIdA== X-Google-Smtp-Source: ABdhPJw3RN1egjSoLvl+B2DbG15W3NMziAigHcn8vagV1bgM62rTW++4ZLg5sw/7OBnL3BBpEvGGGi8dmudIClWNw+4= X-Received: by 2002:a37:88d:: with SMTP id 135mr6024573qki.132.1616514868735; Tue, 23 Mar 2021 08:54:28 -0700 (PDT) MIME-Version: 1.0 References: <20210322193417.2376788-1-simon.marchi@efficios.com> <20210322193417.2376788-2-simon.marchi@efficios.com> <13c62035-c0e2-06cf-aeb7-4ae515b90c27@polymtl.ca> In-Reply-To: <13c62035-c0e2-06cf-aeb7-4ae515b90c27@polymtl.ca> From: Christian Biesinger Date: Tue, 23 Mar 2021 16:53:49 +0100 Message-ID: Subject: Re: [PATCH 1/4] gdb: add intern method to objfile_per_bfd_storage To: Simon Marchi Cc: Simon Marchi , gdb-patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-24.9 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Mar 2021 15:54:39 -0000 On Tue, Mar 23, 2021 at 4:49 PM Simon Marchi 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 > > wrote: > >> > >> From: Simon Marchi > >> > >> 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) : New > >> method. > >> (struct objfile) : 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