Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Limit qualified completions
@ 2009-08-19  1:14 Keith Seitz
  2009-08-19  5:22 ` Daniel Jacobowitz
  2009-08-19 22:02 ` Tom Tromey
  0 siblings, 2 replies; 4+ messages in thread
From: Keith Seitz @ 2009-08-19  1:14 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 714 bytes --]

Hi,

If the user attempts to complete symbols in a class or namespace, i.e., 
"complete break foo::", default_make_symbol_completion_list will return 
every single known global symbol in the executable.

This simplistic patch (and test case) "fixes" the problem, limiting the 
matches to the appropriate symbols.

Ok?

Keith

ChangeLog
2009-08-18  Keith Seitz  <keiths@redhat.com>

	* symtab.c (default_make_symbol_completion_list): Keep
	':', too, so that we can limit searches in namespaces
	and classes.

testsuite/ChangeLog
2009-08-18  Keith Seitz  <keiths@redhat.com>

	* gdb.cp/cpcompletion.exp (test_class_complete): New procedure.
	Add two new C++ completer tests which limit the output to a given
	class.

[-- Attachment #2: cpcompletion.patch --]
[-- Type: text/plain, Size: 2308 bytes --]

Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.214
diff -u -p -r1.214 symtab.c
--- symtab.c	23 Jul 2009 16:03:13 -0000	1.214
+++ symtab.c	18 Aug 2009 22:38:24 -0000
@@ -3836,7 +3836,8 @@ default_make_symbol_completion_list (cha
 	   which are in symbols.  */
 	while (p > text)
 	  {
-	    if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
+	    if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0'
+		|| p[-1] == ':')
 	      --p;
 	    else
 	      break;
Index: testsuite/gdb.cp/cpcompletion.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/cpcompletion.exp,v
retrieving revision 1.3
diff -u -p -r1.3 cpcompletion.exp
--- testsuite/gdb.cp/cpcompletion.exp	13 Jul 2009 19:24:18 -0000	1.3
+++ testsuite/gdb.cp/cpcompletion.exp	18 Aug 2009 22:38:24 -0000
@@ -15,6 +15,40 @@
 
 # This file is part of the gdb testsuite.
 
+# A helper procedure to test location completions restricted by
+# class.
+proc test_class_complete {class expr name matches} {
+    global gdb_prompt
+
+    set matches [lsort $matches]
+    set cmd "complete break ${class}::$expr"
+    set seen {}
+    gdb_test_multiple $cmd $name {
+	"break ${class}::main" { fail "$name (saw global symbol)" }
+	$cmd { exp_continue }
+	-re "break ${class}::\[A-Za-z0-9_~\]+" {
+	    set str $expect_out(0,string)
+	    scan $str "break ${class}::%\[^(\]" method
+	    lappend seen $method
+	    exp_continue
+	}
+	-re "$gdb_prompt $" {
+	    set failed ""
+	    foreach got [lsort $seen] have $matches {
+		if {![string equal $got $have]} {
+		    set failed $have
+		    break
+		}
+	    }
+	    if {[string length $failed] != 0} {
+		fail "$name ($failed not found)"
+	    } else {
+		pass $name
+	    }
+	}
+    }
+}
+
 if $tracelevel then {
 	strace $tracelevel
 }
@@ -58,3 +92,11 @@ gdb_test "complete p foo1.Fo" "p foo1\\.
 
 # Test completion with an anonymous struct.
 gdb_test "complete p a.g" "p a\\.get"
+
+# Test that completion is restricted by class name (all methods)
+test_class_complete Foo "" "complete class methods" \
+    [list Foo Foofoo get_foo set_foo ~Foo]
+
+test_class_complete Foo F "complete class methods beginning with F" \
+    [list Foo Foofoo]
+

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-08-24 22:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-19  1:14 [RFA] Limit qualified completions Keith Seitz
2009-08-19  5:22 ` Daniel Jacobowitz
2009-08-19 22:02 ` Tom Tromey
2009-08-24 22:27   ` Keith Seitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox