Re: [PATCH 15/40] Rewrite/enhance explicit locations completer, parse left->right

Keith Seitz
2017-07-14T20:55:38Z

On 06/02/2017 05:22 AM, Pedro Alves wrote:

> So... this patch gets rid of the need for quoting.

Yippie! /me really dislikes all the quoting nonsense that users have to deal with

> gdb/testsuite/ChangeLog:
> yyyy-mm-dd Pedro Alves <palves@redhat.com>
>
> * gdb.base/completion.exp: Adjust expected output.
> * gdb.linespec/ls-errs.exp (do_test): Adjust expected output.

> diff --git a/gdb/completer.c b/gdb/completer.c
> index a1d3a43..0473d8c 100644
> --- a/gdb/completer.c
> +++ b/gdb/completer.c

> @@ -1189,6 +1452,22 @@ completion_tracker::completion_tracker ()
> NULL, xcalloc, xfree);
> }
>
> +void
> +completion_tracker::discard_completions ()

Implicit or missing comment?

> @@ -1517,6 +1839,12 @@ completion_tracker::recompute_lowest_common_denominator (const char *new_match)
> }
> }
>
> +void
> +completion_tracker::advance_custom_word_point_by (size_t len)

Implicit or missing comment?

> +{
> + m_custom_word_point += len;
> +}
> +
> /* Build a new C string that is a copy or LCD with the whitespace of
> ORIG/ORIG_LEN preserved.
>
> @@ -1720,14 +2055,20 @@ completion_result::reset_match_list ()
> static char **
> gdb_rl_attempted_completion_function_throw (const char *text, int start, int end)
> {
> - /* Completers must be called twice. If rl_point (i.e., END) is at
> - column 0, then readline skips the the handle_brkchars phase, and
> - so we create a tracker now in that case too. */
> - delete current_completion.tracker;
> - current_completion.tracker = new completion_tracker ();
> + /* Completers that provide a custom word point in the
> + handle_brkchars phase also compute their completions then.
> + Completers that leave the completion word handling to readline
> + must be called twice. If rl_point (i.e., END) is at column 0,
> + then readline skips the the handle_brkchars phase, and so we
^^^^^^^
"the the"

> + create a tracker now in that case too. */
> + if (end == 0 || !current_completion.tracker->use_custom_word_point ())
> + {
> + delete current_completion.tracker;
> + current_completion.tracker = new completion_tracker ();
>
> - complete_line (*current_completion.tracker, text,
> - rl_line_buffer, rl_point);
> + complete_line (*current_completion.tracker, text,
> + rl_line_buffer, rl_point);
> + }
>
> completion_tracker &tracker = *current_completion.tracker;
>
> diff --git a/gdb/location.c b/gdb/location.c
> index d711d7b..19d3232 100644
> --- a/gdb/location.c
> +++ b/gdb/location.c
> +static bool
> +is_cp_operator (const char *start, const char *comma)
> +{
> + if (comma != NULL
> + && (comma - start) >= CP_OPERATOR_LEN)
> + {
> + const char *p = comma;
> +
> + while (p > start && isspace (p[-1]))
> + p--;
> + if (p - start >= CP_OPERATOR_LEN)
> + {
> + p-= CP_OPERATOR_LEN;
^^^

Missing a space there.

> + if (strncmp (p, CP_OPERATOR_STR, CP_OPERATOR_LEN) == 0
> + && (p == start
> + || !(isalnum (p[-1]) || p[-1] == '_')))
> + {

> diff --git a/gdb/symtab.c b/gdb/symtab.c
> index 91e8b90..7c7ff7f 100644
> --- a/gdb/symtab.c
> +++ b/gdb/symtab.c
> @@ -4995,6 +4995,7 @@ add_symtab_completions (struct compunit_symtab *cust,
> void
> default_collect_symbol_completion_matches_break_on
> (completion_tracker &tracker,
> + complete_symbol_mode mode,
> const char *text, const char *word,
> const char *break_on, enum type_code code)
> {
> @@ -5013,8 +5014,12 @@ default_collect_symbol_completion_matches_break_on
> const char *sym_text;
> /* Length of sym_text. */
> int sym_text_len;
> + struct cleanup *cleanups;

`cleanups' is unused.

> diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
> index 6597ea7..f03bfc3 100644
> --- a/gdb/testsuite/gdb.base/completion.exp
> +++ b/gdb/testsuite/gdb.base/completion.exp
> @@ -790,7 +790,7 @@ gdb_test_multiple "" $test {
> -re "break\.c.*break1\.c.*$gdb_prompt " {
> send_gdb "1\t\n"
> gdb_test_multiple "" $test {
> - -re ".*Function \"$srcfile2\" not defined\..*$gdb_prompt " {
> + -re "malformed linespec error: unexpected end of input\r\n$gdb_prompt " {
> pass $test
> }
> -re "$gdb_prompt p$" {

I don't understand this change, and it FAILs for me. In the log, it is still saying "Function \"break1.c\" not found". [NOTE: the completion is still "break break1.c ".]

I see this will eventually PASS (when the trailing ':' is output). Perhaps this hunk is in the wrong patch?

Keith