From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WJQ8BOhNKGB1AgAAWB0awg (envelope-from ) for ; Sat, 13 Feb 2021 17:08:40 -0500 Received: by simark.ca (Postfix, from userid 112) id 0E4231EF68; Sat, 13 Feb 2021 17:08:40 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 989B41E789 for ; Sat, 13 Feb 2021 17:08:37 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5655838930D8; Sat, 13 Feb 2021 22:08:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5655838930D8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1613254117; bh=ZAvm7DpzKB23IVWW8jm0OtrjmJh+b0V0DvAJI8h7myM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=t//mK8BUc3M5F8pmsELJT+SBdh6y8cgXpjipJEhjoNIgi73urtXwk4u/Lwre3lYkT SYiKF+5k+fNHuB13thNqJcP3uRTHm0bYfXcrBJ/m/9YS2UzgTtP3z7GWH+7qPYzLuU raLGJKItS4lKqrVipQlDMsQzOqH92irXj4iHR7lM= Received: from beryx.lancelotsix.com (beryx.lancelotsix.com [IPv6:2001:41d0:401:3000::1ab3]) by sourceware.org (Postfix) with ESMTPS id 9FB8238930D8 for ; Sat, 13 Feb 2021 22:08:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9FB8238930D8 Received: from Plymouth.lan (unknown [IPv6:2a02:390:8443:0:2199:d918:170f:6cbf]) by beryx.lancelotsix.com (Postfix) with ESMTPSA id A92F72E006; Sat, 13 Feb 2021 23:08:33 +0100 (CET) To: gdb-patches@sourceware.org Subject: [PATCH 2/3] gdb::option: Add support for zuinteger. Date: Sat, 13 Feb 2021 22:07:51 +0000 Message-Id: <20210213220752.32581-3-lsix@lancelotsix.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210213220752.32581-1-lsix@lancelotsix.com> References: <20210213220752.32581-1-lsix@lancelotsix.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (beryx.lancelotsix.com [0.0.0.0]); Sat, 13 Feb 2021 23:08:33 +0100 (CET) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Lancelot SIX via Gdb-patches Reply-To: Lancelot SIX Cc: Lancelot SIX Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This patch adds support for options of type var_zuinteger in the gdb::option framework. gdb/ChangeLog: * cli/cli-option.c (union option_value): Add zuinteger field. (parse_option): Add parsing of zuinteger field. (save_option_value_in_ctx): Handle var_zuinteger. (get_val_type_str): Handle var_zuinteger. (add_setshow_cmds_for_options): Handle var_zuinteger. * cli/cli-option.h (struct option_def): Add var_address.zuinteger. (struct zuinteger_option_def): Add. * maint-test-options.c (struct test_options_opts): Add zuint_opt. gdb/testsuite/ChangeLog: * gdb.base/options.exp: Add tests for -zuinteger. --- gdb/cli/cli-option.c | 27 ++++++++++ gdb/cli/cli-option.h | 21 ++++++++ gdb/maint-test-options.c | 14 +++++- gdb/testsuite/gdb.base/options.exp | 80 +++++++++++++++++++----------- 4 files changed, 111 insertions(+), 31 deletions(-) diff --git a/gdb/cli/cli-option.c b/gdb/cli/cli-option.c index 5a6c997dcda..a36e899739c 100644 --- a/gdb/cli/cli-option.c +++ b/gdb/cli/cli-option.c @@ -40,6 +40,9 @@ union option_value /* For var_uinteger options. */ unsigned int uinteger; + /* For var_zuinteger options. */ + unsigned int zuinteger; + /* For var_zuinteger_unlimited options. */ int integer; @@ -593,6 +596,15 @@ parse_option (gdb::array_view options_group, return option_def_and_value {*match, match_ctx, val}; } } + case var_zuinteger: + { + /* No completion available. We cannot display NUMBER as a + convinience for the user since there would be only one + option and readline would complete it. */ + option_value val; + val.zuinteger = parse_cli_var_uinteger (match->type, args, false); + return option_def_and_value {*match, match_ctx, val}; + } case var_enum: { if (completion != nullptr) @@ -827,6 +839,10 @@ save_option_value_in_ctx (gdb::optional &ov) *ov->option.var_address.uinteger (ov->option, ov->ctx) = ov->value->uinteger; break; + case var_zuinteger: + *ov->option.var_address.zuinteger (ov->option, ov->ctx) + = ov->value->zuinteger; + break; case var_zuinteger_unlimited: *ov->option.var_address.integer (ov->option, ov->ctx) = ov->value->integer; @@ -906,6 +922,8 @@ get_val_type_str (const option_def &opt, std::string &buffer) case var_uinteger: case var_zuinteger_unlimited: return "NUMBER|unlimited"; + case var_zuinteger: + return "NUMBER"; case var_enum: { buffer = ""; @@ -1036,6 +1054,15 @@ add_setshow_cmds_for_options (command_class cmd_class, nullptr, option.show_cmd_cb, set_list, show_list); } + else if (option.type == var_zuinteger) + { + add_setshow_zuinteger_cmd (option.name, cmd_class, + option.var_address.zuinteger (option, data), + option.set_doc, option.show_doc, + option.help_doc, + nullptr, option.show_cmd_cb, + set_list, show_list); + } else if (option.type == var_zuinteger_unlimited) { add_setshow_zuinteger_unlimited_cmd diff --git a/gdb/cli/cli-option.h b/gdb/cli/cli-option.h index fc3aca887e7..b4dc2c36ce7 100644 --- a/gdb/cli/cli-option.h +++ b/gdb/cli/cli-option.h @@ -84,6 +84,7 @@ struct option_def { bool *(*boolean) (const option_def &, void *ctx); unsigned int *(*uinteger) (const option_def &, void *ctx); + unsigned int *(*zuinteger) (const option_def &, void *ctx); int *(*integer) (const option_def &, void *ctx); const char **(*enumeration) (const option_def &, void *ctx); char **(*string) (const option_def &, void *ctx); @@ -221,6 +222,26 @@ struct uinteger_option_def : option_def } }; +/* A var_zuinteger command line option. */ + +template +struct zuinteger_option_def : option_def +{ + zuinteger_option_def (const char *long_option_, + unsigned int *(*get_var_address_cb_) (Context *), + show_value_ftype *show_cmd_cb_, + const char *set_doc_, + const char *show_doc_ = nullptr, + const char *help_doc_ = nullptr) + : option_def (long_option_, var_zuinteger, + (erased_get_var_address_ftype *) get_var_address_cb_, + show_cmd_cb_, + set_doc_, show_doc_, help_doc_) + { + var_address.uinteger = detail::get_var_address; + } +}; + /* A var_zuinteger_unlimited command line option. */ template diff --git a/gdb/maint-test-options.c b/gdb/maint-test-options.c index 93d62eecc47..1e7145b3767 100644 --- a/gdb/maint-test-options.c +++ b/gdb/maint-test-options.c @@ -132,6 +132,7 @@ struct test_options_opts bool boolean_opt = false; const char *enum_opt = test_options_enum_values_xxx; unsigned int uint_opt = 0; + unsigned int zuint_opt = 0; int zuint_unl_opt = 0; char *string_opt = nullptr; char *filename_opt = nullptr; @@ -151,7 +152,7 @@ struct test_options_opts { fprintf_unfiltered (file, _("-flag %d -xx1 %d -xx2 %d -bool %d " - "-enum %s -uint %s -zuint-unl %s -string '%s' " + "-enum %s -uint %s -zuint %s -zuint-unl %s -string '%s' " "-filename '%s' -- %s\n"), flag_opt, xx1_opt, @@ -161,6 +162,7 @@ struct test_options_opts (uint_opt == UINT_MAX ? "unlimited" : pulongest (uint_opt)), + pulongest (zuint_opt), (zuint_unl_opt == -1 ? "unlimited" : plongest (zuint_unl_opt)), @@ -225,6 +227,16 @@ static const gdb::option::option_def test_options_option_defs[] = { N_("A help doc that spawns\nmultiple lines."), }, + /* A zuinteger option. */ + gdb::option::zuinteger_option_def { + "zuinteger", + [] (test_options_opts *opts) { return &opts->zuint_opt; }, + nullptr, /* show_cmd_cb */ + N_("A zuinteger option."), + nullptr, /* show_doc */ + nullptr, + }, + /* A zuinteger_unlimited option. */ gdb::option::zuinteger_unlimited_option_def { "zuinteger-unlimited", diff --git a/gdb/testsuite/gdb.base/options.exp b/gdb/testsuite/gdb.base/options.exp index 92b298064b2..3fcbd68a4e5 100644 --- a/gdb/testsuite/gdb.base/options.exp +++ b/gdb/testsuite/gdb.base/options.exp @@ -95,19 +95,19 @@ proc make_cmd {variant} { # test-options xxx", with no flag/option set. OPERAND is the expected # operand. proc expect_none {operand} { - return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '' -filename '' -- $operand" + return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint 0 -zuint-unl 0 -string '' -filename '' -- $operand" } # Return a string for the expected result of running "maint # test-options xxx", with -flag set. OPERAND is the expected operand. proc expect_flag {operand} { - return "-flag 1 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '' -filename '' -- $operand" + return "-flag 1 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint 0 -zuint-unl 0 -string '' -filename '' -- $operand" } # Return a string for the expected result of running "maint # test-options xxx", with -bool set. OPERAND is the expected operand. proc expect_bool {operand} { - return "-flag 0 -xx1 0 -xx2 0 -bool 1 -enum xxx -uint 0 -zuint-unl 0 -string '' -filename '' -- $operand" + return "-flag 0 -xx1 0 -xx2 0 -bool 1 -enum xxx -uint 0 -zuint 0 -zuint-unl 0 -string '' -filename '' -- $operand" } # Return a string for the expected result of running "maint @@ -116,9 +116,11 @@ proc expect_bool {operand} { # expected operand. proc expect_integer {option val operand} { if {$option == "uinteger"} { - return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint $val -zuint-unl 0 -string '' -filename '' -- $operand" + return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint $val -zuint 0 -zuint-unl 0 -string '' -filename '' -- $operand" + } elseif {$option == "zuinteger"} { + return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint $val -zuint-unl 0 -string '' -filename '' -- $operand" } elseif {$option == "zuinteger-unlimited"} { - return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl $val -string '' -filename '' -- $operand" + return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint 0 -zuint-unl $val -string '' -filename '' -- $operand" } else { error "unsupported option: $option" } @@ -141,7 +143,7 @@ proc dequote_expected_string {str} { # expected operand. proc expect_string {str operand} { set str [dequote_expected_string $str] - return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '$str' -filename '' -- $operand" + return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint 0 -zuint-unl 0 -string '$str' -filename '' -- $operand" } # Return a string for the expected result of running "maint @@ -149,7 +151,7 @@ proc expect_string {str operand} { # expected operand. proc expect_filename {filename operand} { set filename [dequote_expected_string $filename] - return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '' -filename '$filename' -- $operand" + return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint 0 -zuint-unl 0 -string '' -filename '$filename' -- $operand" } set all_options { @@ -161,6 +163,7 @@ set all_options { "-uinteger" "-xx1" "-xx2" + "-zuinteger" "-zuinteger-unlimited" } @@ -609,7 +612,7 @@ proc_with_prefix test-flag {variant} { # Extract twice the same flag, separated by one space. gdb_test "$cmd -xx1 -xx2 -xx1 -xx2 -xx1 -- non flags args" \ - "-flag 0 -xx1 1 -xx2 1 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '' -filename '' -- non flags args" + "-flag 0 -xx1 1 -xx2 1 -bool 0 -enum xxx -uint 0 -zuint 0 -zuint-unl 0 -string '' -filename '' -- non flags args" # Extract 2 known flags in front of unknown flags. gdb_test "$cmd -xx1 -xx2 -a -b -c -xx1 --" \ @@ -827,39 +830,49 @@ proc_with_prefix test-boolean {variant} { } # Uinteger option tests. OPTION is which integer option we're -# testing. Can be "uinteger" or "zuinteger-unlimited". +# testing. Can be "uinteger", "zuinteger" or "zuinteger-unlimited". proc_with_prefix test-uinteger {variant option} { global all_options set cmd "[make_cmd $variant] -$option" - # Test completing a uinteger option: - res_test_gdb_complete_multiple \ - "1 [expect_none ""]" \ - "$cmd " "" "" { - "NUMBER" - "unlimited" - } + # zuinteger have no completion. NUMBER is not present since it + # would be the only option available and therefore completed on. + if {$option != "zuinteger"} { - # NUMBER above is just a placeholder, make sure we don't complete - # it as a valid option. - res_test_gdb_complete_none \ - "1 [expect_none "NU"]" \ - "$cmd NU" + # Test completing a uinteger option: + res_test_gdb_complete_multiple \ + "1 [expect_none ""]" \ + "$cmd " "" "" { + "NUMBER" + "unlimited" + } - # "unlimited" is valid though. - res_test_gdb_complete_unique \ - "1 [expect_none "u"]" \ - "$cmd u" \ - "$cmd unlimited" + # NUMBER above is just a placeholder, make sure we don't complete + # it as a valid option. + res_test_gdb_complete_none \ + "1 [expect_none "NU"]" \ + "$cmd NU" + + # "unlimited" is valid though. + res_test_gdb_complete_unique \ + "1 [expect_none "u"]" \ + "$cmd u" \ + "$cmd unlimited" + } # Basic smoke test of accepted / not accepted values. gdb_test "$cmd 1 -- 999" [expect_integer $option "1" "999"] - gdb_test "$cmd unlimited -- 999" \ - [expect_integer $option "unlimited" "999"] + if {$option != "zuinteger"} { + gdb_test "$cmd unlimited -- 999" \ + [expect_integer $option "unlimited" "999"] + } if {$option == "zuinteger-unlimited"} { gdb_test "$cmd -1 --" [expect_integer $option "unlimited" ""] gdb_test "$cmd 0 --" [expect_integer $option "0" ""] + } elseif {$option == "zuinteger"} { + gdb_test "$cmd 0 --" [expect_integer $option "0" ""] + gdb_test "$cmd -1 --" "integer -1 out of range" } else { gdb_test "$cmd -1 --" "integer -1 out of range" gdb_test "$cmd 0 --" [expect_integer $option "unlimited" ""] @@ -870,7 +883,7 @@ proc_with_prefix test-uinteger {variant option} { "Expected integer at: unlimitedx --" # Don't offer completions until we're past the - # -uinteger/-zuinteger-unlimited argument. + # -uinteger/-zuinteger/-zuinteger-unlimited argument. res_test_gdb_complete_none \ "1 [expect_none ""]" \ "$cmd 1" @@ -890,6 +903,13 @@ proc_with_prefix test-uinteger {variant option} { "1 [expect_none ""]" \ "$cmd $value" } + } elseif {$option == "zuinteger"} { + # -1 is invalid uinteger. + foreach value {"-1" "-1 "} { + res_test_gdb_complete_none \ + "1 [expect_none ""]" \ + "$cmd $value" + } } else { # -1 is valid for zuinteger-unlimited. res_test_gdb_complete_none \ @@ -1121,7 +1141,7 @@ foreach_with_prefix cmd { test-misc $cmd test-flag $cmd test-boolean $cmd - foreach subcmd {"uinteger" "zuinteger-unlimited" } { + foreach subcmd {"uinteger" "zuinteger" "zuinteger-unlimited" } { test-uinteger $cmd $subcmd } test-enum $cmd -- 2.29.2