From patchwork Tue Jun 4 22:34:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 32988 Received: (qmail 45124 invoked by alias); 4 Jun 2019 22:35:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 45066 invoked by uid 89); 4 Jun 2019 22:35:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=readline X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Jun 2019 22:35:05 +0000 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B74230860AD for ; Tue, 4 Jun 2019 22:35:04 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id B612419C69 for ; Tue, 4 Jun 2019 22:35:03 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v3 02/24] Fix latent bug with custom word point completers Date: Tue, 4 Jun 2019 23:34:22 +0100 Message-Id: <20190604223444.26472-3-palves@redhat.com> In-Reply-To: <20190604223444.26472-1-palves@redhat.com> References: <20190604223444.26472-1-palves@redhat.com> 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: yyyy-mm-dd Pedro Alves * 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/completer.c | 5 ++++- gdb/completer.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index 03d0d0e5dbd..5dd9a99f2a2 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -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; } diff --git a/gdb/completer.h b/gdb/completer.h index 38a0132ca4d..27371b63a57 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -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. */