From patchwork Thu Jun 13 08:45: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: 33102 Received: (qmail 68441 invoked by alias); 13 Jun 2019 08:45:32 -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 68284 invoked by uid 89); 13 Jun 2019 08:45:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 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; Thu, 13 Jun 2019 08:45:11 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A298FDD9F4 for ; Thu, 13 Jun 2019 08:45:07 +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 1B46E600C1 for ; Thu, 13 Jun 2019 08:45:06 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH] Fix "set integer-command unlimited junk" Date: Thu, 13 Jun 2019 09:45:05 +0100 Message-Id: <20190613084505.13786-1-palves@redhat.com> 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 * 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 * gdb.base/settings.exp (test-integer): Test junk after "unlimited". --- gdb/cli/cli-setshow.c | 23 +++++++++++++++++++---- gdb/testsuite/gdb.base/settings.exp | 11 +++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c index 14ea723c6a9..8199fa7c0b0 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/gdb.base/settings.exp b/gdb/testsuite/gdb.base/settings.exp index 4a7319df489..aeca67c0e7f 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"