This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Make the linespec/location completer ignore data symbols


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f9d67a22392f8f52c779f68a2561eb35c2f86b81

commit f9d67a22392f8f52c779f68a2561eb35c2f86b81
Author: Pedro Alves <palves@redhat.com>
Date:   Wed Nov 8 14:22:34 2017 +0000

    Make the linespec/location completer ignore data symbols
    
    Currently "b foo[TAB]" offers data symbols as completion candidates.
    This doesn't make sense, since you can't set a breakpoint on data
    symbols, only on code symbols.
    
     (gdb) b globa[TAB]
     (gdb) b global [ENTER]
     Function "global" not defined.
     Make breakpoint pending on future shared library load? (y or [n]) n
     (gdb) info symbol global
     global in section .rodata
    
    So this patch makes linespec completion ignore data symbols.
    
    gdb/ChangeLog:
    2017-11-08  Pedro Alves  <palves@redhat.com>
    
    	* ada-lang.c (ada_make_symbol_completion_list): Use
    	completion_skip_symbol.
    	* symtab.c (symbol_is_function_or_method(minimal_symbol*)): New.
    	(symbol_is_function_or_method(symbol*)): New.
    	(add_symtab_completions): Add complete_symbol_mode parameter.  Use
    	completion_skip_symbol.
    	(default_collect_symbol_completion_matches_break_on): Use
    	completion_skip_symbol.  Pass down mode.
    	(collect_file_symbol_completion_matches): Pass down mode.
    	* symtab.h (symbol_is_function_or_method): New declarations.
    	(completion_skip_symbol): New template function.

Diff:
---
 gdb/ChangeLog  | 14 ++++++++++++++
 gdb/ada-lang.c | 12 ++++++++++++
 gdb/symtab.c   | 45 ++++++++++++++++++++++++++++++++++++++++++---
 gdb/symtab.h   | 20 ++++++++++++++++++++
 4 files changed, 88 insertions(+), 3 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 38cfccb..a26afa4 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,19 @@
 2017-11-08  Pedro Alves  <palves@redhat.com>
 
