61 gdb::optional<option_value>
value;
65 gdb::optional<option_value> &&value_ = {})
68 value (std::move (value_))
87 if (
value.has_value ())
102 gdb::optional<option_value> &
value)
104 if (
value.has_value ())
107 value->string =
nullptr;
134 const char *p = args;
142 p = skip_to_space (p);
155 const char *text,
const char *word)
157 size_t textlen = strlen (text);
158 for (
const auto &grp : options_group)
159 for (
const auto &opt : grp.options)
160 if (strncmp (opt.name, text, textlen) == 0)
171 gdb::array_view<const option_def_group> options_group)
173 static const char opt[] =
"-";
180static gdb::optional<option_def_and_value>
187 if (*args ==
nullptr)
189 else if (**args !=
'-')
192 error (_(
"Unrecognized option at: %s"), *args);
199 const char *arg = *args + 1;
201 const char *after = skip_to_space (arg);
202 size_t len = after - arg;
204 void *match_ctx =
nullptr;
206 for (
const auto &grp : options_group)
208 for (
const auto &o : grp.options)
210 if (strncmp (o.name, arg, len) == 0)
212 if (match !=
nullptr)
214 if (completion !=
nullptr && arg[len] ==
'\0')
218 arg, completion->word);
222 error (_(
"Ambiguous option at: -%s"), arg);
228 if ((isspace (arg[len]) || arg[len] ==
'\0')
229 && strlen (o.name) == len)
235 if (match ==
nullptr)
238 error (_(
"Unrecognized option at: %s"), *args);
243 if (completion !=
nullptr && arg[len] ==
'\0')
246 arg, completion->word);
251 *args = skip_spaces (*args);
252 if (completion !=
nullptr)
253 completion->word = *args;
266 const char *val_str = *args;
269 if (**args ==
'\0' && completion !=
nullptr)
281 else if (**args ==
'-')
290 else if (**args ==
'\0')
304 const char *end = skip_to_space (*args);
305 if (completion !=
nullptr)
316 error (_(
"Value given for `-%s' is not a boolean: %.*s"),
317 match->
name, (
int) (end - val_str), val_str);
324 else if (completion !=
nullptr && **args ==
'\0')
341 static const char *
const all_boolean_enums[] = {
361 if (completion !=
nullptr)
369 completion->tracker.add_completion
370 (make_unique_xstrdup (
"NUMBER"));
371 completion->tracker.add_completion
372 (make_unique_xstrdup (
"unlimited"));
375 else if (startswith (
"unlimited", *args))
377 completion->tracker.add_completion
378 (make_unique_xstrdup (
"unlimited"));
398 if (completion !=
nullptr)
400 const char *after_arg = skip_to_space (*args);
401 if (*after_arg ==
'\0')
404 match->
enums, *args, *args);
405 if (completion->tracker.have_completions ())
433 error (_(
"-%s requires an argument"), match->
name);
436 const char *arg_start = *args;
437 std::string str = extract_string_maybe_quoted (args);
438 if (*args == arg_start)
439 error (_(
"-%s requires an argument"), match->
name);
442 val.
string =
new std::string (std::move (str));
448 gdb_assert_not_reached (
"option type not supported");
460 gdb::array_view<const option_def_group> options_group)
462 const char *text = *args;
467 bool have_delimiter = delimiter !=
nullptr;
469 if (text[0] ==
'-' && (!have_delimiter || *delimiter ==
'\0'))
475 *args = skip_spaces (*args);
476 completion_info.word = *args;
478 if (strcmp (*args,
"-") == 0)
481 completion_info.word);
483 else if (strcmp (*args,
"--") == 0)
487 else if (**args ==
'-')
489 gdb::optional<option_def_and_value> ov
491 args, &completion_info);
500 && !ov->value.has_value ())
525 && *args > text && !isspace ((*args)[-1]))
534 if (ov && ov->ctx !=
nullptr)
540 (completion_info.word - text);
553 if (completion_info.word[0] ==
'\0')
564 (completion_info.word - text);
569 else if (delimiter !=
nullptr)
584 switch (ov->option.type)
588 bool value = ov->
value.has_value () ? ov->value->boolean :
true;
589 *ov->option.var_address.boolean (ov->option, ov->ctx) =
value;
593 *ov->option.var_address.uinteger (ov->option, ov->ctx)
594 = ov->value->uinteger;
597 *ov->option.var_address.integer (ov->option, ov->ctx)
598 = ov->value->integer;
601 *ov->option.var_address.enumeration (ov->option, ov->ctx)
602 = ov->value->enumeration;
605 *ov->option.var_address.string (ov->option, ov->ctx)
606 = std::move (*ov->value->string);
609 gdb_assert_not_reached (
"unhandled option type");
618 gdb::array_view<const option_def_group> options_group)
620 if (*args ==
nullptr)
632 bool processed_any =
false;
636 *args = skip_spaces (*args);
638 auto ov =
parse_option (options_group, mode, have_delimiter, args);
646 processed_any =
true;
668 return "NUMBER|unlimited";
672 for (
size_t i = 0; opt.
enums[i] !=
nullptr; i++)
676 buffer += opt.
enums[i];
678 return buffer.c_str ();
694 const char *n = strchr (p,
'\n');
699 help.append (p, n - p + 1);
701 n = strchr (p,
'\n');
716 for (
const auto &o : options)
718 if (o.set_doc ==
nullptr)
725 if (val_type_str !=
nullptr)
728 help += val_type_str;
732 if (o.help_doc !=
nullptr)
744 gdb::array_view<const option_def_group> options_group)
746 bool need_newlines =
false;
747 std::string help_str;
749 const char *p = strstr (help_tmpl,
"%OPTIONS%");
750 help_str.assign (help_tmpl, p);
752 for (
const auto &grp : options_group)
753 for (
const auto &opt : grp.options)
758 need_newlines =
true;
762 p += strlen (
"%OPTIONS%");
773 gdb::array_view<const option_def> options,
777 for (
const auto &option : options)
786 set_list, show_list);
795 set_list, show_list);
800 (option.
name, cmd_class,
805 set_list, show_list);
815 set_list, show_list);
824 set_list, show_list);
827 gdb_assert_not_reached (
"option type not handled");
void add_completion(gdb::unique_xmalloc_ptr< char > name, completion_match_for_lcd *match_for_lcd=NULL, const char *text=NULL, const char *word=NULL)
bool have_completions() const
void advance_custom_word_point_by(int len)
void set_use_custom_word_point(bool enable)
set_show_commands add_setshow_uinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_string_cmd(const char *name, enum command_class theclass, std::string *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_zuinteger_unlimited_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_enum_cmd(const char *name, enum command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
const char *const boolean_enums[]
void complete_on_enum(completion_tracker &tracker, const char *const *enumlist, const char *text, const char *word)
int parse_cli_var_zuinteger_unlimited(const char **arg, bool expression)
unsigned int parse_cli_var_uinteger(var_types var_type, const char **arg, bool expression)
const char * parse_cli_var_enum(const char **args, const char *const *enums)
int parse_cli_boolean_value(const char **arg)
int check_for_argument(const char **str, const char *arg, int arg_len)
@ var_zuinteger_unlimited
gdb::unique_xmalloc_ptr< char > make_completion_match_str(const char *match_name, const char *text, const char *word)
bool process_options(const char **args, process_options_mode mode, gdb::array_view< const option_def_group > options_group)
static const char * get_val_type_str(const option_def &opt, std::string &buffer)
@ PROCESS_OPTIONS_REQUIRE_DELIMITER
@ PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
std::string build_help(const char *help_tmpl, gdb::array_view< const option_def_group > options_group)
static void complete_on_options(gdb::array_view< const option_def_group > options_group, completion_tracker &tracker, const char *text, const char *word)
static gdb::optional< option_def_and_value > parse_option(gdb::array_view< const option_def_group > options_group, process_options_mode mode, bool have_delimiter, const char **args, parse_option_completion_info *completion=nullptr)
static void append_indented_doc(const char *doc, std::string &help)
static void build_help_option(gdb::array_view< const option_def > options, std::string &help)
static void save_option_value_in_ctx(gdb::optional< option_def_and_value > &ov)
void complete_on_all_options(completion_tracker &tracker, gdb::array_view< const option_def_group > options_group)
bool complete_options(completion_tracker &tracker, const char **args, process_options_mode mode, gdb::array_view< const option_def_group > options_group)
void add_setshow_cmds_for_options(command_class cmd_class, void *data, gdb::array_view< const option_def > options, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static const char * find_end_options_delimiter(const char *args)
DISABLE_COPY_AND_ASSIGN(option_def_and_value)
static void clear_value(const option_def &option, gdb::optional< option_value > &value)
const option_def & option
gdb::optional< option_value > value
option_def_and_value(const option_def &option_, void *ctx_, gdb::optional< option_value > &&value_={})
option_def_and_value(option_def_and_value &&rval)
unsigned int *(* uinteger)(const option_def &, void *ctx)
union gdb::option::option_def::@26 var_address
show_value_ftype * show_cmd_cb
const char **(* enumeration)(const option_def &, void *ctx)
std::string *(* string)(const option_def &, void *ctx)
int *(* integer)(const option_def &, void *ctx)
const char *const * enums
bool *(* boolean)(const option_def &, void *ctx)
completion_tracker & tracker
value(struct type *type_)