From: Lancelot SIX <lsix@lancelotsix.com>
To: gdb-patches@sourceware.org
Cc: Lancelot SIX <lsix@lancelotsix.com>
Subject: [PATCH 2/3] gdb::option: Add support for zuinteger.
Date: Sat, 13 Feb 2021 22:07:51 +0000 [thread overview]
Message-ID: <20210213220752.32581-3-lsix@lancelotsix.com> (raw)
In-Reply-To: <20210213220752.32581-1-lsix@lancelotsix.com>
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<const option_def_group> 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<option_def_and_value> &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<typename Context>
+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<unsigned int, Context>;
+ }
+};
+
/* A var_zuinteger_unlimited command line option. */
template<typename Context>
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<test_options_opts> {
+ "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<test_options_opts> {
"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
next prev parent reply other threads:[~2021-02-13 22:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-13 22:07 [PATCH 0/3] Improve the add-inferior completer Lancelot SIX
2021-02-13 22:07 ` [PATCH 1/3] gdb::option: Add support for filename option Lancelot SIX
2021-02-16 17:45 ` Andrew Burgess
2021-02-16 18:52 ` Lancelot SIX
2021-02-17 10:20 ` Andrew Burgess
2021-02-13 22:07 ` Lancelot SIX [this message]
2021-02-13 22:07 ` [PATCH 3/3] Add completer to the add-inferior command Lancelot SIX
2021-02-16 17:04 ` Andrew Burgess
2021-02-16 18:10 ` Lancelot SIX
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=20210213220752.32581-3-lsix@lancelotsix.com \
--to=lsix@lancelotsix.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).