Fix latent bug with custom word point completers
authorPedro Alves <palves@redhat.com>
Wed, 12 Jun 2019 23:06:52 +0000 (00:06 +0100)
committerPedro Alves <palves@redhat.com>
Wed, 12 Jun 2019 23:07:37 +0000 (00:07 +0100)
Completion routines that use a custom word point, and that then
recurse into complete_line (e.g., if we make "thread apply" a custom
word point completer, and complete on the command passed as argument),
we stumble on this latent bug:

 (gdb) thread apply all pri[TAB]
 (gdb) thread apply all priprint

The problem is that there's a spot in complete_line_internal_1 that
rewinds the completion word but does not reflect that change in the
custom word point in the tracker.  This patch fixes it.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* completer.c (complete_line_internal_1): Rewind completion word
point.
(completion_tracker::advance_custom_word_point_by): Change
parameter type to int.
* completer.h (completion_tracker::advance_custom_word_point_by):
Likewise.

gdb/ChangeLog
gdb/completer.c
gdb/completer.h

index 19b2a7dc76c89d20bea5ec79a619b1530b51aba6..cd81cfea350259ca3a66ed00b56020b161ab2645 100644 (file)
@@ -1,3 +1,12 @@
+2019-06-13  Pedro Alves  <palves@redhat.com>
+
+       * completer.c (complete_line_internal_1): Rewind completion word
+       point.
+       (completion_tracker::advance_custom_word_point_by): Change
+       parameter type to int.
+       * completer.h (completion_tracker::advance_custom_word_point_by):
+       Likewise.
+
 2019-06-13  Pedro Alves  <palves@redhat.com>
 
        * completer.c (advance_to_completion_word): Handle delimiters.
index 03d0d0e5dbd39d6ec340402e46800a906fd2f9f4..5dd9a99f2a2eb38c14a3fe289ef1a216c2b16136 100644 (file)
@@ -1403,6 +1403,9 @@ complete_line_internal_1 (completion_tracker &tracker,
                    break;
                }
 
+             /* Move the custom word point back too.  */
+             tracker.advance_custom_word_point_by (q - p);
+
              if (reason != handle_brkchars)
                complete_on_cmdlist (result_list, tracker, q, word,
                                     ignore_help_classes);
@@ -1972,7 +1975,7 @@ completion_tracker::recompute_lowest_common_denominator
 /* See completer.h.  */
 
 void
-completion_tracker::advance_custom_word_point_by (size_t len)
+completion_tracker::advance_custom_word_point_by (int len)
 {
   m_custom_word_point += len;
 }
index 38a0132ca4d137aa9965b9903d0e31809db4987d..27371b63a5763ff28c19350e1b92a4ae2038964b 100644 (file)
@@ -357,7 +357,7 @@ public:
   { m_custom_word_point = point; }
 
   /* Advance the custom word point by LEN.  */
-  void advance_custom_word_point_by (size_t len);
+  void advance_custom_word_point_by (int len);
 
   /* Whether to tell readline to skip appending a whitespace after the
      completion.  See m_suppress_append_ws.  */