From patchwork Tue Jun 4 22:34:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 32995 Received: (qmail 46494 invoked by alias); 4 Jun 2019 22:35:15 -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 46415 invoked by uid 89); 4 Jun 2019 22:35:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 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= 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:13 +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 BAF7E316290C for ; Tue, 4 Jun 2019 22:35:12 +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 503B619C69 for ; Tue, 4 Jun 2019 22:35:12 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v3 11/24] number_or_range_parser::get_number, don't treat "1 -" as a range Date: Tue, 4 Jun 2019 23:34:31 +0100 Message-Id: <20190604223444.26472-12-palves@redhat.com> In-Reply-To: <20190604223444.26472-1-palves@redhat.com> References: <20190604223444.26472-1-palves@redhat.com> While adding -OPT options to "frame apply level", I noticed that: (gdb) frame apply level 0 -[TAB] wasn't completing on the supported options. This commit fixes it. We'll get instead: (gdb) frame apply level 0 - -c -past-entry -past-main -q -s I added the isspace check because this case: (gdb) frame apply level 0- can't be an option. Tests for this will be in a new gdb.base/options.exp file, in a following patch. It will exercise all of: (gdb) frame apply level 0- (gdb) frame apply level 0 - (gdb) frame apply level 0 -- (gdb) frame apply level 0 -- - gdb/ChangeLog: yyyy-mm-dd Pedro Alves * cli/cli-utils.c (number_or_range_parser::get_number): Do not parse a range if "-" is at the end of the string. --- gdb/cli/cli-utils.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c index a24fe9278c7..23296cee9c3 100644 --- a/gdb/cli/cli-utils.c +++ b/gdb/cli/cli-utils.c @@ -233,10 +233,18 @@ number_or_range_parser::get_number () /* Default case: state->m_cur_tok is pointing either to a solo number, or to the first number of a range. */ m_last_retval = get_number_trailer (&m_cur_tok, '-'); - /* If get_number_trailer has found a -, it might be the start - of a command option. So, do not parse a range if the - is - followed by an alpha. */ - if (*m_cur_tok == '-' && !isalpha (*(m_cur_tok + 1))) + /* If get_number_trailer has found a '-' preceded by a space, it + might be the start of a command option. So, do not parse a + range if the '-' is followed by an alpha or another '-'. We + might also be completing something like + "frame apply level 0 -" and we prefer treating that "-" as an + option rather than an incomplete range, so check for end of + string as well. */ + if (m_cur_tok[0] == '-' + && !(isspace (m_cur_tok[-1]) + && (isalpha (m_cur_tok[1]) + || m_cur_tok[1] == '-' + || m_cur_tok[1] == '\0'))) { const char **temp;