From: Keith Seitz <keiths@redhat.com>
To: gdb-patches@sourceware.org
Subject: [RFA] Limit qualified completions
Date: Wed, 19 Aug 2009 01:14:00 -0000 [thread overview]
Message-ID: <4A8B3BB9.2070105@redhat.com> (raw)
[-- 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]
+
next reply other threads:[~2009-08-18 23:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-19 1:14 Keith Seitz [this message]
2009-08-19 5:22 ` Daniel Jacobowitz
2009-08-19 22:02 ` Tom Tromey
2009-08-24 22:27 ` Keith Seitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A8B3BB9.2070105@redhat.com \
--to=keiths@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox