/* Maintenance commands for testing the options framework.
- Copyright (C) 2019 Free Software Foundation, Inc.
+ Copyright (C) 2019-2023 Free Software Foundation, Inc.
This file is part of GDB.
available kinds of commands (boolean, enum, flag, string, uinteger):
(gdb) maint test-options require-delimiter -[TAB]
- -bool -enum -flag -string -uinteger -xx1 -xx2
+ -bool -pinteger-unlimited -xx1
+ -enum -string -xx2
+ -flag -uinteger-unlimited
(gdb) maint test-options require-delimiter -bool o[TAB]
off on
(gdb) maint test-options require-delimiter -enum [TAB]
xxx yyy zzz
- (gdb) maint test-options require-delimiter -uinteger [TAB]
+ (gdb) maint test-options require-delimiter -uinteger-unlimited [TAB]
NUMBER unlimited
'-xx1' and '-xx2' are flag options too. They exist in order to
Invoking the commands makes them print out the options parsed:
(gdb) maint test-options unknown-is-error -flag -enum yyy cmdarg
- -flag 1 -xx1 0 -xx2 0 -bool 0 -enum yyy -uint 0 -zuint-unl 0 -- cmdarg
+ -flag 1 -xx1 0 -xx2 0 -bool 0 -enum yyy -uint-unl 0 -pint-unl 0 -string '' -- cmdarg
(gdb) maint test-options require-delimiter -flag -enum yyy cmdarg
- -flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -- -flag -enum yyy cmdarg
+ -flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl 0 -pint-unl 0 -string '' -- -flag -enum yyy cmdarg
(gdb) maint test-options require-delimiter -flag -enum yyy cmdarg --
Unrecognized option at: cmdarg --
(gdb) maint test-options require-delimiter -flag -enum yyy -- cmdarg
- -flag 1 -xx1 0 -xx2 0 -bool 0 -enum yyy -uint 0 -zuint-unl 0 -- cmdarg
+ -flag 1 -xx1 0 -xx2 0 -bool 0 -enum yyy -uint-unl 0 -pint-unl 0 -string '' -- cmdarg
The "maint show test-options-completion-result" command exists in
order to do something similar for completion:
struct test_options_opts
{
- int flag_opt = 0;
- int xx1_opt = 0;
- int xx2_opt = 0;
- int boolean_opt = 0;
+ bool flag_opt = false;
+ bool xx1_opt = false;
+ bool xx2_opt = false;
+ bool boolean_opt = false;
const char *enum_opt = test_options_enum_values_xxx;
- unsigned int uint_opt = 0;
- int zuint_unl_opt = 0;
- char *string_opt = nullptr;
+ unsigned int uint_unl_opt = 0;
+ int pint_unl_opt = 0;
+ std::string string_opt;
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. */
void dump (ui_file *file, const char *args) const
{
- fprintf_unfiltered (file,
- _("-flag %d -xx1 %d -xx2 %d -bool %d "
- "-enum %s -uint %s -zuint-unl %s -string '%s' -- %s\n"),
- flag_opt,
- xx1_opt,
- xx2_opt,
- boolean_opt,
- enum_opt,
- (uint_opt == UINT_MAX
- ? "unlimited"
- : pulongest (uint_opt)),
- (zuint_unl_opt == -1
- ? "unlimited"
- : plongest (zuint_unl_opt)),
- (string_opt != nullptr
- ? string_opt
- : ""),
- args);
+ gdb_printf (file,
+ _("-flag %d -xx1 %d -xx2 %d -bool %d "
+ "-enum %s -uint-unl %s -pint-unl %s -string '%s' -- %s\n"),
+ flag_opt,
+ xx1_opt,
+ xx2_opt,
+ boolean_opt,
+ enum_opt,
+ (uint_unl_opt == UINT_MAX
+ ? "unlimited"
+ : pulongest (uint_unl_opt)),
+ (pint_unl_opt == -1
+ ? "unlimited"
+ : plongest (pint_unl_opt)),
+ string_opt.c_str (),
+ args);
}
};
N_("An enum option."),
},
- /* A uinteger option. */
+ /* A uinteger + "unlimited" option. */
gdb::option::uinteger_option_def<test_options_opts> {
- "uinteger",
- [] (test_options_opts *opts) { return &opts->uint_opt; },
+ "uinteger-unlimited",
+ [] (test_options_opts *opts) { return &opts->uint_unl_opt; },
+ uinteger_unlimited_literals,
nullptr, /* show_cmd_cb */
N_("A uinteger option."),
nullptr, /* show_doc */
N_("A help doc that spawns\nmultiple lines."),
},
- /* A zuinteger_unlimited option. */
- gdb::option::zuinteger_unlimited_option_def<test_options_opts> {
- "zuinteger-unlimited",
- [] (test_options_opts *opts) { return &opts->zuint_unl_opt; },
+ /* A pinteger + "unlimited" option. */
+ gdb::option::pinteger_option_def<test_options_opts> {
+ "pinteger-unlimited",
+ [] (test_options_opts *opts) { return &opts->pint_unl_opt; },
+ pinteger_unlimited_literals,
nullptr, /* show_cmd_cb */
- N_("A zuinteger-unlimited option."),
+ N_("A pinteger-unlimited option."),
nullptr, /* show_doc */
nullptr, /* help_doc */
},
maintenance_show_test_options_completion_result (const char *args,
int from_tty)
{
- puts_filtered (maintenance_test_options_command_completion_text.c_str ());
+ gdb_puts (maintenance_test_options_command_completion_text.c_str ());
}
/* Save the completion result in the global variables read by the
stream.puts ("1 ");
opts.dump (&stream, text);
- maintenance_test_options_command_completion_text
- = std::move (stream.string ());
+ maintenance_test_options_command_completion_text = stream.release ();
}
else
{
}
/* Command list for maint test-options. */
-struct cmd_list_element *maintenance_test_options_list;
-
-/* The "maintenance test-options" prefix command. */
-
-static void
-maintenance_test_options_command (const char *arg, int from_tty)
-{
- printf_unfiltered
- (_("\"maintenance test-options\" must be followed "
- "by the name of a subcommand.\n"));
- help_list (maintenance_test_options_list, "maintenance test-options ",
- all_commands, gdb_stdout);
-}
+static cmd_list_element *maintenance_test_options_list;
\f
+void _initialize_maint_test_options ();
void
_initialize_maint_test_options ()
{
cmd_list_element *cmd;
- add_prefix_cmd ("test-options", no_class, maintenance_test_options_command,
- _("\
+ add_basic_prefix_cmd ("test-options", no_class,
+ _("\
Generic command for testing the options infrastructure."),
- &maintenance_test_options_list,
- "maintenance test-options ", 0,
- &maintenancelist);
+ &maintenance_test_options_list,
+ 0, &maintenancelist);
const auto def_group = make_test_options_options_def_group (nullptr);
Usage: maint test-options require-delimiter [[OPTION]... --] [OPERAND]...\n\
\n\
Options:\n\
-\n\
%OPTIONS%\n\
+\n\
If you specify any command option, you must use a double dash (\"--\")\n\
to mark the end of option processing."),
def_group);
Usage: maint test-options unknown-is-error [OPTION]... [OPERAND]...\n\
\n\
Options:\n\
-\n\
%OPTIONS%"),
def_group);
Usage: maint test-options unknown-is-operand [OPTION]... [OPERAND]...\n\
\n\
Options:\n\
-\n\
%OPTIONS%"),
def_group);