Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sources.redhat.com
Subject: RFA: fix two field name completion bugs
Date: Sun, 08 Jun 2008 18:41:00 -0000	[thread overview]
Message-ID: <m33ann93c7.fsf@fleche.redhat.com> (raw)

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


             reply	other threads:[~2008-06-08 18:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-08 18:41 Tom Tromey [this message]
2008-06-09 19:15 ` Daniel Jacobowitz
2008-06-09 19:26   ` Tom Tromey
2008-06-09 22:40     ` Daniel Jacobowitz
2008-06-09 22:50       ` 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=m33ann93c7.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sources.redhat.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