]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add "Ada linkage" mode to cooked_index_entry::full_name
authorTom Tromey <tromey@adacore.com>
Tue, 3 Sep 2024 18:53:07 +0000 (12:53 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 6 Mar 2025 21:17:18 +0000 (14:17 -0700)
Unfortunately, due to some details of how the Ada support in gdb
currently works, the DWARF reader will still have to synthesize some
"full name" entries after the cooked index has been constructed.

You can see one particular finding related to this in:

    https://sourceware.org/bugzilla/show_bug.cgi?id=32142

This patch adds a new flag to cooked_index_entry::full_name to enable
the construction of these names.

I hope to redo this part of the Ada support eventually, so that this
code can be removed and the full-name entries simply not created.

gdb/dwarf2/cooked-index.c
gdb/dwarf2/cooked-index.h

index f630d34b92861f79ec475d897837ad858a3be826..2ffa831f2b6cc7c95de3ac2f9d30c1c25d0f19c7 100644 (file)
@@ -222,6 +222,7 @@ cooked_index_entry::matches (domain_search_flags kind) const
 
 const char *
 cooked_index_entry::full_name (struct obstack *storage, bool for_main,
+                              bool for_ada_linkage,
                               const char *default_sep) const
 {
   const char *local_name = for_main ? name : canonical;
@@ -238,9 +239,15 @@ cooked_index_entry::full_name (struct obstack *storage, bool for_main,
       sep = "::";
       break;
 
+    case language_ada:
+      if (for_ada_linkage)
+       {
+         sep = "__";
+         break;
+       }
+      [[fallthrough]];
     case language_go:
     case language_d:
-    case language_ada:
       sep = ".";
       break;
 
@@ -250,7 +257,7 @@ cooked_index_entry::full_name (struct obstack *storage, bool for_main,
       break;
     }
 
-  get_parent ()->write_scope (storage, sep, for_main);
+  get_parent ()->write_scope (storage, sep, for_main, for_ada_linkage);
   obstack_grow0 (storage, local_name, strlen (local_name));
   return (const char *) obstack_finish (storage);
 }
@@ -260,11 +267,14 @@ cooked_index_entry::full_name (struct obstack *storage, bool for_main,
 void
 cooked_index_entry::write_scope (struct obstack *storage,
                                 const char *sep,
-                                bool for_main) const
+                                bool for_main,
+                                bool for_ada_linkage) const
 {
   if (get_parent () != nullptr)
-    get_parent ()->write_scope (storage, sep, for_main);
-  const char *local_name = for_main ? name : canonical;
+    get_parent ()->write_scope (storage, sep, for_main, for_ada_linkage);
+  /* When computing the Ada linkage name, the entry might not have
+     been canonicalized yet, so use the 'name'.  */
+  const char *local_name = (for_main || for_ada_linkage) ? name : canonical;
   obstack_grow (storage, local_name, strlen (local_name));
   obstack_grow (storage, sep, strlen (sep));
 }
index c47f84e7cc8885859fe94ed716ac4b3f1be54b01..68407c84b9be53aab8f75195353b58df758cd437 100644 (file)
@@ -143,10 +143,15 @@ struct cooked_index_entry : public allocate_on_obstack<cooked_index_entry>
      STORAGE.  FOR_MAIN is true if we are computing the name of the
      "main" entry -- one marked DW_AT_main_subprogram.  This matters
      for avoiding name canonicalization and also a related race (if
-     "main" computation is done during finalization).  If the language
+     "main" computation is done during finalization).  If
+     FOR_ADA_LINKAGE is true, then Ada-language symbols will have
+     their "linkage-style" name computed.  The default is
+     source-style.  If the language
      doesn't prescribe a separator, one can be specified using
      DEFAULT_SEP.  */
-  const char *full_name (struct obstack *storage, bool for_main = false,
+  const char *full_name (struct obstack *storage,
+                        bool for_main = false,
+                        bool for_ada_linkage = false,
                         const char *default_sep = nullptr) const;
 
   /* Comparison modes for the 'compare' function.  See the function
@@ -250,10 +255,11 @@ private:
 
   /* A helper method for full_name.  Emits the full scope of this
      object, followed by the separator, to STORAGE.  If this entry has
-     a parent, its write_scope method is called first.  FOR_MAIN is
-     true when computing the name of 'main'; see full_name.  */
+     a parent, its write_scope method is called first.  See full_name
+     for a description of the FOR_MAIN and FOR_ADA_LINKAGE
+     parameters.  */
   void write_scope (struct obstack *storage, const char *sep,
-                   bool for_main) const;
+                   bool for_main, bool for_ada_linkage) const;
 
   /* The parent entry.  This is NULL for top-level entries.
      Otherwise, it points to the parent entry, such as a namespace or