public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 06/17] Add language to cooked_index_entry
Date: Sun, 10 Dec 2023 09:44:55 -0700	[thread overview]
Message-ID: <20231210-debug-names-fix-v1-6-a8f6d2525018@tromey.com> (raw)
In-Reply-To: <20231210-debug-names-fix-v1-0-a8f6d2525018@tromey.com>

This adds a new 'lang' member to cooked_index_entry.  This holds the
language of the symbol.  This is primarily useful for the new
.debug_names reader, which will not scan the CUs for languages up
front.

This also changes cooked_index_shard::add to return a non-const
pointer.  This doesn't impact the current code, but is needed for the
new reader.
---
 gdb/dwarf2/cooked-index.c | 24 ++++++++++++------------
 gdb/dwarf2/cooked-index.h | 32 +++++++++++++++++++-------------
 gdb/dwarf2/index-write.c  |  4 ++--
 3 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index e59835ea11f..d32fb360a4b 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -206,7 +206,7 @@ cooked_index_entry::full_name (struct obstack *storage, bool for_main) const
     return local_name;
 
   const char *sep = nullptr;
-  switch (per_cu->lang ())
+  switch (lang)
     {
     case language_cplus:
     case language_rust:
@@ -244,13 +244,14 @@ cooked_index_entry::write_scope (struct obstack *storage,
 
 /* See cooked-index.h.  */
 
-const cooked_index_entry *
+cooked_index_entry *
 cooked_index_shard::add (sect_offset die_offset, enum dwarf_tag tag,
-			 cooked_index_flag flags, const char *name,
+			 cooked_index_flag flags, enum language lang,
+			 const char *name,
 			 const cooked_index_entry *parent_entry,
 			 dwarf2_per_cu_data *per_cu)
 {
-  cooked_index_entry *result = create (die_offset, tag, flags, name,
+  cooked_index_entry *result = create (die_offset, tag, flags, lang, name,
 				       parent_entry, per_cu);
   m_entries.push_back (result);
 
@@ -260,7 +261,7 @@ cooked_index_shard::add (sect_offset die_offset, enum dwarf_tag tag,
     m_main = result;
   else if (parent_entry == nullptr
 	   && m_main == nullptr
-	   && language_may_use_plain_main (per_cu->lang ())
+	   && language_may_use_plain_main (lang)
 	   && strcmp (name, "main") == 0)
     m_main = result;
 
@@ -299,7 +300,7 @@ cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
 	  gdb::unique_xmalloc_ptr<char> new_name
 	    = make_unique_xstrndup (name.data (), name.length ());
 	  last = create (entry->die_offset, DW_TAG_namespace,
-			 0, new_name.get (), parent,
+			 0, language_ada, new_name.get (), parent,
 			 entry->per_cu);
 	  last->canonical = last->name;
 	  m_names.push_back (std::move (new_name));
@@ -362,7 +363,7 @@ cooked_index_shard::finalize ()
       gdb_assert (entry->canonical == nullptr);
       if ((entry->flags & IS_LINKAGE) != 0)
 	entry->canonical = entry->name;
-      else if (entry->per_cu->lang () == language_ada)
+      else if (entry->lang == language_ada)
 	{
 	  gdb::unique_xmalloc_ptr<char> canon_name
 	    = handle_gnat_encoded_entry (entry, gnat_entries.get ());
@@ -374,15 +375,14 @@ cooked_index_shard::finalize ()
 	      m_names.push_back (std::move (canon_name));
 	    }
 	}
-      else if (entry->per_cu->lang () == language_cplus
-	       || entry->per_cu->lang () == language_c)
+      else if (entry->lang == language_cplus || entry->lang == language_c)
 	{
 	  void **slot = htab_find_slot (seen_names.get (), entry,
 					INSERT);
 	  if (*slot == nullptr)
 	    {
 	      gdb::unique_xmalloc_ptr<char> canon_name
-		= (entry->per_cu->lang () == language_cplus
+		= (entry->lang == language_cplus
 		   ? cp_canonicalize_string (entry->name)
 		   : c_canonicalize_name (entry->name));
 	      if (canon_name == nullptr)
@@ -570,7 +570,7 @@ cooked_index::get_main_name (struct obstack *obstack, enum language *lang)
   if (entry == nullptr)
     return nullptr;
 
-  *lang = entry->per_cu->lang ();
+  *lang = entry->lang;
   return entry->full_name (obstack, true);
 }
 
@@ -593,7 +593,7 @@ cooked_index::get_main () const
 	{
 	  if ((entry->flags & IS_MAIN) != 0)
 	    {
-	      if (!language_requires_canonicalization (entry->per_cu->lang ()))
+	      if (!language_requires_canonicalization (entry->lang))
 		{
 		  /* There won't be one better than this.  */
 		  return entry;
diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index 323c335677b..4e7882204a9 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -85,12 +85,14 @@ extern bool language_requires_canonicalization (enum language lang);
 struct cooked_index_entry : public allocate_on_obstack
 {
   cooked_index_entry (sect_offset die_offset_, enum dwarf_tag tag_,
-		      cooked_index_flag flags_, const char *name_,
+		      cooked_index_flag flags_,
+		      enum language lang_, const char *name_,
 		      const cooked_index_entry *parent_entry_,
 		      dwarf2_per_cu_data *per_cu_)
     : name (name_),
       tag (tag_),
       flags (flags_),
+      lang (lang_),
       die_offset (die_offset_),
       parent_entry (parent_entry_),
       per_cu (per_cu_)
@@ -229,6 +231,8 @@ struct cooked_index_entry : public allocate_on_obstack
   enum dwarf_tag tag;
   /* Any flags attached to this entry.  */
   cooked_index_flag flags;
+  /* The language of this symbol.  */
+  ENUM_BITFIELD (language) lang : LANGUAGE_BITS;
   /* The offset of this DIE.  */
   sect_offset die_offset;
   /* The parent entry.  This is NULL for top-level entries.
@@ -264,11 +268,11 @@ class cooked_index_shard
 
   /* Create a new cooked_index_entry and register it with this object.
      Entries are owned by this object.  The new item is returned.  */
-  const cooked_index_entry *add (sect_offset die_offset, enum dwarf_tag tag,
-				 cooked_index_flag flags,
-				 const char *name,
-				 const cooked_index_entry *parent_entry,
-				 dwarf2_per_cu_data *per_cu);
+  cooked_index_entry *add (sect_offset die_offset, enum dwarf_tag tag,
+			   cooked_index_flag flags, enum language lang,
+			   const char *name,
+			   const cooked_index_entry *parent_entry,
+			   dwarf2_per_cu_data *per_cu);
 
   /* Install a new fixed addrmap from the given mutable addrmap.  */
   void install_addrmap (addrmap_mutable *map)
@@ -316,12 +320,13 @@ class cooked_index_shard
   cooked_index_entry *create (sect_offset die_offset,
 			      enum dwarf_tag tag,
 			      cooked_index_flag flags,
+			      enum language lang,
 			      const char *name,
 			      const cooked_index_entry *parent_entry,
 			      dwarf2_per_cu_data *per_cu)
   {
     return new (&m_storage) cooked_index_entry (die_offset, tag, flags,
-						name, parent_entry,
+						lang, name, parent_entry,
 						per_cu);
   }
 
@@ -379,13 +384,14 @@ class cooked_index_storage
 
   /* Add an entry to the index.  The arguments describe the entry; see
      cooked-index.h.  The new entry is returned.  */
-  const cooked_index_entry *add (sect_offset die_offset, enum dwarf_tag tag,
-				 cooked_index_flag flags,
-				 const char *name,
-				 const cooked_index_entry *parent_entry,
-				 dwarf2_per_cu_data *per_cu)
+  cooked_index_entry *add (sect_offset die_offset, enum dwarf_tag tag,
+			   cooked_index_flag flags,
+			   const char *name,
+			   const cooked_index_entry *parent_entry,
+			   dwarf2_per_cu_data *per_cu)
   {
-    return m_index->add (die_offset, tag, flags, name, parent_entry, per_cu);
+    return m_index->add (die_offset, tag, flags, per_cu->lang (),
+			 name, parent_entry, per_cu);
   }
 
   /* Install the current addrmap into the shard being constructed,
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index b4a0117330e..44728e4216d 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1282,7 +1282,7 @@ write_cooked_index (cooked_index *table,
 
       const char *name = entry->full_name (symtab->obstack ());
 
-      if (entry->per_cu->lang () == language_ada)
+      if (entry->lang == language_ada)
 	{
 	  /* In order for the index to work when read back into
 	     gdb, it has to use the encoded name, with any
@@ -1290,7 +1290,7 @@ write_cooked_index (cooked_index *table,
 	  std::string encoded = ada_encode (name, false);
 	  name = obstack_strdup (symtab->obstack (), encoded.c_str ());
 	}
-      else if (entry->per_cu->lang () == language_cplus
+      else if (entry->lang == language_cplus
 	       && (entry->flags & IS_LINKAGE) != 0)
 	{
 	  /* GDB never put C++ linkage names into .gdb_index.  The

-- 
2.43.0


  parent reply	other threads:[~2023-12-10 16:45 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-10 16:44 [PATCH 00/17] Rewrite .debug_names reader and writer Tom Tromey
2023-12-10 16:44 ` [PATCH 01/17] Refactor 'maint set dwarf synchronous' handling Tom Tromey
2023-12-10 16:44 ` [PATCH 02/17] Refactor quick-function installation in DWARF reader Tom Tromey
2023-12-10 16:44 ` [PATCH 03/17] Remove IS_ENUM_CLASS from cooked_index_flag Tom Tromey
2023-12-10 16:44 ` [PATCH 04/17] Add some new DW_IDX_* values Tom Tromey
2024-01-09 15:08   ` Tom Tromey
2024-01-09 19:02     ` Tom Tromey
2023-12-10 16:44 ` [PATCH 05/17] Document GDB extensions to DWARF .debug_names Tom Tromey
2023-12-10 17:37   ` Eli Zaretskii
2024-01-17 16:24     ` Tom Tromey
2023-12-10 16:44 ` Tom Tromey [this message]
2023-12-10 16:44 ` [PATCH 07/17] Move cooked_index_functions to cooked-index.h Tom Tromey
2023-12-10 16:44 ` [PATCH 08/17] Do not write the index cache from an index Tom Tromey
2023-12-10 16:44 ` [PATCH 09/17] Change cooked_index_worker to abstract base class Tom Tromey
2023-12-10 16:44 ` [PATCH 10/17] Remove cooked_index_worker::start_reading Tom Tromey
2023-12-10 16:45 ` [PATCH 11/17] Empty hash table fix in .debug_names reader Tom Tromey
2023-12-10 16:45 ` [PATCH 12/17] Fix dw2-zero-range.exp when an index is in use Tom Tromey
2023-12-10 16:45 ` [PATCH 13/17] Explicitly expand CUs in dw2-inline-with-lexical-scope.exp Tom Tromey
2023-12-10 16:45 ` [PATCH 14/17] Remove some .debug_names tests Tom Tromey
2023-12-10 16:45 ` [PATCH 15/17] Rewrite .debug_names reader Tom Tromey
2023-12-10 16:45 ` [PATCH 16/17] Export dwarf5_augmentation Tom Tromey
2023-12-10 16:45 ` [PATCH 17/17] Rewrite .debug_names writer Tom Tromey

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=20231210-debug-names-fix-v1-6-a8f6d2525018@tromey.com \
    --to=tom@tromey.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).