Don't remove C++ aliases from completions if symbol doesn't match
authorPedro Alves <palves@redhat.com>
Sun, 24 May 2020 12:32:25 +0000 (13:32 +0100)
committerPedro Alves <palves@redhat.com>
Sun, 24 May 2020 12:32:25 +0000 (13:32 +0100)
completion_list_add_symbol currently tries to remove C++ function
aliases from the completions match list even if the symbol passed down
wasn't successfully added to the completion list because it didn't
match.  I.e., we call cp_canonicalize_string_no_typedefs for each and
every C++ function in the program, which is useful work.  This patch
skips that useless work.

gdb/ChangeLog:
2020-05-24  Pedro Alves  <palves@redhat.com>

* symtab.c (completion_list_add_name): Return boolean indication
of whether the symbol matched.
(completion_list_add_symbol): Don't try to remove C++ aliases if
the symbol didn't match in the first place.
* symtab.h (completion_list_add_name): Return bool.

gdb/ChangeLog
gdb/symtab.c
gdb/symtab.h

index 35fdc614ee47cac95c80ee5f7619e0c1da411407..9f65e2df97005471aebef138ccc3f0b8f6a046e0 100644 (file)
@@ -1,3 +1,11 @@
+2020-05-24  Pedro Alves  <palves@redhat.com>
+
+       * symtab.c (completion_list_add_name): Return boolean indication
+       of whether the symbol matched.
+       (completion_list_add_symbol): Don't try to remove C++ aliases if
+       the symbol didn't match in the first place.
+       * symtab.h (completion_list_add_name): Return bool.
+
 2020-05-23  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * gdbtypes.h (TYPE_FIELD): Remove.  Replace all uses with
index 3f90ea996478db072983b6450732679ca0bff34f..5c4e282c0246262d0f9d5de74a35c2a0fadcb812 100644 (file)
@@ -5260,7 +5260,7 @@ compare_symbol_name (const char *symbol_name, language symbol_language,
 
 /*  See symtab.h.  */
 
-void
+bool
 completion_list_add_name (completion_tracker &tracker,
                          language symbol_language,
                          const char *symname,
@@ -5272,7 +5272,7 @@ completion_list_add_name (completion_tracker &tracker,
 
   /* Clip symbols that cannot match.  */
   if (!compare_symbol_name (symname, symbol_language, lookup_name, match_res))
-    return;
+    return false;
 
   /* Refresh SYMNAME from the match string.  It's potentially
      different depending on language.  (E.g., on Ada, the match may be
@@ -5296,6 +5296,8 @@ completion_list_add_name (completion_tracker &tracker,
     tracker.add_completion (std::move (completion),
                            &match_res.match_for_lcd, text, word);
   }
+
+  return true;
 }
 
 /* completion_list_add_name wrapper for struct symbol.  */
@@ -5306,9 +5308,10 @@ completion_list_add_symbol (completion_tracker &tracker,
                            const lookup_name_info &lookup_name,
                            const char *text, const char *word)
 {
-  completion_list_add_name (tracker, sym->language (),
-                           sym->natural_name (),
-                           lookup_name, text, word);
+  if (!completion_list_add_name (tracker, sym->language (),
+                                sym->natural_name (),
+                                lookup_name, text, word))
+    return;
 
   /* C++ function symbols include the parameters within both the msymbol
      name and the symbol name.  The problem is that the msymbol name will
index 05e6a311b875b5d1fccb812730cf06b8b89cf80e..9972e8125ba0e845a6b5a674e4f14c0803159954 100644 (file)
@@ -2332,8 +2332,9 @@ const char *
 /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
    SYMNAME (which is already demangled for C++ symbols) matches
    SYM_TEXT in the first SYM_TEXT_LEN characters.  If so, add it to
-   the current completion list.  */
-void completion_list_add_name (completion_tracker &tracker,
+   the current completion list and return true.  Otherwise, return
+   false.  */
+bool completion_list_add_name (completion_tracker &tracker,
                               language symbol_language,
                               const char *symname,
                               const lookup_name_info &lookup_name,