From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4010 invoked by alias); 11 Mar 2009 10:32:12 -0000 Received: (qmail 4002 invoked by uid 22791); 11 Mar 2009 10:32:11 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,MIME_QP_LONG_LINE X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.155) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Mar 2009 10:32:01 +0000 Received: from baal.u-strasbg.fr (baal.u-strasbg.fr [IPv6:2001:660:2402::41]) by mailhost.u-strasbg.fr (8.14.2/jtpda-5.5pre1) with ESMTP id n2BAVuBF031308 for ; Wed, 11 Mar 2009 11:31:56 +0100 (CET) Received: from mailserver.u-strasbg.fr (ms3.u-strasbg.fr [IPv6:2001:660:2402:d::12]) by baal.u-strasbg.fr (8.14.0/jtpda-5.5pre1) with ESMTP id n2BAVteO055452 for ; Wed, 11 Mar 2009 11:31:56 +0100 (CET) (envelope-from muller@ics.u-strasbg.fr) Received: from d620muller (www-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id n2BAVt31069082 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Wed, 11 Mar 2009 11:31:55 +0100 (CET) (envelope-from muller@ics.u-strasbg.fr) From: "Pierre Muller" To: Subject: [RFC-version3] Fix completion bug for directories Date: Wed, 11 Mar 2009 15:25:00 -0000 Message-ID: <000001c9a234$9e4486e0$dacd94a0$@u-strasbg.fr> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0001_01C9A23D.0008EEE0" Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-03/txt/msg00151.txt.bz2 Il s'agit d'un message ` parties multiples au format MIME. ------=_NextPart_000_0001_01C9A23D.0008EEE0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-length: 2305 This is a new patch to fix the problem with completion on directories. Please see http://sourceware.org/ml/gdb-patches/2008-07/msg00072.html and http://sourceware.org/ml/gdb-patches/2008-07/msg00120.html as these contain previous versions of my patch. To summarize, when you try to complete (gdb) dir /usr/inclu by pressing TAB key, readline completion uses a default set of characters to find out the last 'word' of a command line, and, as '/' is in this set, only 'inclu' is sent as text argument to complete_line. The rl_completion_word_break_hook allows to adapt the set of word_break characters to the current command, and thus suppress '/' from the list if a directory completion is expected. I ran the patch on two computer from the compile farm, to which I now have access and besides the new test that I added that succeeds with my patch and fails without, I do get some random success/failure differences in gdb.threads/schedlock.exp or gdb.threads/attach-into-signal.exp but I understood from other emails that these are non-deterministic tests that do fail/succeed more or less randomly. Pierre Muller Pascal language support maintainer for GDB PS: Apparently, there are no listings of the header dependencies in Makefile.in anymore, I suppose that these are now generated automatically somehow now, is this right? I didn't find anything in the generated Makefile, how does that work? gdb/ChangeLog entry: 2009-03-11 Pierre Muller Fix completer problem for filename completion on the first try. * gdb/completer.h (gdb_completion_word_break_characters): New function. * gdb/completer.c: Include gdb_assert.h. (complete_line_internal_reason): New enum. (complete_line_internal): Change last argument type to complete_line_internal_reason. Modify function to handle the different complete_line_internal_reason argument values. (complete_line): Adapt to change in complete_line_internal. (command_completer): Ditto. (gdb_completion_word_break_characters): Implement new function. * top.c (init_main): Set rl_completion_word_break_hook to gdb_completion_word_break_characters. gdb/testsuite/ChangeLog entry: 2009-03-11 Pierre Muller * gdb.base/completion.exp: Add a test for directory completion. ------=_NextPart_000_0001_01C9A23D.0008EEE0 Content-Type: application/octet-stream; name="completer-v3.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="completer-v3.patch" Content-length: 11431 Index: src/gdb/completer.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/completer.c,v=0A= retrieving revision 1.33=0A= diff -u -p -r1.33 completer.c=0A= --- src/gdb/completer.c 6 Feb 2009 21:33:58 -0000 1.33=0A= +++ src/gdb/completer.c 6 Mar 2009 16:27:38 -0000=0A= @@ -22,6 +22,7 @@=0A= #include "expression.h"=0A= #include "filenames.h" /* For DOSish file names. */=0A= #include "language.h"=0A= +#include "gdb_assert.h"=0A= =20=0A= #include "cli/cli-decode.h"=0A= =20=0A= @@ -481,24 +482,47 @@ expression_completer (struct cmd_list_el=0A= "file ../gdb.stabs/we" "ird" (needs to not break word at slash)=0A= */=0A= =20=0A= -/* Generate completions all at once. Returns a NULL-terminated array=0A= - of strings. Both the array and each element are allocated with=0A= - xmalloc. It can also return NULL if there are no completions.=0A= +typedef enum=0A= +{=0A= + handle_brkchars,=0A= + handle_completions,=0A= + handle_help=0A= +}=0A= +complete_line_internal_reason;=0A= +=0A= +=0A= +/* Internal function used to handle completions.=0A= +=0A= =20=0A= TEXT is the caller's idea of the "word" we are looking at.=0A= =20=0A= LINE_BUFFER is available to be looked at; it contains the entire text= =0A= of the line. POINT is the offset in that line of the cursor. You=0A= should pretend that the line ends at POINT.=0A= -=20=20=20=0A= - FOR_HELP is true when completing a 'help' command. In this case,=0A= +=0A= + REASON is of type complete_line_internal_reason.=0A= +=0A= + if REASON is handle_brkchars:=0A= + Preliminary phase, called by gdb_completion_word_break_characters funct= ion,=0A= + is used to determine the correct set of chars that are word delimiters= =0A= + depending gon the current command in line_buffer.=0A= + No completion list should be generated; the return value should be NULL= .=0A= + This is checked by an assertion in that function.=0A= +=0A= + if REASON is handle_completions:=0A= + Main phase, called by complete_line function, is used to get the list= =0A= + of posible completions.=0A= +=0A= + if REASON is handle_help:=0A= + Special case when completing a 'help' command. In this case,=0A= once sub-command completions are exhausted, we simply return NULL.=0A= When FOR_HELP is false, we will call a sub-command's completion=0A= - function. */=0A= + function.=0A= + */=0A= =20=0A= static char **=0A= complete_line_internal (const char *text, char *line_buffer, int point,=0A= - int for_help)=0A= + complete_line_internal_reason reason)=0A= {=0A= char **list =3D NULL;=0A= char *tmp_command, *p;=0A= @@ -512,7 +536,6 @@ complete_line_internal (const char *text=0A= functions, which can be any string) then we will switch to the=0A= special word break set for command strings, which leaves out the=0A= '-' character used in some commands. */=0A= -=0A= rl_completer_word_break_characters =3D=0A= current_language->la_word_break_characters();=0A= =20=0A= @@ -575,12 +598,14 @@ complete_line_internal (const char *text=0A= This we can deal with. */=0A= if (result_list)=0A= {=0A= - list =3D complete_on_cmdlist (*result_list->prefixlist, p,=0A= - word);=0A= + if (reason !=3D handle_brkchars)=0A= + list =3D complete_on_cmdlist (*result_list->prefixlist, p,=0A= + word);=0A= }=0A= else=0A= {=0A= - list =3D complete_on_cmdlist (cmdlist, p, word);=0A= + if (reason !=3D handle_brkchars)=0A= + list =3D complete_on_cmdlist (cmdlist, p, word);=0A= }=0A= /* Ensure that readline does the right thing with respect to=0A= inserting quotes. */=0A= @@ -604,18 +629,20 @@ complete_line_internal (const char *text=0A= {=0A= /* It is a prefix command; what comes after it is=0A= a subcommand (e.g. "info "). */=0A= - list =3D complete_on_cmdlist (*c->prefixlist, p, word);=0A= + if (reason !=3D handle_brkchars)=0A= + list =3D complete_on_cmdlist (*c->prefixlist, p, word);=0A= =20=0A= /* Ensure that readline does the right thing=0A= with respect to inserting quotes. */=0A= rl_completer_word_break_characters =3D=0A= gdb_completer_command_word_break_characters;=0A= }=0A= - else if (for_help)=0A= + else if (reason =3D=3D handle_help)=0A= list =3D NULL;=0A= else if (c->enums)=0A= {=0A= - list =3D complete_on_enum (c->enums, p, word);=0A= + if (reason !=3D handle_brkchars)=0A= + list =3D complete_on_enum (c->enums, p, word);=0A= rl_completer_word_break_characters =3D=0A= gdb_completer_command_word_break_characters;=0A= }=0A= @@ -651,7 +678,8 @@ complete_line_internal (const char *text=0A= p--)=0A= ;=0A= }=0A= - list =3D (*c->completer) (c, p, word);=0A= + if (reason !=3D handle_brkchars)=0A= + list =3D (*c->completer) (c, p, word);=0A= }=0A= }=0A= else=0A= @@ -672,7 +700,8 @@ complete_line_internal (const char *text=0A= break;=0A= }=0A= =20=0A= - list =3D complete_on_cmdlist (result_list, q, word);=0A= + if (reason !=3D handle_brkchars)=0A= + list =3D complete_on_cmdlist (result_list, q, word);=0A= =20=0A= /* Ensure that readline does the right thing=0A= with respect to inserting quotes. */=0A= @@ -680,7 +709,7 @@ complete_line_internal (const char *text=0A= gdb_completer_command_word_break_characters;=0A= }=0A= }=0A= - else if (for_help)=0A= + else if (reason =3D=3D handle_help)=0A= list =3D NULL;=0A= else=0A= {=0A= @@ -694,7 +723,8 @@ complete_line_internal (const char *text=0A= }=0A= else if (c->enums)=0A= {=0A= - list =3D complete_on_enum (c->enums, p, word);=0A= + if (reason !=3D handle_brkchars)=0A= + list =3D complete_on_enum (c->enums, p, word);=0A= }=0A= else=0A= {=0A= @@ -719,29 +749,52 @@ complete_line_internal (const char *text=0A= p--)=0A= ;=0A= }=0A= - list =3D (*c->completer) (c, p, word);=0A= + if (reason !=3D handle_brkchars)=0A= + list =3D (*c->completer) (c, p, word);=0A= }=0A= }=0A= }=0A= =20=0A= return list;=0A= }=0A= +/* Generate completions all at once. Returns a NULL-terminated array=0A= + of strings. Both the array and each element are allocated with=0A= + xmalloc. It can also return NULL if there are no completions.=0A= =20=0A= -/* Like complete_line_internal, but always passes 0 for FOR_HELP. */=0A= + TEXT is the caller's idea of the "word" we are looking at.=0A= +=0A= + LINE_BUFFER is available to be looked at; it contains the entire text= =0A= + of the line.=0A= +=0A= + POINT is the offset in that line of the cursor. You=0A= + should pretend that the line ends at POINT. */=0A= =20=0A= char **=0A= complete_line (const char *text, char *line_buffer, int point)=0A= {=0A= - return complete_line_internal (text, line_buffer, point, 0);=0A= + return complete_line_internal (text, line_buffer, point, handle_completi= ons);=0A= }=0A= =20=0A= /* Complete on command names. Used by "help". */=0A= char **=0A= command_completer (struct cmd_list_element *ignore, char *text, char *word= )=0A= {=0A= - return complete_line_internal (word, text, strlen (text), 1);=0A= + return complete_line_internal (word, text, strlen (text), handle_help);= =0A= }=0A= =20=0A= +/* Get the list of chars that are considered as word breaks=0A= + for the current command. */=0A= +=0A= +char *=0A= +gdb_completion_word_break_characters (void)=0A= +{=0A= + char ** list;=0A= + list =3D complete_line_internal (rl_line_buffer, rl_line_buffer, rl_poin= t,=0A= + handle_brkchars);=0A= + gdb_assert (list =3D=3D NULL);=0A= + return rl_completer_word_break_characters;=0A= +}=0A= +=0A= /* Generate completions one by one for the completer. Each time we are=0A= called return another potential completion to the caller.=0A= line_completion just completes on commands or passes the buck to the=0A= Index: src/gdb/completer.h=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/completer.h,v=0A= retrieving revision 1.16=0A= diff -u -p -r1.16 completer.h=0A= --- src/gdb/completer.h 6 Feb 2009 21:33:58 -0000 1.16=0A= +++ src/gdb/completer.h 6 Mar 2009 16:27:38 -0000=0A= @@ -33,6 +33,8 @@ extern char **command_completer (struct=20=0A= =20=0A= extern char *get_gdb_completer_quote_characters (void);=0A= =20=0A= +extern char *gdb_completion_word_break_characters (void);=0A= +=0A= /* Exported to linespec.c */=0A= =20=0A= extern char *skip_quoted_chars (char *, char *, char *);=0A= Index: src/gdb/top.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/top.c,v=0A= retrieving revision 1.161=0A= diff -u -p -r1.161 top.c=0A= --- src/gdb/top.c 3 Mar 2009 13:35:24 -0000 1.161=0A= +++ src/gdb/top.c 6 Mar 2009 16:27:38 -0000=0A= @@ -1543,6 +1543,7 @@ init_main (void)=0A= write_history_p =3D 0;=0A= =20=0A= /* Setup important stuff for command line editing. */=0A= + rl_completion_word_break_hook =3D gdb_completion_word_break_characters;= =0A= rl_completion_entry_function =3D readline_line_completion_function;=0A= rl_completer_word_break_characters =3D default_word_break_characters ();= =0A= rl_completer_quote_characters =3D get_gdb_completer_quote_characters ();= =0A= Index: src/gdb/testsuite/gdb.base/completion.exp=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/testsuite/gdb.base/completion.exp,v=0A= retrieving revision 1.36=0A= diff -u -p -r1.36 completion.exp=0A= --- src/gdb/testsuite/gdb.base/completion.exp 3 Jan 2009 05:58:03 -0000 1.3= 6=0A= +++ src/gdb/testsuite/gdb.base/completion.exp 9 Mar 2009 08:56:58 -0000=0A= @@ -734,6 +734,36 @@ gdb_test "cd ${fullsrcdir}" \=0A= "Working directory [string_to_regexp ${fullsrcdir}].*" \=0A= "cd to \${srcdir}"=0A= =20=0A= +=0A= +# GDB used to fail adding / on directories, on the first try only=0A= +send_gdb "dir ../testsu\t"=0A= +gdb_expect {=0A= + -re "../testsuite/$" {=0A= + pass "directory completion"=0A= + send_gdb "gdb.bas\t"=0A= + }=0A= + -re "../testsuite $" {=0A= + fail "directory completion (old gdb bug)"=0A= + send_gdb "\b/gdb.bas\t"=0A= + }=0A= + default {=0A= + fail "directory completion (timeout)"=0A= + send_gdb "\ndir ../testsuite/gdb.bas\t"=0A= + }=0A= +}=0A= +=0A= +gdb_expect {=0A= + -re "gdb.base/$" {=0A= + pass "directory completion 2"=0A= + }=0A= + timeout {=0A= + fail "directory completion 2"=0A= + }=0A= +}=0A= +=0A= +gdb_test "\n" "" "Glob remaining of directory test"=0A= +=0A= +=0A= send_gdb "complete file ./gdb.base/compl\n"=0A= sleep 1=0A= gdb_expect {=0A= ------=_NextPart_000_0001_01C9A23D.0008EEE0--