From patchwork Wed May 22 20:53:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 32808 Received: (qmail 129873 invoked by alias); 22 May 2019 20:53:41 -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 129822 invoked by uid 89); 22 May 2019 20:53:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.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; Wed, 22 May 2019 20:53:39 +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 5B699309B7B9 for ; Wed, 22 May 2019 20:53:38 +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 D643F1001284 for ; Wed, 22 May 2019 20:53:37 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 10/24] boolean/auto-boolean commands, make "o" ambiguous Date: Wed, 22 May 2019 21:53:13 +0100 Message-Id: <20190522205327.2568-11-palves@redhat.com> In-Reply-To: <20190522205327.2568-1-palves@redhat.com> References: <20190522205327.2568-1-palves@redhat.com> We currently accept "o" with boolean/auto-boolean commands, taking it to mean "on". But "o" is ambiguous, between "on" and "off". I can't imagine why assuming the user wanted to type "on" is a good idea, it might have been a typo. This commit makes gdb error out. We now get: (gdb) maint test-settings set boolean o "on" or "off" expected. (gdb) maint test-settings set auto-boolean o "on", "off" or "auto" expected. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * cli/cli-setshow.c (parse_auto_binary_operation) (parse_cli_boolean_value): Don't allow "o". gdb/testsuite/ChangeLog: yyyy-mm-dd Pedro Alves * gdb.base/settings.exp (test-boolean, test-auto-boolean): Check that "o" is ambiguous. --- gdb/cli/cli-setshow.c | 15 ++++++++++----- gdb/testsuite/gdb.base/settings.exp | 10 ++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c index 9d6479ffca2..76bc2a3d751 100644 --- a/gdb/cli/cli-setshow.c +++ b/gdb/cli/cli-setshow.c @@ -54,18 +54,21 @@ parse_auto_binary_operation (const char *arg) while (isspace (arg[length - 1]) && length > 0) length--; - if (strncmp (arg, "on", length) == 0 + + /* Note that "o" is ambiguous. */ + + if ((length == 2 && strncmp (arg, "on", length) == 0) || strncmp (arg, "1", length) == 0 || strncmp (arg, "yes", length) == 0 || strncmp (arg, "enable", length) == 0) return AUTO_BOOLEAN_TRUE; - else if (strncmp (arg, "off", length) == 0 + else if ((length >= 2 && strncmp (arg, "off", length) == 0) || strncmp (arg, "0", length) == 0 || strncmp (arg, "no", length) == 0 || strncmp (arg, "disable", length) == 0) return AUTO_BOOLEAN_FALSE; else if (strncmp (arg, "auto", length) == 0 - || (strncmp (arg, "-1", length) == 0 && length > 1)) + || (length > 1 && strncmp (arg, "-1", length) == 0)) return AUTO_BOOLEAN_AUTO; } error (_("\"on\", \"off\" or \"auto\" expected.")); @@ -87,12 +90,14 @@ parse_cli_boolean_value (const char *arg) while (arg[length - 1] == ' ' || arg[length - 1] == '\t') length--; - if (strncmp (arg, "on", length) == 0 + /* Note that "o" is ambiguous. */ + + if ((length == 2 && strncmp (arg, "on", length) == 0) || strncmp (arg, "1", length) == 0 || strncmp (arg, "yes", length) == 0 || strncmp (arg, "enable", length) == 0) return 1; - else if (strncmp (arg, "off", length) == 0 + else if ((length >= 2 && strncmp (arg, "off", length) == 0) || strncmp (arg, "0", length) == 0 || strncmp (arg, "no", length) == 0 || strncmp (arg, "disable", length) == 0) diff --git a/gdb/testsuite/gdb.base/settings.exp b/gdb/testsuite/gdb.base/settings.exp index 365f39ea2f9..ad945a8ccbe 100644 --- a/gdb/testsuite/gdb.base/settings.exp +++ b/gdb/testsuite/gdb.base/settings.exp @@ -191,13 +191,16 @@ proc_with_prefix test-boolean {} { gdb_test "$set_cmd auto" \ "\"on\" or \"off\" expected\\." + # "o" is ambiguous. + gdb_test "$set_cmd o" \ + "\"on\" or \"off\" expected\\." + # Various valid values. Test both full value names and # abbreviations. # Note that unlike with auto-bool, empty value implies "on". foreach_with_prefix value { "" - "o" "on" "1" "y" @@ -275,11 +278,14 @@ proc_with_prefix test-auto-boolean {} { gdb_test "$set_cmd on 1" \ "\"on\", \"off\" or \"auto\" expected\\." + # "o" is ambiguous. + gdb_test "$set_cmd o" \ + "\"on\", \"off\" or \"auto\" expected\\." + # Various valid values. Test both full value names and # abbreviations. foreach_with_prefix value { - "o" "on" "1" "y"