public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pedro Alves <palves@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Fix "set integer-command unlimited junk"
Date: Thu, 13 Jun 2019 16:58:00 -0000	[thread overview]
Message-ID: <20190613165814.95206.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4c04873103043dc9a1c8d6cdeea1b9b1f545f375

commit 4c04873103043dc9a1c8d6cdeea1b9b1f545f375
Author: Pedro Alves <palves@redhat.com>
Date:   Thu Jun 13 15:22:44 2019 +0100

    Fix "set integer-command unlimited junk"
    
    With integer commands that support "unlimited", we currently fail to
    notice junk after "unlimited":
    
     (gdb) show print elements
     Limit on string chars or array elements to print is 200.
     (gdb) set print elements unlimited foo
     (gdb) show print elements
     Limit on string chars or array elements to print is unlimited.
    
    This commit fixes that.  After, we get:
    
     (gdb) set print elements unlimited foo
     Junk after "unlimited": foo
    
    gdb/ChangeLog:
    2019-06-13  Pedro Alves  <palves@redhat.com>
    
    	* cli/cli-setshow.c (cli/cli-setshow.c): New parameter
    	'expression'.  When parsing an expression, error out if there's
    	junk after "unlimited".
    	(parse_cli_var_uinteger, parse_cli_var_zuinteger_unlimited)
    	(do_set_command): Adjust calls to is_unlimited_literal.
    
    gdb/testsuite/ChangeLog:
    2019-06-13  Pedro Alves  <palves@redhat.com>
    
    	* gdb.base/settings.exp (test-integer): Test junk after
    	"unlimited".

Diff:
---
 gdb/ChangeLog                       |  8 ++++++++
 gdb/cli/cli-setshow.c               | 23 +++++++++++++++++++----
 gdb/testsuite/ChangeLog             |  5 +++++
 gdb/testsuite/gdb.base/settings.exp | 11 +++++++++++
 4 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 029acd1..91f3b75 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
 2019-06-13  Pedro Alves  <palves@redhat.com>
 
+	* cli/cli-setshow.c (cli/cli-setshow.c): New parameter
+	'expression'.  When parsing an expression, error out if there's
+	junk after "unlimited".
+	(parse_cli_var_uinteger, parse_cli_var_zuinteger_unlimited)
+	(do_set_command): Adjust calls to is_unlimited_literal.
+
+2019-06-13  Pedro Alves  <palves@redhat.com>
+
 	* compile/compile.c (make_compile_options_def_group): Add braces
 	around array_view initializer.
 	* thread.c (make_thread_apply_all_options_def_group)
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 14ea723..8199fa7 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -150,10 +150,12 @@ deprecated_show_value_hack (struct ui_file *ignore_file,
 /* Returns true if ARG is "unlimited".  */
 
 static bool
-is_unlimited_literal (const char **arg)
+is_unlimited_literal (const char **arg, bool expression)
 {
   *arg = skip_spaces (*arg);
 
+  const char *unl_start = *arg;
+
   const char *p = skip_to_space (*arg);
 
   size_t len = p - *arg;
@@ -161,6 +163,19 @@ is_unlimited_literal (const char **arg)
   if (len > 0 && strncmp ("unlimited", *arg, len) == 0)
     {
       *arg += len;
+
+      /* If parsing an expression (i.e., parsing for a "set" command),
+	 anything after "unlimited" is junk.  For options, anything
+	 after "unlimited" might be a command argument or another
+	 option.  */
+      if (expression)
+	{
+	  const char *after = skip_spaces (*arg);
+	  if (*after != '\0')
+	    error (_("Junk after \"%.*s\": %s"),
+		   (int) len, unl_start, after);
+	}
+
       return true;
     }
 
@@ -183,7 +198,7 @@ parse_cli_var_uinteger (var_types var_type, const char **arg,
 	error_no_arg (_("integer to set it to."));
     }
 
-  if (var_type == var_uinteger && is_unlimited_literal (arg))
+  if (var_type == var_uinteger && is_unlimited_literal (arg, expression))
     val = 0;
   else if (expression)
     val = parse_and_eval_long (*arg);
@@ -213,7 +228,7 @@ parse_cli_var_zuinteger_unlimited (const char **arg, bool expression)
   if (*arg == nullptr)
     error_no_arg (_("integer to set it to, or \"unlimited\"."));
 
-  if (is_unlimited_literal (arg))
+  if (is_unlimited_literal (arg, expression))
     val = -1;
   else if (expression)
     val = parse_and_eval_long (*arg);
@@ -448,7 +463,7 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
 	      error_no_arg (_("integer to set it to."));
 	  }
 
-	if (c->var_type == var_integer && is_unlimited_literal (&arg))
+	if (c->var_type == var_integer && is_unlimited_literal (&arg, true))
 	  val = 0;
 	else
 	  val = parse_and_eval_long (arg);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 3a3a6e8..37e327d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
 2019-06-13  Pedro Alves  <palves@redhat.com>
 
+	* gdb.base/settings.exp (test-integer): Test junk after
+	"unlimited".
+
+2019-06-13  Pedro Alves  <palves@redhat.com>
+
 	* gdb.base/options.exp (test-thread-apply): New.
 	(top level): Call it.
 
diff --git a/gdb/testsuite/gdb.base/settings.exp b/gdb/testsuite/gdb.base/settings.exp
index 4a7319d..aeca67c 100644
--- a/gdb/testsuite/gdb.base/settings.exp
+++ b/gdb/testsuite/gdb.base/settings.exp
@@ -141,8 +141,19 @@ proc test-integer {variant} {
 	    "$set_cmd unlimited"
     }
 
+    # Check junk after "unlimited".
     gdb_test "$set_cmd unlimitedu" "No symbol table is loaded.*"
 
+    if {$variant == "zinteger" || $variant == "zuinteger"} {
+	gdb_test "$set_cmd unlimited u" "No symbol table is loaded.*"
+	gdb_test "$set_cmd unlimited 1" "No symbol table is loaded.*"
+	gdb_test "$set_cmd unlimited -1" "No symbol table is loaded.*"
+    } else {
+	gdb_test "$set_cmd unlimited u" "Junk after \"unlimited\": u"
+	gdb_test "$set_cmd unlimited 1" "Junk after \"unlimited\": 1"
+	gdb_test "$set_cmd unlimited -1" "Junk after \"unlimited\": -1"
+    }
+
     test_gdb_complete_none "$set_cmd unlimited "
     test_gdb_complete_none "$set_cmd unlimitedu"
     test_gdb_complete_none "$set_cmd unlimited u"


                 reply	other threads:[~2019-06-13 16:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20190613165814.95206.qmail@sourceware.org \
    --to=palves@sourceware.org \
    --cc=gdb-cvs@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).