summaryrefslogtreecommitdiff
path: root/gdb/maint-test-options.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2019-07-03 16:57:49 +0100
committerPedro Alves <palves@redhat.com>2019-07-03 16:59:24 +0100
commit3d9be6f531db395a5ad940ef06e56d849f4de646 (patch)
treebfb290fae432f5dcc6186dba817d093ba5b872d6 /gdb/maint-test-options.c
parent41fc454c915057d9c5536617370c5eb2a5f71323 (diff)
downloadbinutils-gdb-3d9be6f531db395a5ad940ef06e56d849f4de646.tar.gz
Teach gdb::option about string options
A following patch will make the "pipe" command use the gdb::option framework for option processing. However, "pipe"'s only option today is a string option, "-d DELIM", and gdb::option does not support string options yet. This commit adds support for string options, mapped to var_string. For now, a string is parsed up until the first whitespace. I imagine that we'll need to add support for quoting so that we could do: (gdb) cmd -option 'some -string' without gdb confusing the "-string" for an option. This doesn't seem important for pipe, so I'm leaving it for another day. One thing I'm not happy with, is that the string data is managed as a raw malloc-allocated char *, which means that we need to xfree it manually. This is because var_string settings work that way too. Although with var_string settings we're leaking the strings at gdb exit, that was never really a problem. For options though, leaking is undesirable. I think we should tackle that for both settings and options at the same time, so for now I'm just managing the malloced data manually. It's a bit ugly in option_def_and_value, but at least that's hidden from view. For testing, this adds a new "-string" option to "maint test-settings", and then tweaks gdb.base/options.exp to exercise it. gdb/ChangeLog: 2019-07-03 Pedro Alves <palves@redhat.com> * cli/cli-option.c (union option_value) <string>: New field. (struct option_def_and_value): Add ctor, move ctor, dtor and use DISABLE_COPY_AND_ASSIGN. (option_def_and_value::clear_value): New. (parse_option, save_option_value_in_ctx, get_val_type_str) (add_setshow_cmds_for_options): Handle var_string. * cli-option.h (union option_def::var_address) <string>: New field. (struct string_option_def): New. * maint-test-options.c (struct test_options_opts): Add default ctor and use DISABLE_COPY_AND_ASSIGN. <string_opt>: New field. (test_options_opts::~test_options_opts): New. (test_options_opts::dump): Also dump "-string". (test_options_option_defs): Install "string. gdb/testsuite/ChangeLog: 2019-07-03 Pedro Alves <palves@redhat.com> * gdb.base/options.exp (expect_none, expect_flag, expect_bool) (expect_integer): Adjust to expect "-string". (expect_string): New. (all_options): Expect "-string". (test-flag, test-boolean): Adjust to expect "-string". (test-string): New proc. (top level): Call it.
Diffstat (limited to 'gdb/maint-test-options.c')
-rw-r--r--gdb/maint-test-options.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/gdb/maint-test-options.c b/gdb/maint-test-options.c
index 7e7ef6e7992..4caa865ae43 100644
--- a/gdb/maint-test-options.c
+++ b/gdb/maint-test-options.c
@@ -58,10 +58,10 @@
readline, for proper testing of TAB completion.
These maintenance commands support options of all the different
- available kinds of commands (boolean, enum, flag, uinteger):
+ available kinds of commands (boolean, enum, flag, string, uinteger):
(gdb) maint test-options require-delimiter -[TAB]
- -bool -enum -flag -uinteger -xx1 -xx2
+ -bool -enum -flag -string -uinteger -xx1 -xx2
(gdb) maint test-options require-delimiter -bool o[TAB]
off on
@@ -133,6 +133,16 @@ struct test_options_opts
const char *enum_opt = test_options_enum_values_xxx;
unsigned int uint_opt = 0;
int zuint_unl_opt = 0;
+ char *string_opt = nullptr;
+
+ test_options_opts () = default;
+
+ DISABLE_COPY_AND_ASSIGN (test_options_opts);
+
+ ~test_options_opts ()
+ {
+ xfree (string_opt);
+ }
/* Dump the options to FILE. ARGS is the remainder unprocessed
arguments. */
@@ -140,7 +150,7 @@ struct test_options_opts
{
fprintf_unfiltered (file,
_("-flag %d -xx1 %d -xx2 %d -bool %d "
- "-enum %s -uint %s -zuint-unl %s -- %s\n"),
+ "-enum %s -uint %s -zuint-unl %s -string '%s' -- %s\n"),
flag_opt,
xx1_opt,
xx2_opt,
@@ -152,6 +162,9 @@ struct test_options_opts
(zuint_unl_opt == -1
? "unlimited"
: plongest (zuint_unl_opt)),
+ (string_opt != nullptr
+ ? string_opt
+ : ""),
args);
}
};
@@ -216,6 +229,14 @@ static const gdb::option::option_def test_options_option_defs[] = {
nullptr, /* show_doc */
nullptr, /* help_doc */
},
+
+ /* A string option. */
+ gdb::option::string_option_def<test_options_opts> {
+ "string",
+ [] (test_options_opts *opts) { return &opts->string_opt; },
+ nullptr, /* show_cmd_cb */
+ N_("A string option."),
+ },
};
/* Create an option_def_group for the test_options_opts options, with