This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RFA: fix two field name completion bugs
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sun, 08 Jun 2008 12:41:28 -0600
- Subject: RFA: fix two field name completion bugs
- Reply-to: Tom Tromey <tromey at redhat dot com>
After committing the field name completion patch I found a couple
bugs.
One is a huge goof -- I must not have checked the '->' case, since it
didn't work. How embarrassing.
The other is that spaces in the expression could throw off the
completer. The fix is to make sure that the entire expression is
passed to expression_completer, then duplicate some logic there in the
case where location_completer is called.
I added test cases for both of these.
Ok?
Tom
ChangeLog:
2008-06-08 Tom Tromey <tromey@redhat.com>
* completer.c (complete_line): Don't special-case
expression_completer.
(expression_completer): Only pass last word to
location_completer.
* c-exp.y (yylex): Check 'token', not 'operator'.
testsuite/ChangeLog:
2008-06-08 Tom Tromey <tromey@redhat.com>
* gdb.base/completion.exp: New tests for field name completion
with spaces, and field name completion with '->'.
Index: c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.44
diff -u -r1.44 c-exp.y
--- c-exp.y 6 Jun 2008 20:58:08 -0000 1.44
+++ c-exp.y 8 Jun 2008 18:38:48 -0000
@@ -1433,7 +1433,7 @@
{
lexptr += 2;
yylval.opcode = tokentab2[i].opcode;
- if (in_parse_field && tokentab2[i].opcode == ARROW)
+ if (in_parse_field && tokentab2[i].token == ARROW)
last_was_structop = 1;
return tokentab2[i].token;
}
Index: completer.c
===================================================================
RCS file: /cvs/src/src/gdb/completer.c,v
retrieving revision 1.25
diff -u -r1.25 completer.c
--- completer.c 6 Jun 2008 20:58:08 -0000 1.25
+++ completer.c 8 Jun 2008 18:38:48 -0000
@@ -387,7 +387,7 @@
expression_completer (char *text, char *word)
{
struct type *type;
- char *fieldname;
+ char *fieldname, *p;
/* Perform a tentative parse of the expression, to see whether a
field completion is required. */
@@ -418,8 +418,15 @@
}
}
+ /* Commands which complete on locations want to see the entire
+ argument. */
+ for (p = word;
+ p > text && p[-1] != ' ' && p[-1] != '\t';
+ p--)
+ ;
+
/* Not ideal but it is what we used to do before... */
- return location_completer (text, word);
+ return location_completer (p, word);
}
/* Complete on command names. Used by "help". */
@@ -604,8 +611,7 @@
rl_completer_word_break_characters =
gdb_completer_file_name_break_characters;
}
- else if (c->completer == location_completer
- || c->completer == expression_completer)
+ else if (c->completer == location_completer)
{
/* Commands which complete on locations want to
see the entire argument. */
@@ -673,8 +679,7 @@
rl_completer_word_break_characters =
gdb_completer_file_name_break_characters;
}
- else if (c->completer == location_completer
- || c->completer == expression_completer)
+ else if (c->completer == location_completer)
{
for (p = word;
p > tmp_command
Index: testsuite/gdb.base/completion.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/completion.exp,v
retrieving revision 1.30
diff -u -r1.30 completion.exp
--- testsuite/gdb.base/completion.exp 6 Jun 2008 20:58:08 -0000 1.30
+++ testsuite/gdb.base/completion.exp 8 Jun 2008 18:38:50 -0000
@@ -654,6 +654,40 @@
timeout { fail "(timeout) complete 'p values\[0\].a' 2" }
}
+send_gdb "p values\[0\] . a\t"
+sleep 3
+gdb_expect {
+ -re "^p values.0. . a_field $"\
+ { send_gdb "\n"
+ sleep 1
+ gdb_expect {
+ -re "^.* = 0.*$gdb_prompt $"\
+ { pass "complete 'p values\[0\] . a'"}
+ -re ".*$gdb_prompt $" { fail "complete 'p values\[0\] . a'"}
+ timeout {fail "(timeout) complete 'p values\[0\] . a'"}
+ }
+ }
+ -re ".*$gdb_prompt $" { fail "complete 'p values\[0\] . a'" }
+ timeout { fail "(timeout) complete 'p values\[0\] . a' 2" }
+ }
+
+send_gdb "p &values\[0\] -> a\t"
+sleep 3
+gdb_expect {
+ -re "^p &values.0. -> a_field $"\
+ { send_gdb "\n"
+ sleep 1
+ gdb_expect {
+ -re "^.* = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $"\
+ { pass "complete 'p &values\[0\] -> a'"}
+ -re ".*$gdb_prompt $" { fail "complete 'p &values\[0\] -> a'"}
+ timeout {fail "(timeout) complete 'p &values\[0\] -> a'"}
+ }
+ }
+ -re ".*$gdb_prompt $" { fail "complete 'p &values\[0\] -> a'" }
+ timeout { fail "(timeout) complete 'p &values\[0\] -> a' 2" }
+ }
+
# The following tests used to simply try to complete `${objdir}/file',
# and so on. The problem is that ${objdir} can be very long; the
# completed filename may be more than eighty characters wide. When