From patchwork Wed May 22 20:53:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 32801 Received: (qmail 128561 invoked by alias); 22 May 2019 20:53:33 -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 128511 invoked by uid 89); 22 May 2019 20:53:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.1 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=Advance, pri 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; Wed, 22 May 2019 20:53:31 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9FCCC3082B5F for ; Wed, 22 May 2019 20:53:30 +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 2C2621001E67 for ; Wed, 22 May 2019 20:53:29 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 02/24] Fix latent bug with custom word point completers Date: Wed, 22 May 2019 21:53:05 +0100 Message-Id: <20190522205327.2568-3-palves@redhat.com> In-Reply-To: <20190522205327.2568-1-palves@redhat.com> References: <20190522205327.2568-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 ee2eec1a35a..e86b0531f54 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -1405,6 +1405,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); @@ -1976,7 +1979,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. */