Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* complete command doesn't work for files...
@ 2003-09-24 23:14 Jim Ingham
  2003-09-24 23:25 ` Joel Brobecker
  2004-01-19 16:22 ` Daniel Jacobowitz
  0 siblings, 2 replies; 9+ messages in thread
From: Jim Ingham @ 2003-09-24 23:14 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 2304 bytes --]

I was looking at this for some other reason (I want to add an 
"interpreter-complete console" type command), and I noticed that 
"complete" and the complete_line function that it relies on don't work 
when the input text is a filename, and contains more that just the 
filename.  You can see this easily, do:

(gdb) file /usr/<TAB><TAB>
X11R6               etc                 info                local       
         share
bin                 games               kerberos            lost+found  
         src
dict                i386-glibc21-linux  lib                 man         
         tmp
doc                 include             libexec             sbin
(gdb) complete file /usr/
(gdb)

That isn't right, you should get:

(gdb) complete file /usr/
file /usr/X11R6
file /usr/bin
file /usr/dict
file /usr/doc
file /usr/etc
file /usr/games
file /usr/i386-glibc21-linux
file /usr/include
file /usr/info
file /usr/kerberos
file /usr/lib
file /usr/libexec
file /usr/local
file /usr/lost+found
file /usr/man
file /usr/sbin
file /usr/share
file /usr/src
file /usr/tmp

The attached patch fixes the bug.

The <TAB><TAB> case works because readline advances the first argument 
of complete_line past the initial command.  But "complete" always 
passes both TEXT and LINE_BUFFER as the whole command.  This patch 
actually does what the comment about file completers above it says it 
intends, namely that we should go to the cursor, and then back up to 
the first file-wordbreak we find.  The old code clearly didn't do 
that...  Both the <TAB> case and the complete case work now.  This also 
makes emacs behave a little better when you try to complete files.

I added a test case for this failure.

ChangeLog
2003-09-24  Jim Ingham  <jingham@apple.com>

       * completer.c (complete_line): For filename completions, when you 
look for
       the last word before the cursor, actually start from the cursor & 
work backwards,
       rather than starting from the word you were handed.  Starting 
from the
       word doesn't work if the input contains more than one word - as 
it does
       in the complete command.

testsuite/ChangeLog
2003-09-24  Jim Ingham  <jingham@apple.com>

       * completion.exp: Test that "complete file ./gdb.base/compl" 
agrees with the
       result from sending a tab.


[-- Attachment #2: complete.patch --]
[-- Type: application/octet-stream, Size: 2032 bytes --]

Index: completer.c
===================================================================
RCS file: /cvs/src/src/gdb/completer.c,v
retrieving revision 1.13
diff -p -r1.13 completer.c
*** completer.c 9 Dec 2002 00:59:26 -0000       1.13
--- completer.c 24 Sep 2003 22:50:34 -0000
*************** complete_line (const char *text, char *l
*** 584,590 ****
                {
                  /* See the commentary above about the specifics
                     of file-name completion.  */
!                 for (p = word;
                       p > tmp_command
                         && strchr (gdb_completer_file_name_break_characters, p[-1]) == NULL;
                       p--)
--- 584,590 ----
                {
                  /* See the commentary above about the specifics
                     of file-name completion.  */
!                 for (p = tmp_command + point - 1;
                       p > tmp_command
                         && strchr (gdb_completer_file_name_break_characters, p[-1]) == NULL;
                       p--)
Index: testsuite/gdb.base/completion.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/completion.exp,v
retrieving revision 1.18
diff -p -r1.18 completion.exp
*** testsuite/gdb.base/completion.exp   7 Aug 2003 17:58:44 -0000       1.18
--- testsuite/gdb.base/completion.exp   24 Sep 2003 22:50:36 -0000
*************** gdb_test "cd ${fullsrcdir}" \
*** 647,652 ****
--- 647,661 ----
           "Working directory [string_to_regexp ${fullsrcdir}].*" \
           "cd to \${srcdir}"
  
+ send_gdb "complete file ./gdb.base/compl\n"
+ sleep 1
+ gdb_expect  {
+     -re "file ./gdb.base/completion\\.exp.*$gdb_prompt $"\
+           { pass "complete-command 'file ./gdb.base/compl'"}
+     -re ".*$gdb_prompt $"       { fail "complete-command 'file ./gdb.base/compl'" }
+     timeout         { fail "(timeout) complete-command 'file ./gdb.base/compl'" }
+ }
+ 
  send_gdb "file ./gdb.base/complet\t"
  sleep 1
  gdb_expect  {

[-- Attachment #3: Type: text/plain, Size: 103 bytes --]



Jim
--
Jim Ingham                                   jingham@apple.com
Developer Tools
Apple Computer

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-02-01  5:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-24 23:14 complete command doesn't work for files Jim Ingham
2003-09-24 23:25 ` Joel Brobecker
2003-09-24 23:30   ` Andrew Cagney
2003-09-25 19:04     ` Jim Ingham
2003-09-25 19:41       ` Andrew Cagney
2003-09-27  4:36         ` Jim Blandy
2004-01-19 16:22 ` Daniel Jacobowitz
2004-01-20 22:19   ` Jim Ingham
2004-02-01  5:51     ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox