Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 10/24] boolean/auto-boolean commands, make "o" ambiguous
Date: Wed, 22 May 2019 20:54:00 -0000	[thread overview]
Message-ID: <20190522205327.2568-11-palves@redhat.com> (raw)
In-Reply-To: <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  <palves@redhat.com>

	* cli/cli-setshow.c (parse_auto_binary_operation)
	(parse_cli_boolean_value): Don't allow "o".

gdb/testsuite/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* 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"
-- 
2.14.5


  parent reply	other threads:[~2019-05-22 20:53 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-22 20:53 [PATCH 00/24] gdb::option framework, "print -OPT", other cmd options Pedro Alves
2019-05-22 20:53 ` [PATCH 03/24] Fix TID parser bug Pedro Alves
2019-05-22 20:53 ` [PATCH 07/24] Remove "show" command completers Pedro Alves
2019-05-23 19:28   ` Sergio Durigan Junior
2019-05-24 11:25     ` Pedro Alves
2019-05-24 14:21       ` Sergio Durigan Junior
2019-05-22 20:53 ` [PATCH 08/24] gdb.base/settings.exp: Fix comment typo Pedro Alves
2019-05-24 11:40   ` Pedro Alves
2019-05-22 20:53 ` [PATCH 18/24] lib/completion-support.exp: Add test_gdb_completion_offers_commands Pedro Alves
2019-05-22 20:53 ` [PATCH 04/24] Make check_for_argument skip whitespace after arg itself Pedro Alves
2019-05-22 20:53 ` [PATCH 11/24] number_or_range_parser::get_number, don't treat "1 -" as a range Pedro Alves
2019-05-22 20:53 ` [PATCH 19/24] Introduce complete_command Pedro Alves
2019-05-22 20:53 ` [PATCH 15/24] Introduce rename_cmd Pedro Alves
2019-05-25 19:58   ` Philippe Waroquiers
2019-05-29 16:03     ` Pedro Alves
2019-05-29 18:30       ` Pedro Alves
2019-05-30 10:22         ` Philippe Waroquiers
2019-05-30 20:01           ` Pedro Alves
2019-05-22 20:54 ` [PATCH 22/24] Make "thread apply" use the gdb::option framework Pedro Alves
2019-05-25 20:24   ` Philippe Waroquiers
2019-05-29 15:38     ` Pedro Alves
2019-05-22 20:54 ` Pedro Alves [this message]
2019-05-22 20:54 ` [PATCH 20/24] Make "frame apply" support -OPT options Pedro Alves
2019-05-25 20:12   ` Philippe Waroquiers
2019-05-29 15:13     ` Pedro Alves
2019-05-29 15:25       ` Pedro Alves
2019-05-22 20:54 ` [PATCH 14/24] Migrate rest of compile commands to new options framework Pedro Alves
2019-05-22 20:54 ` [PATCH 01/24] Fix latent bug in custom word point completion handling Pedro Alves
2019-05-22 20:54 ` [PATCH 02/24] Fix latent bug with custom word point completers Pedro Alves
2019-05-22 20:54 ` [PATCH 12/24] Introduce generic command options framework Pedro Alves
2019-05-25  7:43   ` Philippe Waroquiers
2019-05-25 10:31     ` Pedro Alves
2019-05-22 20:54 ` [PATCH 21/24] "thread apply 1 -- -" vs "frame apply level 0 -- -" Pedro Alves
2019-05-22 20:54 ` [PATCH 09/24] New set/show testing framework (gdb.base/settings.exp) Pedro Alves
2019-05-23  4:15   ` Eli Zaretskii
2019-05-22 20:54 ` [PATCH 05/24] Allow "unlimited" abbreviations Pedro Alves
2019-05-22 20:54 ` [PATCH 06/24] Fix "set enum-command value garbage" Pedro Alves
2019-05-23 19:13   ` Sergio Durigan Junior
2019-05-24 11:39     ` Pedro Alves
2019-05-22 20:58 ` [PATCH 13/24] Make "print" and "compile print" support -OPT options Pedro Alves
2019-05-24 19:49   ` Sergio Durigan Junior
2019-05-25 10:10     ` Pedro Alves
2019-05-25 10:37       ` Andreas Schwab
2019-05-22 20:58 ` [PATCH 16/24] Make "backtrace" " Pedro Alves
2019-05-22 21:00 ` [PATCH 17/24] "backtrace full/no-filters/hide" completer Pedro Alves
2019-05-22 21:00 ` [PATCH 24/24] NEWS and manual changes for command options changes Pedro Alves
2019-05-23  4:31   ` Eli Zaretskii
2019-05-23 15:01     ` Pedro Alves
2019-05-23 15:07       ` Eli Zaretskii
2019-05-23 15:31         ` Pedro Alves
2019-05-25 20:40   ` Philippe Waroquiers
2019-05-29 16:03     ` Pedro Alves
2019-05-22 21:03 ` [PATCH 23/24] Delete parse_flags/parse_flags_qcs Pedro Alves
2019-05-22 21:46 ` [PATCH 00/24] gdb::option framework, "print -OPT", other cmd options Pedro Alves
2019-05-24 19:58 ` Sergio Durigan Junior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190522205327.2568-11-palves@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox