From: Tom Tromey <tromey@redhat.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: Doug Evans <dje@sebabeach.org>,
msnyder@vmware.com, gdb-patches@sourceware.org
Subject: Patch: completion -vs- deprecated commands (Was: [RFA] target record_core -> target record-core?)
Date: Fri, 23 Apr 2010 20:40:00 -0000 [thread overview]
Message-ID: <m3mxwtykcq.fsf_-_@fleche.redhat.com> (raw)
In-Reply-To: <20100420181116.GU19194@adacore.com> (Joel Brobecker's message of "Tue, 20 Apr 2010 14:11:16 -0400")
Tom> One more thing I've wanted is also making it so deprecated commands
Tom> don't show up in completion when there is a non-deprecated completion
Tom> available. Any comments on that?
Joel> I think that would be useful indeed.
Here's the patch. It looks big because I had to reindent a loop.
I plan to commit this early next week, barring objections or comments.
Built and regtested on x86-64 (compile farm).
New tests included.
Tom
2010-04-23 Tom Tromey <tromey@redhat.com>
* cli/cli-decode.c (complete_on_cmdlist): Make two passes over the
command list.
2010-04-23 Tom Tromey <tromey@redhat.com>
* gdb.base/completion.exp: Add tests for completion and deprecated
commands.
Index: cli/cli-decode.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-decode.c,v
retrieving revision 1.86
diff -u -r1.86 cli-decode.c
--- cli/cli-decode.c 1 Jan 2010 07:31:46 -0000 1.86
+++ cli/cli-decode.c 23 Apr 2010 20:17:41 -0000
@@ -1597,43 +1597,65 @@
int sizeof_matchlist;
int matches;
int textlen = strlen (text);
+ int pass;
+ int saw_deprecated_match = 0;
sizeof_matchlist = 10;
matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
matches = 0;
- for (ptr = list; ptr; ptr = ptr->next)
- if (!strncmp (ptr->name, text, textlen)
- && !ptr->abbrev_flag
- && (ptr->func
- || ptr->prefixlist))
- {
- if (matches == sizeof_matchlist)
- {
- sizeof_matchlist *= 2;
- matchlist = (char **) xrealloc ((char *) matchlist,
- (sizeof_matchlist
- * sizeof (char *)));
- }
-
- matchlist[matches] = (char *)
- xmalloc (strlen (word) + strlen (ptr->name) + 1);
- if (word == text)
- strcpy (matchlist[matches], ptr->name);
- else if (word > text)
- {
- /* Return some portion of ptr->name. */
- strcpy (matchlist[matches], ptr->name + (word - text));
- }
- else
- {
- /* Return some of text plus ptr->name. */
- strncpy (matchlist[matches], word, text - word);
- matchlist[matches][text - word] = '\0';
- strcat (matchlist[matches], ptr->name);
- }
- ++matches;
- }
+ /* We do one or two passes. In the first pass, we skip deprecated
+ commands. If we see no matching commands in the first pass, and
+ if we did happen to see a matching deprecated command, we do
+ another loop to collect those. */
+ for (pass = 0; matches == 0 && pass < 2; ++pass)
+ {
+ for (ptr = list; ptr; ptr = ptr->next)
+ if (!strncmp (ptr->name, text, textlen)
+ && !ptr->abbrev_flag
+ && (ptr->func
+ || ptr->prefixlist))
+ {
+ if (pass == 0)
+ {
+ if ((ptr->flags & CMD_DEPRECATED) != 0)
+ {
+ saw_deprecated_match = 1;
+ continue;
+ }
+ }
+
+ if (matches == sizeof_matchlist)
+ {
+ sizeof_matchlist *= 2;
+ matchlist = (char **) xrealloc ((char *) matchlist,
+ (sizeof_matchlist
+ * sizeof (char *)));
+ }
+
+ matchlist[matches] = (char *)
+ xmalloc (strlen (word) + strlen (ptr->name) + 1);
+ if (word == text)
+ strcpy (matchlist[matches], ptr->name);
+ else if (word > text)
+ {
+ /* Return some portion of ptr->name. */
+ strcpy (matchlist[matches], ptr->name + (word - text));
+ }
+ else
+ {
+ /* Return some of text plus ptr->name. */
+ strncpy (matchlist[matches], word, text - word);
+ matchlist[matches][text - word] = '\0';
+ strcat (matchlist[matches], ptr->name);
+ }
+ ++matches;
+ }
+ /* If we saw no matching deprecated commands in the first pass,
+ just bail out. */
+ if (!saw_deprecated_match)
+ break;
+ }
if (matches == 0)
{
Index: testsuite/gdb.base/completion.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/completion.exp,v
retrieving revision 1.44
diff -u -r1.44 completion.exp
--- testsuite/gdb.base/completion.exp 4 Apr 2010 23:47:16 -0000 1.44
+++ testsuite/gdb.base/completion.exp 23 Apr 2010 20:17:43 -0000
@@ -847,6 +847,12 @@
eof { fail "(eof) Completing non-existing component #2" }
}
+# If there is a non-deprecated completion, it should be returned.
+gdb_test "complete sav" "save" "test non-deprecated completion"
+# If there is only a deprecated completion, then it should be returned.
+gdb_test "complete save-t" "save-tracepoints" "test deprecated completion"
+
+
# Restore globals modified in this test...
set timeout $oldtimeout1
next prev parent reply other threads:[~2010-04-23 20:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-19 6:47 [RFA] target record_core -> target record-core? Doug Evans
2010-04-19 18:01 ` Michael Snyder
2010-04-20 9:56 ` Pedro Alves
2010-04-20 12:24 ` Hui Zhu
2010-04-20 18:06 ` Tom Tromey
2010-04-20 18:11 ` Joel Brobecker
2010-04-23 20:40 ` Tom Tromey [this message]
2010-04-26 18:37 ` Patch: completion -vs- deprecated commands Tom Tromey
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=m3mxwtykcq.fsf_-_@fleche.redhat.com \
--to=tromey@redhat.com \
--cc=brobecker@adacore.com \
--cc=dje@sebabeach.org \
--cc=gdb-patches@sourceware.org \
--cc=msnyder@vmware.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).