Don't include sys/personality.h in linux-low.cc anymore
[deliverable/binutils-gdb.git] / gdb / maint-test-options.c
index 7e7ef6e799261386af045e13b0ac20f76ba91d50..16ecd1dd7e58b711810dcc65c285295af7269298 100644 (file)
@@ -1,6 +1,6 @@
 /* Maintenance commands for testing the options framework.
 
-   Copyright (C) 2019 Free Software Foundation, Inc.
+   Copyright (C) 2019-2021 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    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
@@ -126,13 +126,23 @@ static const char *const test_options_enum_values_choices[] =
 
 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;
+
+  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
@@ -388,32 +409,21 @@ maintenance_test_options_unknown_is_operand_command_completer
 }
 
 /* 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,
+                       "maintenance test-options ", 0,
+                       &maintenancelist);
 
   const auto def_group = make_test_options_options_def_group (nullptr);
 
@@ -423,8 +433,8 @@ Command used for testing options processing.\n\
 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);
@@ -435,7 +445,6 @@ Command used for testing options processing.\n\
 Usage: maint test-options unknown-is-error [OPTION]... [OPERAND]...\n\
 \n\
 Options:\n\
-\n\
 %OPTIONS%"),
                               def_group);
 
@@ -445,7 +454,6 @@ Command used for testing options processing.\n\
 Usage: maint test-options unknown-is-operand [OPTION]... [OPERAND]...\n\
 \n\
 Options:\n\
-\n\
 %OPTIONS%"),
                               def_group);
 
This page took 0.026726 seconds and 4 git commands to generate.