[RFA] Limit qualified completions

Keith Seitz
2009-08-18T23:39:52Z

[-- 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]
+