+	* ada-lang.c (ada_make_symbol_completion_list): Use
+	completion_skip_symbol.
+	* symtab.c (symbol_is_function_or_method(minimal_symbol*)): New.
+	(symbol_is_function_or_method(symbol*)): New.
+	(add_symtab_completions): Add complete_symbol_mode parameter.  Use
+	completion_skip_symbol.
+	(default_collect_symbol_completion_matches_break_on): Use
+	completion_skip_symbol.  Pass down mode.
+	(collect_file_symbol_completion_matches): Pass down mode.
+	* symtab.h (symbol_is_function_or_method): New declarations.
+	(completion_skip_symbol): New template function.
+
+2017-11-08  Pedro Alves  <palves@redhat.com>
+
 	* linespec.c (iterate_over_all_matching_symtabs): Add
 	search_domain parameter.  Pass it down to expand_symtabs_matching.
 	(decode_objc): Request FUNCTIONS_DOMAIN symbols only.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 9ebd25e..7494733 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -6472,6 +6472,9 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
   {
     QUIT;
 
+    if (completion_skip_symbol (mode, msymbol))
+      continue;
+
     completion_list_add_name (tracker,
 			      MSYMBOL_LANGUAGE (msymbol),
 			      MSYMBOL_LINKAGE_NAME (msymbol),
@@ -6488,6 +6491,9 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
 
       ALL_BLOCK_SYMBOLS (b, iter, sym)
       {
+	if (completion_skip_symbol (mode, sym))
+	  continue;
+
 	completion_list_add_name (tracker,
 				  SYMBOL_LANGUAGE (sym),
 				  SYMBOL_LINKAGE_NAME (sym),
@@ -6504,6 +6510,9 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
     b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), GLOBAL_BLOCK);
     ALL_BLOCK_SYMBOLS (b, iter, sym)
     {
+      if (completion_skip_symbol (mode, sym))
+	continue;
+
       completion_list_add_name (tracker,
 				SYMBOL_LANGUAGE (sym),
 				SYMBOL_LINKAGE_NAME (sym),
@@ -6520,6 +6529,9 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
       continue;
     ALL_BLOCK_SYMBOLS (b, iter, sym)
     {
+      if (completion_skip_symbol (mode, sym))
+	continue;
+
       completion_list_add_name (tracker,
 				SYMBOL_LANGUAGE (sym),
 				SYMBOL_LINKAGE_NAME (sym),
diff --git a/gdb/symtab.c b/gdb/symtab.c
index eb4e30d..ebb7fbe 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4877,11 +4877,44 @@ completion_list_add_fields (completion_tracker &tracker,
     }
 }
 
+/* See symtab.h.  */
+
+bool
+symbol_is_function_or_method (symbol *sym)
+{
+  switch (TYPE_CODE (SYMBOL_TYPE (sym)))
+    {
+    case TYPE_CODE_FUNC:
+    case TYPE_CODE_METHOD:
+      return true;
+    default:
+      return false;
+    }
+}
+
+/* See symtab.h.  */
+
+bool
+symbol_is_function_or_method (minimal_symbol *msymbol)
+{
+  switch (MSYMBOL_TYPE (msymbol))
+    {
+    case mst_text:
+    case mst_text_gnu_ifunc:
+    case mst_solib_trampoline:
+    case mst_file_text:
+      return true;
+    default:
+      return false;
+    }
+}
+
 /* Add matching symbols from SYMTAB to the current completion list.  */
 
 static void
 add_symtab_completions (struct compunit_symtab *cust,
 			completion_tracker &tracker,
+			complete_symbol_mode mode,
 			const lookup_name_info &lookup_name,
 			const char *text, const char *word,
 			enum type_code code)
@@ -4900,6 +4933,9 @@ add_symtab_completions (struct compunit_symtab *cust,
       b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), i);
       ALL_BLOCK_SYMBOLS (b, iter, sym)
 	{
+	  if (completion_skip_symbol (mode, sym))
+	    continue;
+
 	  if (code == TYPE_CODE_UNDEF
 	      || (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
 		  && TYPE_CODE (SYMBOL_TYPE (sym)) == code))
@@ -4998,6 +5034,9 @@ default_collect_symbol_completion_matches_break_on
 	{
 	  QUIT;
 
+	  if (completion_skip_symbol (mode, msymbol))
+	    continue;
+
 	  completion_list_add_msymbol (tracker, msymbol, lookup_name,
 				       sym_text, word);
 
@@ -5008,7 +5047,7 @@ default_collect_symbol_completion_matches_break_on
 
   /* Add completions for all currently loaded symbol tables.  */
   ALL_COMPUNITS (objfile, cust)
-    add_symtab_completions (cust, tracker, lookup_name,
+    add_symtab_completions (cust, tracker, mode, lookup_name,
 			    sym_text, word, code);
 
   /* Look through the partial symtabs for all symbols which begin by
@@ -5019,7 +5058,7 @@ default_collect_symbol_completion_matches_break_on
 			   [&] (compunit_symtab *symtab) /* expansion notify */
 			     {
 			       add_symtab_completions (symtab,
-						       tracker, lookup_name,
+						       tracker, mode, lookup_name,
 						       sym_text, word, code);
 			     },
 			   ALL_DOMAIN);
@@ -5225,7 +5264,7 @@ collect_file_symbol_completion_matches (completion_tracker &tracker,
   iterate_over_symtabs (srcfile, [&] (symtab *s)
     {
       add_symtab_completions (SYMTAB_COMPUNIT (s),
-			      tracker, lookup_name,
+			      tracker, mode, lookup_name,
 			      sym_text, word, TYPE_CODE_UNDEF);
       return false;
     });
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 868c435..7b8b5cc 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1803,6 +1803,26 @@ extern void collect_file_symbol_completion_matches
 extern completion_list
   make_source_files_completion_list (const char *, const char *);
 
+/* Return whether SYM is a function/method, as opposed to a data symbol.  */
+
+extern bool symbol_is_function_or_method (symbol *sym);
+
+/* Return whether MSYMBOL is a function/method, as opposed to a data
+   symbol */
+
+extern bool symbol_is_function_or_method (minimal_symbol *msymbol);
+
+/* Return whether SYM should be skipped in completion mode MODE.  In
+   linespec mode, we're only interested in functions/methods.  */
+
+template<typename Symbol>
+static bool
+completion_skip_symbol (complete_symbol_mode mode, Symbol *sym)
+{
+  return (mode == complete_symbol_mode::LINESPEC
+	  && !symbol_is_function_or_method (sym));
+}
+
 /* symtab.c */
 
 int matching_obj_sections (struct obj_section *, struct obj_section *);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]