61 gdb::optional<option_value>
value;
65 gdb::optional<option_value> &&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[] = {
370 completion->tracker.add_completion
371 (make_unique_xstrdup (
"NUMBER"));
373 l->literal !=
nullptr;
375 completion->tracker.add_completion
376 (make_unique_xstrdup (l->literal));
381 bool completions =
false;
383 l->literal !=
nullptr;
385 if (startswith (l->literal, *args))
387 completion->tracker.add_completion
388 (make_unique_xstrdup (l->literal));
408 if (completion !=
nullptr)
410 const char *after_arg = skip_to_space (*args);
411 if (*after_arg ==
'\0')
414 match->
enums, *args, *args);
415 if (completion->tracker.have_completions ())
443 error (_(
"-%s requires an argument"), match->
name);
446 const char *arg_start = *args;
447 std::string str = extract_string_maybe_quoted (args);
448 if (*args == arg_start)
449 error (_(
"-%s requires an argument"), match->
name);
452 val.
string =
new std::string (std::move (str));
458 gdb_assert_not_reached (
"option type not supported");
470 gdb::array_view<const option_def_group> options_group)
472 const char *text = *args;
477 bool have_delimiter = delimiter !=
nullptr;
479 if (text[0] ==
'-' && (!have_delimiter || *delimiter ==
'\0'))
485 *args = skip_spaces (*args);
486 completion_info.word = *args;
488 if (strcmp (*args,
"-") == 0)
491 completion_info.word);
493 else if (strcmp (*args,
"--") == 0)
497 else if (**args ==
'-')
499 gdb::optional<option_def_and_value> ov
501 args, &completion_info);
510 && !ov->value.has_value ())
535 && *args > text && !isspace ((*args)[-1]))
544 if (ov && ov->ctx !=
nullptr)
550 (completion_info.word - text);
563 if (completion_info.word[0] ==
'\0')
574 (completion_info.word - text);
579 else if (delimiter !=
nullptr)
594 switch (ov->option.type)
598 bool value = ov->
value.has_value () ? ov->value->boolean :
true;
599 *ov->option.var_address.boolean (ov->option, ov->ctx) =
value;
603 *ov->option.var_address.uinteger (ov->option, ov->ctx)
604 = ov->value->uinteger;
608 *ov->option.var_address.integer (ov->option, ov->ctx)
609 = ov->value->integer;
612 *ov->option.var_address.enumeration (ov->option, ov->ctx)
613 = ov->value->enumeration;
616 *ov->option.var_address.string (ov->option, ov->ctx)
617 = std::move (*ov->value->string);
620 gdb_assert_not_reached (
"unhandled option type");
629 gdb::array_view<const option_def_group> options_group)
631 if (*args ==
nullptr)
643 bool processed_any =
false;
647 *args = skip_spaces (*args);
649 auto ov =
parse_option (options_group, mode, have_delimiter, args);
657 processed_any =
true;
684 l->literal !=
nullptr;
688 buffer += l->literal;
690 return buffer.c_str ();
695 for (
size_t i = 0; opt.
enums[i] !=
nullptr; i++)
699 buffer += opt.
enums[i];
701 return buffer.c_str ();
717 const char *n = strchr (p,
'\n');
722 help.append (p, n - p + 1);
724 n = strchr (p,
'\n');
739 for (
const auto &o : options)
741 if (o.set_doc ==
nullptr)
748 if (val_type_str !=
nullptr)
751 help += val_type_str;
755 if (o.help_doc !=
nullptr)
767 gdb::array_view<const option_def_group> options_group)
769 bool need_newlines =
false;
770 std::string help_str;
772 const char *p = strstr (help_tmpl,
"%OPTIONS%");
773 help_str.assign (help_tmpl, p);
775 for (
const auto &grp : options_group)
776 for (
const auto &opt : grp.options)
781 need_newlines =
true;
785 p += strlen (
"%OPTIONS%");
796 gdb::array_view<const option_def> options,
800 for (
const auto &option : options)
805 option.var_address.boolean (option, data),
806 option.set_doc, option.show_doc,
808 nullptr, option.show_cmd_cb,
809 set_list, show_list);
814 option.var_address.uinteger (option, data),
815 option.extra_literals,
816 option.set_doc, option.show_doc,
818 nullptr, option.show_cmd_cb,
819 set_list, show_list);
824 option.var_address.integer (option, data),
825 option.extra_literals,
826 option.set_doc, option.show_doc,
828 nullptr, option.show_cmd_cb,
829 set_list, show_list);
834 option.var_address.integer (option, data),
835 option.extra_literals,
836 option.set_doc, option.show_doc,
838 nullptr, option.show_cmd_cb,
839 set_list, show_list);
845 option.var_address.enumeration (option, data),
846 option.set_doc, option.show_doc,
848 nullptr, option.show_cmd_cb,
849 set_list, show_list);
854 option.var_address.string (option, data),
855 option.set_doc, option.show_doc,
857 nullptr, option.show_cmd_cb,
858 set_list, show_list);
861 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_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_uinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const literal_def *extra_literals, 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_integer_cmd(const char *name, enum command_class theclass, int *var, const literal_def *extra_literals, 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)
set_show_commands add_setshow_pinteger_cmd(const char *name, enum command_class theclass, int *var, const literal_def *extra_literals, 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)
LONGEST parse_cli_var_integer(var_types var_type, const literal_def *extra_literals, 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)
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)
const char *const * enums
const literal_def * extra_literals
completion_tracker & tracker
value(struct type *type_)