public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: Tom Tromey <tom@tromey.com>,
	Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 1/4] gdb: add intern method to objfile_per_bfd_storage
Date: Fri, 2 Apr 2021 11:38:15 -0400	[thread overview]
Message-ID: <292c9d0b-3a96-22b9-705c-e8076efb96e1@efficios.com> (raw)
In-Reply-To: <87eeftq4qt.fsf@tromey.com>



On 2021-04-01 1:44 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> 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 <simon.marchi@polymtl.ca>
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) <intern>: New
	methods.
	(struct objfile) <intern>: 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  <simon.marchi@polymtl.ca>
+
+	* objfiles.h (struct objfile_per_bfd_storage) <intern>: New
+	methods.
+	(struct objfile) <intern>: Use
+	objfile::objfile_per_bfd_storage::intern.
+
 2021-04-01  Simon Marchi  <simon.marchi@efficios.com>
 
 	* 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


  reply	other threads:[~2021-04-02 15:38 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
2021-03-23 16:08         ` Simon Marchi
2021-04-01 17:44       ` Tom Tromey
2021-04-02 15:38         ` Simon Marchi [this message]
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=292c9d0b-3a96-22b9-705c-e8076efb96e1@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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).