]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/ada-lang.c
Move logic out of symbol_find_demangled_name
[thirdparty/binutils-gdb.git] / gdb / ada-lang.c
index 796dc6536ef0d217c9d605304d98a9d9879f9c16..b22b7ac78ce9768d448431d68464a4d6f1eb3113 100644 (file)
@@ -1452,6 +1452,45 @@ ada_la_decode (const char *encoded, int options)
   return xstrdup (ada_decode (encoded));
 }
 
+/* Implement la_sniff_from_mangled_name for Ada.  */
+
+static int
+ada_sniff_from_mangled_name (const char *mangled, char **out)
+{
+  const char *demangled = ada_decode (mangled);
+
+  *out = NULL;
+
+  if (demangled != mangled && demangled != NULL && demangled[0] != '<')
+    {
+      /* Set the gsymbol language to Ada, but still return 0.
+        Two reasons for that:
+
+        1. For Ada, we prefer computing the symbol's decoded name
+        on the fly rather than pre-compute it, in order to save
+        memory (Ada projects are typically very large).
+
+        2. There are some areas in the definition of the GNAT
+        encoding where, with a bit of bad luck, we might be able
+        to decode a non-Ada symbol, generating an incorrect
+        demangled name (Eg: names ending with "TB" for instance
+        are identified as task bodies and so stripped from
+        the decoded name returned).
+
+        Returning 1, here, but not setting *DEMANGLED, helps us get a
+        little bit of the best of both worlds.  Because we're last,
+        we should not affect any of the other languages that were
+        able to demangle the symbol before us; we get to correctly
+        tag Ada symbols as such; and even if we incorrectly tagged a
+        non-Ada symbol, which should be rare, any routing through the
+        Ada language should be transparent (Ada tries to behave much
+        like C/C++ with non-Ada symbols).  */
+      return 1;
+    }
+
+  return 0;
+}
+
 /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing
    suffixes that encode debugging information or leading _ada_ on
    SYM_NAME (see is_name_suffix commentary for the debugging
@@ -14086,6 +14125,7 @@ const struct language_defn ada_language_defn = {
   ada_lookup_symbol_nonlocal,   /* Looking up non-local symbols.  */
   basic_lookup_transparent_type,        /* lookup_transparent_type */
   ada_la_decode,                /* Language specific symbol demangler */
+  ada_sniff_from_mangled_name,
   NULL,                         /* Language specific
                                   class_name_from_physname */
   ada_op_print_tab,             /* expression operators for printing */