From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by sourceware.org (Postfix) with ESMTPS id E8C383858D33 for ; Fri, 2 Apr 2021 15:38:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E8C383858D33 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id AEA0E2F5498; Fri, 2 Apr 2021 11:38:17 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id H0N3rJZ91Jg5; Fri, 2 Apr 2021 11:38:16 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 6F4EE2F5496; Fri, 2 Apr 2021 11:38:16 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 6F4EE2F5496 X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id C6kq0YDmW6Xz; Fri, 2 Apr 2021 11:38:16 -0400 (EDT) Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by mail.efficios.com (Postfix) with ESMTPSA id 42ED52F5589; Fri, 2 Apr 2021 11:38:16 -0400 (EDT) Subject: Re: [PATCH 1/4] gdb: add intern method to objfile_per_bfd_storage To: Tom Tromey , Simon Marchi via Gdb-patches References: <20210322193417.2376788-1-simon.marchi@efficios.com> <20210322193417.2376788-2-simon.marchi@efficios.com> <13c62035-c0e2-06cf-aeb7-4ae515b90c27@polymtl.ca> <87eeftq4qt.fsf@tromey.com> From: Simon Marchi Message-ID: <292c9d0b-3a96-22b9-705c-e8076efb96e1@efficios.com> Date: Fri, 2 Apr 2021 11:38:15 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <87eeftq4qt.fsf@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP 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: Fri, 02 Apr 2021 15:38:19 -0000 On 2021-04-01 1:44 p.m., Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi via Gdb-patches writes: > > Simon> In this particular case, callers of this intern method have a C string > Simon> and an std::string, so we know they are null-terminated. > > It seems a little dangerous to do this, though, in that someone might > add a call without remembering or checking the invariant. > Maybe it's better to just have 2 overloads on the per-bfd object. Yeah, you're right. I changed the patch to just move the two overloads from objfile to objfile_per_bfd_storage. Here's what I pushed: >From 4a4f97c129b26445ff14d0e5323feeb80610a539 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 2 Apr 2021 11:23:52 -0400 Subject: [PATCH] gdb: add intern methods to objfile_per_bfd_storage This allows keeping the objfile_per_bfd_storage implementation details into objfile_per_bfd_storage, instead of into objfile. And this makes the intern methods usable for code that only has an objfile_per_bfd_storage to work with. gdb/ChangeLog: * objfiles.h (struct objfile_per_bfd_storage) : New methods. (struct objfile) : Use objfile::objfile_per_bfd_storage::intern. Change-Id: Ifd54026c5efaeffafac9b84ff84c199acc7ce78a --- gdb/ChangeLog | 7 +++++++ gdb/objfiles.h | 22 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1bdd652b632a..ac64f5c76099 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2021-04-02 Simon Marchi + + * objfiles.h (struct objfile_per_bfd_storage) : New + methods. + (struct objfile) : Use + objfile::objfile_per_bfd_storage::intern. + 2021-04-01 Simon Marchi * gdbtypes.h (TYPE_FLAG_ENUM): Remove, replace all uses diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 4cd392bd7f02..e8a8b5f6de78 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -270,6 +270,23 @@ 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. + + STRING must be null-terminated. */ + + const char *intern (const char *str) + { + return (const char *) string_cache.insert (str, strlen (str) + 1); + } + + /* Same as the above, but for an std::string. */ + + const char *intern (const std::string &str) + { + return (const char *) string_cache.insert (str.c_str (), str.size () + 1); + } + /* The storage has an obstack of its own. */ auto_obstack storage_obstack; @@ -516,15 +533,14 @@ struct objfile lifetime as the per-BFD object. */ const char *intern (const char *str) { - return (const char *) per_bfd->string_cache.insert (str, strlen (str) + 1); + return per_bfd->intern (str); } /* Intern STRING and return the unique copy. The copy has the same lifetime as the per-BFD object. */ const char *intern (const std::string &str) { - return (const char *) per_bfd->string_cache.insert (str.c_str (), - str.size () + 1); + return per_bfd->intern (str); } /* Retrieve the gdbarch associated with this objfile. */ -- 2.30.1