diff options
Diffstat (limited to 'gdb/cli')
| -rw-r--r-- | gdb/cli/cli-cmds.c | 137 | ||||
| -rw-r--r-- | gdb/cli/cli-decode.c | 147 | ||||
| -rw-r--r-- | gdb/cli/cli-decode.h | 12 | ||||
| -rw-r--r-- | gdb/cli/cli-dump.c | 100 | ||||
| -rw-r--r-- | gdb/cli/cli-interp.c | 4 | ||||
| -rw-r--r-- | gdb/cli/cli-logging.c | 6 | ||||
| -rw-r--r-- | gdb/cli/cli-option.c | 4 | ||||
| -rw-r--r-- | gdb/cli/cli-script.c | 20 | ||||
| -rw-r--r-- | gdb/cli/cli-setshow.c | 25 | ||||
| -rw-r--r-- | gdb/cli/cli-style.c | 112 | ||||
| -rw-r--r-- | gdb/cli/cli-style.h | 14 | ||||
| -rw-r--r-- | gdb/cli/cli-utils.c | 34 | ||||
| -rw-r--r-- | gdb/cli/cli-utils.h | 6 |
13 files changed, 403 insertions, 218 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 7e13ef8..cf5571c 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -19,7 +19,6 @@ #include "arch-utils.h" #include "exceptions.h" -#include "readline/tilde.h" #include "completer.h" #include "target.h" #include "gdbsupport/gdb_wait.h" @@ -51,6 +50,7 @@ #include "cli/cli-cmds.h" #include "cli/cli-style.h" #include "cli/cli-utils.h" +#include "terminal.h" #include "extension.h" #include "gdbsupport/pathstuff.h" @@ -300,8 +300,8 @@ with_command_completer_1 (const char *set_cmd_prefix, command as if it was a "set" command. */ if (delim == text || delim == nullptr - || !isspace (delim[-1]) - || !(isspace (delim[2]) || delim[2] == '\0')) + || !c_isspace (delim[-1]) + || !(c_isspace (delim[2]) || delim[2] == '\0')) { std::string new_text = std::string (set_cmd_prefix) + text; tracker.advance_custom_word_point_by (-(int) strlen (set_cmd_prefix)); @@ -519,7 +519,7 @@ cd_command (const char *dir, int from_tty) dont_repeat (); gdb::unique_xmalloc_ptr<char> dir_holder - (tilde_expand (dir != NULL ? dir : "~")); + = gdb_rl_tilde_expand (dir != NULL ? dir : "~"); dir = dir_holder.get (); if (chdir (dir) < 0) @@ -637,7 +637,8 @@ find_and_open_script (const char *script_file, int search_path) openp_flags search_flags = OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH; std::optional<open_script> opened; - gdb::unique_xmalloc_ptr<char> file (tilde_expand (script_file)); + gdb::unique_xmalloc_ptr<char> file + = gdb_rl_tilde_expand (script_file); if (search_path) search_flags |= OPF_SEARCH_IN_PATH; @@ -784,14 +785,14 @@ source_command (const char *args, int from_tty) if (args[0] != '-') break; - if (args[1] == 'v' && isspace (args[2])) + if (args[1] == 'v' && c_isspace (args[2])) { source_verbose = 1; /* Skip passed -v. */ args = &args[3]; } - else if (args[1] == 's' && isspace (args[2])) + else if (args[1] == 's' && c_isspace (args[2])) { search_path = 1; @@ -833,7 +834,7 @@ echo_command (const char *text, int from_tty) gdb_printf ("%c", c); } - gdb_stdout->reset_style (); + gdb_stdout->emit_style_escape (ui_file_style ()); /* Force this output to appear now. */ gdb_flush (gdb_stdout); @@ -949,9 +950,27 @@ shell_escape (const char *arg, int from_tty) static void shell_command (const char *arg, int from_tty) { + scoped_gdb_ttystate save_restore_gdb_ttystate; + restore_initial_gdb_ttystate (); + shell_escape (arg, from_tty); } +/* Completion for the shell command. Currently, this just uses filename + completion, but we could, potentially, complete command names from $PATH + for the first word, which would make this even more shell like. */ + +static void +shell_command_completer (struct cmd_list_element *ignore, + completion_tracker &tracker, + const char *text, const char * /* word */) +{ + tracker.set_use_custom_word_point (true); + const char *word + = advance_to_filename_maybe_quoted_complete_word_point (tracker, text); + filename_maybe_quoted_completer (ignore, tracker, text, word); +} + static void edit_command (const char *arg, int from_tty) { @@ -1020,7 +1039,7 @@ edit_command (const char *arg, int from_tty) paddress (get_current_arch (), sal.pc)); gdbarch = sal.symtab->compunit ()->objfile ()->arch (); - sym = find_pc_function (sal.pc); + sym = find_symbol_for_pc (sal.pc); if (sym) gdb_printf ("%ps is in %ps (%ps:%ps).\n", styled_string (address_style.style (), @@ -1165,7 +1184,7 @@ pipe_command_completer (struct cmd_list_element *ignore, delimiter = opts.delimiter.c_str (); /* Check if we're past option values already. */ - if (text > org_text && !isspace (text[-1])) + if (text > org_text && !c_isspace (text[-1])) return; const char *delim = strstr (text, delimiter); @@ -1178,8 +1197,32 @@ pipe_command_completer (struct cmd_list_element *ignore, return; } - /* We're past the delimiter. What follows is a shell command, which - we don't know how to complete. */ + /* We're past the delimiter now, or at least, DELIM points to the + delimiter string. Update TEXT to point to the start of whatever + appears after the delimiter. */ + text = skip_spaces (delim + strlen (delimiter)); + + /* We really are past the delimiter now, so offer completions. This is + like GDB's "shell" command, currently we only offer filename + completion, but in the future this could be improved by offering + completion of command names from $PATH. + + What we don't do here is offer completions for the empty string. It + is assumed that the first word after the delimiter is going to be a + command name from $PATH, not a filename, so if the user has typed + nothing (yet) and tries to complete, there's no point offering a list + of files from the current directory. + + Once the user has started to type something though, then we do start + offering filename completions. */ + if (*text == '\0') + return; + + tracker.set_use_custom_word_point (true); + tracker.advance_custom_word_point_by (text - org_text); + const char *word + = advance_to_filename_maybe_quoted_complete_word_point (tracker, text); + filename_maybe_quoted_completer (ignore, tracker, text, word); } /* Helper for the list_command function. Prints the lines around (and @@ -1269,7 +1312,7 @@ list_command (const char *arg, int from_tty) selected frame, and finding the line associated to it. */ frame_info_ptr frame = get_selected_frame (nullptr); CORE_ADDR curr_pc = get_frame_pc (frame); - cursal = find_pc_line (curr_pc, 0); + cursal = find_sal_for_pc (curr_pc, 0); if (cursal.symtab == nullptr) error @@ -1432,16 +1475,24 @@ list_command (const char *arg, int from_tty) paddress (get_current_arch (), sal.pc)); gdbarch = sal.symtab->compunit ()->objfile ()->arch (); - sym = find_pc_function (sal.pc); + sym = find_symbol_for_pc (sal.pc); if (sym) - gdb_printf ("%s is in %s (%s:%d).\n", - paddress (gdbarch, sal.pc), + gdb_printf ("%ps is in %s (%ps:%ps).\n", + styled_string (address_style.style (), + paddress (gdbarch, sal.pc)), sym->print_name (), - symtab_to_filename_for_display (sal.symtab), sal.line); + styled_string (file_name_style.style (), + symtab_to_filename_for_display (sal.symtab)), + styled_string (line_number_style.style (), + pulongest (sal.line))); else - gdb_printf ("%s is at %s:%d.\n", - paddress (gdbarch, sal.pc), - symtab_to_filename_for_display (sal.symtab), sal.line); + gdb_printf ("%ps is at %ps:%ps.\n", + styled_string (address_style.style (), + paddress (gdbarch, sal.pc)), + styled_string (file_name_style.style (), + symtab_to_filename_for_display (sal.symtab)), + styled_string (line_number_style.style (), + pulongest (sal.line))); } /* If line was not specified by just a line number, and it does not @@ -1626,7 +1677,7 @@ disassemble_command (const char *arg, int from_tty) if (*p == '\0') error (_("Missing modifier.")); - while (*p && ! isspace (*p)) + while (*p && ! c_isspace (*p)) { switch (*p++) { @@ -1895,8 +1946,8 @@ alias_command_completer (struct cmd_list_element *ignore, typing COMMAND DEFAULT-ARGS... */ if (delim != text && delim != nullptr - && isspace (delim[-1]) - && (isspace (delim[1]) || delim[1] == '\0')) + && c_isspace (delim[-1]) + && (c_isspace (delim[1]) || delim[1] == '\0')) { std::string new_text = std::string (delim + 1); @@ -2131,8 +2182,17 @@ print_sal_location (const symtab_and_line &sal) const char *sym_name = NULL; if (sal.symbol != NULL) sym_name = sal.symbol->print_name (); - gdb_printf (_("file: \"%s\", line number: %ps, symbol: \"%s\"\n"), - symtab_to_filename_for_display (sal.symtab), + else if (CORE_ADDR line_pc; + find_pc_for_line (sal.symtab, sal.line, &line_pc)) + { + struct symbol *sym = find_symbol_for_pc (line_pc); + if (sym != nullptr) + sym_name = sym->print_name (); + } + + gdb_printf (_("file: \"%ps\", line number: %ps, symbol: \"%s\"\n"), + styled_string (file_name_style.style (), + symtab_to_filename_for_display (sal.symtab)), styled_string (line_number_style.style (), pulongest (sal.line)), sym_name != NULL ? sym_name : "???"); @@ -2185,7 +2245,7 @@ cmp_symtabs (const symtab_and_line &sala, const symtab_and_line &salb) return r; } - r = filename_cmp (sala.symtab->filename, salb.symtab->filename); + r = filename_cmp (sala.symtab->filename (), salb.symtab->filename ()); if (r) return r; @@ -2578,15 +2638,27 @@ shell_internal_fn (struct gdbarch *gdbarch, return value::allocate_optimized_out (int_type); } -void _initialize_cli_cmds (); -void -_initialize_cli_cmds () +INIT_GDB_FILE (cli_cmds) { struct cmd_list_element *c; /* Define the classes of commands. They will appear in the help list in alphabetical order. */ + add_cmd ("essential", class_essential, _("\ +GDB essential commands.\n\ +Welcome to GDB! This help text aims to provide a quickstart explanation\n\ +that will allow you to start using GDB. Feel free to use \"help <cmd>\"\n\ +to get further explanations for any command <cmd>, and check the online\n\ +documentation for in-depth explanations.\n\ +Here are some common GDB behaviors that you can expect, which are\n\ +not tied to any specific command but rather GDB functionality itself:\n\ +\n\ +EXPR is any arbitrary expression valid for the current programming language.\n\ +Pressing <return> with an empty prompt executes the last command again.\n\ +You can use <tab> to complete commands and symbols. Pressing it twice lists\n\ +all possible completions if more than one is available."), + &cmdlist); add_cmd ("internals", class_maintenance, _("\ Maintenance commands.\n\ Some gdb commands are provided just for use by gdb maintainers.\n\ @@ -2803,7 +2875,7 @@ the previous command number shown."), = add_com ("shell", class_support, shell_command, _("\ Execute the rest of the line as a shell command.\n\ With no arguments, run an inferior shell.")); - set_cmd_completer (shell_cmd, deprecated_filename_completer); + set_cmd_completer_handle_brkchars (shell_cmd, shell_command_completer); add_com_alias ("!", shell_cmd, class_support, 0); @@ -2839,7 +2911,7 @@ and send its output to SHELL_COMMAND.")); add_com_alias ("|", pipe_cmd, class_support, 0); cmd_list_element *list_cmd - = add_com ("list", class_files, list_command, _("\ + = add_com ("list", class_files | class_essential, list_command, _("\ List specified function or line.\n\ With no argument, lists ten more lines after or around previous listing.\n\ \"list +\" lists the ten lines following a previous ten-line listing.\n\ @@ -2861,6 +2933,7 @@ This can be changed using \"set listsize\", and the current value\n\ can be shown using \"show listsize\".")); add_com_alias ("l", list_cmd, class_files, 1); + set_cmd_completer(list_cmd, location_completer); c = add_com ("disassemble", class_vars, disassemble_command, _("\ Disassemble a specified section of memory.\n\ @@ -2899,7 +2972,7 @@ Show definitions of non-python/scheme user defined commands.\n\ Argument is the name of the user defined command.\n\ With no argument, show definitions of all user defined commands."), &showlist); set_cmd_completer (c, show_user_completer); - add_com ("apropos", class_support, apropos_command, _("\ + add_com ("apropos", class_support | class_essential, apropos_command, _("\ Search for commands matching a REGEXP.\n\ Usage: apropos [-v] REGEXP\n\ Flag -v indicates to produce a verbose output, showing full documentation\n\ diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 48a3466..6a7d07a 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -16,7 +16,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "symtab.h" -#include <ctype.h> #include "gdbsupport/gdb_regex.h" #include "completer.h" #include "ui-out.h" @@ -42,7 +41,7 @@ static struct cmd_list_element *find_cmd (const char *command, int *nfound); static void help_cmd_list (struct cmd_list_element *list, - enum command_class theclass, + command_classes theclass, bool recurse, struct ui_file *stream); @@ -189,11 +188,11 @@ cmd_list_element::command_components () const Add this command to command list *LIST. - Returns a pointer to the added command (not necessarily the head + Returns a pointer to the added command (not necessarily the head of *LIST). */ static struct cmd_list_element * -do_add_cmd (const char *name, enum command_class theclass, +do_add_cmd (const char *name, command_classes theclass, const char *doc, struct cmd_list_element **list) { struct cmd_list_element *c = new struct cmd_list_element (name, theclass, @@ -245,7 +244,7 @@ do_add_cmd (const char *name, enum command_class theclass, } struct cmd_list_element * -add_cmd (const char *name, enum command_class theclass, +add_cmd (const char *name, command_classes theclass, const char *doc, struct cmd_list_element **list) { cmd_list_element *result = do_add_cmd (name, theclass, doc, list); @@ -255,7 +254,7 @@ add_cmd (const char *name, enum command_class theclass, } struct cmd_list_element * -add_cmd (const char *name, enum command_class theclass, +add_cmd (const char *name, command_classes theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **list) { @@ -267,7 +266,7 @@ add_cmd (const char *name, enum command_class theclass, /* Add an element with a suppress notification to the LIST of commands. */ struct cmd_list_element * -add_cmd_suppress_notification (const char *name, enum command_class theclass, +add_cmd_suppress_notification (const char *name, command_classes theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **list, bool *suppress_notification) @@ -307,7 +306,7 @@ deprecate_cmd (struct cmd_list_element *cmd, const char *replacement) struct cmd_list_element * add_alias_cmd (const char *name, cmd_list_element *target, - enum command_class theclass, int abbrev_flag, + command_classes theclass, int abbrev_flag, struct cmd_list_element **list) { gdb_assert (target != nullptr); @@ -369,7 +368,7 @@ update_prefix_field_of_prefixed_commands (struct cmd_list_element *c) containing that list. */ struct cmd_list_element * -add_prefix_cmd (const char *name, enum command_class theclass, +add_prefix_cmd (const char *name, command_classes theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list) @@ -403,7 +402,7 @@ do_prefix_cmd (const char *args, int from_tty, struct cmd_list_element *c) /* See command.h. */ struct cmd_list_element * -add_basic_prefix_cmd (const char *name, enum command_class theclass, +add_basic_prefix_cmd (const char *name, command_classes theclass, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list) { @@ -426,7 +425,7 @@ do_show_prefix_cmd (const char *args, int from_tty, struct cmd_list_element *c) /* See command.h. */ struct cmd_list_element * -add_show_prefix_cmd (const char *name, enum command_class theclass, +add_show_prefix_cmd (const char *name, command_classes theclass, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list) { @@ -440,7 +439,7 @@ add_show_prefix_cmd (const char *name, enum command_class theclass, /* See command.h. */ set_show_commands -add_setshow_prefix_cmd (const char *name, command_class theclass, +add_setshow_prefix_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, cmd_list_element **set_subcommands_list, cmd_list_element **show_subcommands_list, @@ -464,7 +463,7 @@ add_setshow_prefix_cmd (const char *name, command_class theclass, struct cmd_list_element * add_prefix_cmd_suppress_notification - (const char *name, enum command_class theclass, + (const char *name, command_classes theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list, @@ -480,7 +479,7 @@ add_prefix_cmd_suppress_notification /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */ struct cmd_list_element * -add_abbrev_prefix_cmd (const char *name, enum command_class theclass, +add_abbrev_prefix_cmd (const char *name, command_classes theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list) @@ -520,7 +519,7 @@ empty_func (const char *args, int from_tty, cmd_list_element *c) static struct cmd_list_element * add_set_or_show_cmd (const char *name, enum cmd_types type, - enum command_class theclass, + command_classes theclass, var_types var_type, const literal_def *extra_literals, const setting::erased_args &arg, @@ -552,7 +551,7 @@ add_set_or_show_cmd (const char *name, static set_show_commands add_setshow_cmd_full_erased (const char *name, - enum command_class theclass, + command_classes theclass, var_types var_type, const literal_def *extra_literals, const setting::erased_args &args, @@ -640,7 +639,7 @@ integer_literals_completer (struct cmd_list_element *c, template<typename T> static set_show_commands add_setshow_cmd_full (const char *name, - enum command_class theclass, + command_classes theclass, var_types var_type, T *var, const literal_def *extra_literals, const char *set_doc, const char *show_doc, @@ -677,7 +676,7 @@ add_setshow_cmd_full (const char *name, template<typename T> static set_show_commands add_setshow_cmd_full (const char *name, - enum command_class theclass, + command_classes theclass, var_types var_type, T *var, const char *set_doc, const char *show_doc, const char *help_doc, @@ -701,7 +700,7 @@ add_setshow_cmd_full (const char *name, set_show_commands add_setshow_enum_cmd (const char *name, - enum command_class theclass, + command_classes theclass, const char *const *enumlist, const char **var, const char *set_doc, @@ -735,7 +734,7 @@ add_setshow_enum_cmd (const char *name, to a global storage buffer. */ set_show_commands -add_setshow_enum_cmd (const char *name, command_class theclass, +add_setshow_enum_cmd (const char *name, command_classes theclass, const char *const *enumlist, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<const char *>::set set_func, @@ -791,7 +790,7 @@ color_completer (struct cmd_list_element *ignore, set_show_commands add_setshow_color_cmd (const char *name, - enum command_class theclass, + command_classes theclass, ui_file_style::color *var, const char *set_doc, const char *show_doc, @@ -816,7 +815,7 @@ add_setshow_color_cmd (const char *name, to a global storage buffer. */ set_show_commands -add_setshow_color_cmd (const char *name, command_class theclass, +add_setshow_color_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<ui_file_style::color>::set set_func, @@ -846,7 +845,7 @@ const char * const auto_boolean_enums[] = { "on", "off", "auto", NULL }; set_show_commands add_setshow_auto_boolean_cmd (const char *name, - enum command_class theclass, + command_classes theclass, enum auto_boolean *var, const char *set_doc, const char *show_doc, const char *help_doc, @@ -870,7 +869,7 @@ add_setshow_auto_boolean_cmd (const char *name, to a global storage buffer. */ set_show_commands -add_setshow_auto_boolean_cmd (const char *name, command_class theclass, +add_setshow_auto_boolean_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<enum auto_boolean>::set set_func, @@ -902,7 +901,7 @@ const char * const boolean_enums[] = { "on", "off", NULL }; Returns the new command element. */ set_show_commands -add_setshow_boolean_cmd (const char *name, enum command_class theclass, bool *var, +add_setshow_boolean_cmd (const char *name, command_classes theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, @@ -925,7 +924,7 @@ add_setshow_boolean_cmd (const char *name, enum command_class theclass, bool *va to a global storage buffer. */ set_show_commands -add_setshow_boolean_cmd (const char *name, command_class theclass, +add_setshow_boolean_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<bool>::set set_func, @@ -948,7 +947,7 @@ add_setshow_boolean_cmd (const char *name, command_class theclass, list for set/show or some sublist thereof). */ set_show_commands -add_setshow_filename_cmd (const char *name, enum command_class theclass, +add_setshow_filename_cmd (const char *name, command_classes theclass, std::string *var, const char *set_doc, const char *show_doc, const char *help_doc, @@ -972,7 +971,7 @@ add_setshow_filename_cmd (const char *name, enum command_class theclass, to a global storage buffer. */ set_show_commands -add_setshow_filename_cmd (const char *name, command_class theclass, +add_setshow_filename_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<std::string>::set set_func, @@ -996,7 +995,7 @@ add_setshow_filename_cmd (const char *name, command_class theclass, list for set/show or some sublist thereof). */ set_show_commands -add_setshow_string_cmd (const char *name, enum command_class theclass, +add_setshow_string_cmd (const char *name, command_classes theclass, std::string *var, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1021,7 +1020,7 @@ add_setshow_string_cmd (const char *name, enum command_class theclass, to a global storage buffer. */ set_show_commands -add_setshow_string_cmd (const char *name, command_class theclass, +add_setshow_string_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<std::string>::set set_func, @@ -1046,7 +1045,7 @@ add_setshow_string_cmd (const char *name, command_class theclass, list for set/show or some sublist thereof). */ set_show_commands -add_setshow_string_noescape_cmd (const char *name, enum command_class theclass, +add_setshow_string_noescape_cmd (const char *name, command_classes theclass, std::string *var, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1071,7 +1070,7 @@ add_setshow_string_noescape_cmd (const char *name, enum command_class theclass, to a global storage buffer. */ set_show_commands -add_setshow_string_noescape_cmd (const char *name, command_class theclass, +add_setshow_string_noescape_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<std::string>::set set_func, @@ -1097,7 +1096,7 @@ add_setshow_string_noescape_cmd (const char *name, command_class theclass, list for set/show or some sublist thereof). */ set_show_commands -add_setshow_optional_filename_cmd (const char *name, enum command_class theclass, +add_setshow_optional_filename_cmd (const char *name, command_classes theclass, std::string *var, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1121,7 +1120,7 @@ add_setshow_optional_filename_cmd (const char *name, enum command_class theclass to a global storage buffer. */ set_show_commands -add_setshow_optional_filename_cmd (const char *name, command_class theclass, +add_setshow_optional_filename_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<std::string>::set set_func, @@ -1148,7 +1147,7 @@ add_setshow_optional_filename_cmd (const char *name, command_class theclass, function is only used in Python API. Please don't use it elsewhere. */ set_show_commands -add_setshow_integer_cmd (const char *name, enum command_class theclass, +add_setshow_integer_cmd (const char *name, command_classes theclass, int *var, const literal_def *extra_literals, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1169,7 +1168,7 @@ add_setshow_integer_cmd (const char *name, enum command_class theclass, to a global storage buffer. */ set_show_commands -add_setshow_integer_cmd (const char *name, command_class theclass, +add_setshow_integer_cmd (const char *name, command_classes theclass, const literal_def *extra_literals, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1197,7 +1196,7 @@ const literal_def integer_unlimited_literals[] = to a global storage buffer. */ set_show_commands -add_setshow_integer_cmd (const char *name, enum command_class theclass, +add_setshow_integer_cmd (const char *name, command_classes theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1219,7 +1218,7 @@ add_setshow_integer_cmd (const char *name, enum command_class theclass, to a global storage buffer. */ set_show_commands -add_setshow_integer_cmd (const char *name, command_class theclass, +add_setshow_integer_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<int>::set set_func, @@ -1242,7 +1241,7 @@ add_setshow_integer_cmd (const char *name, command_class theclass, value. SET_DOC and SHOW_DOC are the documentation strings. */ set_show_commands -add_setshow_pinteger_cmd (const char *name, enum command_class theclass, +add_setshow_pinteger_cmd (const char *name, command_classes theclass, int *var, const literal_def *extra_literals, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1263,7 +1262,7 @@ add_setshow_pinteger_cmd (const char *name, enum command_class theclass, to a global storage buffer. */ set_show_commands -add_setshow_pinteger_cmd (const char *name, command_class theclass, +add_setshow_pinteger_cmd (const char *name, command_classes theclass, const literal_def *extra_literals, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1286,7 +1285,7 @@ add_setshow_pinteger_cmd (const char *name, command_class theclass, value. SET_DOC and SHOW_DOC are the documentation strings. */ set_show_commands -add_setshow_uinteger_cmd (const char *name, enum command_class theclass, +add_setshow_uinteger_cmd (const char *name, command_classes theclass, unsigned int *var, const literal_def *extra_literals, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1307,7 +1306,7 @@ add_setshow_uinteger_cmd (const char *name, enum command_class theclass, to a global storage buffer. */ set_show_commands -add_setshow_uinteger_cmd (const char *name, command_class theclass, +add_setshow_uinteger_cmd (const char *name, command_classes theclass, const literal_def *extra_literals, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1337,7 +1336,7 @@ const literal_def uinteger_unlimited_literals[] = to a global storage buffer. */ set_show_commands -add_setshow_uinteger_cmd (const char *name, enum command_class theclass, +add_setshow_uinteger_cmd (const char *name, command_classes theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1359,7 +1358,7 @@ add_setshow_uinteger_cmd (const char *name, enum command_class theclass, to a global storage buffer. */ set_show_commands -add_setshow_uinteger_cmd (const char *name, command_class theclass, +add_setshow_uinteger_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<unsigned int>::set set_func, @@ -1384,7 +1383,7 @@ add_setshow_uinteger_cmd (const char *name, command_class theclass, value. SET_DOC and SHOW_DOC are the documentation strings. */ set_show_commands -add_setshow_zinteger_cmd (const char *name, enum command_class theclass, +add_setshow_zinteger_cmd (const char *name, command_classes theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1403,7 +1402,7 @@ add_setshow_zinteger_cmd (const char *name, enum command_class theclass, to a global storage buffer. */ set_show_commands -add_setshow_zinteger_cmd (const char *name, command_class theclass, +add_setshow_zinteger_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<int>::set set_func, @@ -1430,7 +1429,7 @@ const literal_def pinteger_unlimited_literals[] = set_show_commands add_setshow_zuinteger_unlimited_cmd (const char *name, - enum command_class theclass, + command_classes theclass, int *var, const char *set_doc, const char *show_doc, @@ -1453,7 +1452,7 @@ add_setshow_zuinteger_unlimited_cmd (const char *name, to a global storage buffer. */ set_show_commands -add_setshow_zuinteger_unlimited_cmd (const char *name, command_class theclass, +add_setshow_zuinteger_unlimited_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<int>::set set_func, @@ -1477,7 +1476,7 @@ add_setshow_zuinteger_unlimited_cmd (const char *name, command_class theclass, value. SET_DOC and SHOW_DOC are the documentation strings. */ set_show_commands -add_setshow_zuinteger_cmd (const char *name, enum command_class theclass, +add_setshow_zuinteger_cmd (const char *name, command_classes theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, @@ -1496,7 +1495,7 @@ add_setshow_zuinteger_cmd (const char *name, enum command_class theclass, to a global storage buffer. */ set_show_commands -add_setshow_zuinteger_cmd (const char *name, command_class theclass, +add_setshow_zuinteger_cmd (const char *name, command_classes theclass, const char *set_doc, const char *show_doc, const char *help_doc, setting_func_types<unsigned int>::set set_func, @@ -1597,7 +1596,7 @@ add_info_alias (const char *name, cmd_list_element *target, int abbrev_flag) /* Add an element to the list of commands. */ struct cmd_list_element * -add_com (const char *name, enum command_class theclass, +add_com (const char *name, command_classes theclass, cmd_simple_func_ftype *fun, const char *doc) { @@ -1611,7 +1610,7 @@ add_com (const char *name, enum command_class theclass, cmd_list_element * add_com_alias (const char *name, cmd_list_element *target, - command_class theclass, int abbrev_flag) + command_classes theclass, int abbrev_flag) { return add_alias_cmd (name, target, theclass, abbrev_flag, &cmdlist); } @@ -1619,7 +1618,7 @@ add_com_alias (const char *name, cmd_list_element *target, /* Add an element with a suppress notification to the list of commands. */ struct cmd_list_element * -add_com_suppress_notification (const char *name, enum command_class theclass, +add_com_suppress_notification (const char *name, command_classes theclass, cmd_simple_func_ftype *fun, const char *doc, bool *suppress_notification) { @@ -1934,7 +1933,7 @@ help_cmd (const char *command, struct ui_file *stream) If you call this routine with a class >= 0, it recurses. */ void help_list (struct cmd_list_element *list, const char *cmdtype, - enum command_class theclass, struct ui_file *stream) + command_classes theclass, struct ui_file *stream) { int len = strlen (cmdtype); const char *space = ""; @@ -1955,7 +1954,11 @@ help_list (struct cmd_list_element *list, const char *cmdtype, styled_string (command_style.style (), cmdtype), prefix); - help_cmd_list (list, theclass, theclass >= 0, stream); + /* Don't recurse if theclass is beginner, since the quickstart + help is meant to be direct and not include prefix commands. */ + bool recurse = (theclass != all_commands) && (theclass != all_classes) + && (theclass != class_essential); + help_cmd_list (list, theclass, recurse, stream); if (theclass == all_classes) { @@ -2053,8 +2056,8 @@ print_doc_line (struct ui_file *stream, const char *str, if (for_value_prefix) { char &c = (*line_buffer)[0]; - if (islower (c)) - c = toupper (c); + if (c_islower (c)) + c = c_toupper (c); if (line_buffer->back () == '.') line_buffer->pop_back (); } @@ -2108,7 +2111,7 @@ print_help_for_command (const cmd_list_element &c, */ static void -help_cmd_list (struct cmd_list_element *list, enum command_class theclass, +help_cmd_list (struct cmd_list_element *list, command_classes theclass, bool recurse, struct ui_file *stream) { struct cmd_list_element *c; @@ -2121,7 +2124,7 @@ help_cmd_list (struct cmd_list_element *list, enum command_class theclass, continue; } - if (c->is_alias () && theclass != class_alias) + if (c->is_alias () && ((theclass & class_alias) == 0)) { /* Do not show an alias, unless specifically showing the list of aliases: for all other classes, an alias is @@ -2131,7 +2134,7 @@ help_cmd_list (struct cmd_list_element *list, enum command_class theclass, if (theclass == all_commands || (theclass == all_classes && c->is_command_class_help ()) - || (theclass == c->theclass && !c->is_command_class_help ())) + || ((theclass & c->theclass) != 0 && !c->is_command_class_help ())) { /* show C when - showing all commands @@ -2143,13 +2146,13 @@ help_cmd_list (struct cmd_list_element *list, enum command_class theclass, list of sub-commands of the aliased command. */ print_help_for_command (*c, - recurse && (theclass != class_alias || !c->is_alias ()), + recurse && (((theclass & class_alias) == 0) || !c->is_alias ()), stream); continue; } if (recurse - && (theclass == class_user || theclass == class_alias) + && ((theclass & (class_user | class_alias)) != 0) && c->is_prefix ()) { /* User-defined commands or aliases may be subcommands. */ @@ -2227,7 +2230,7 @@ valid_cmd_char_p (int c) /* Alas "42" is a legitimate user-defined command. In the interests of not breaking anything we preserve that. */ - return isalnum (c) || c == '-' || c == '_' || c == '.'; + return c_isalnum (c) || c == '-' || c == '_' || c == '.'; } /* See command.h. */ @@ -2491,7 +2494,7 @@ lookup_cmd (const char **line, struct cmd_list_element *list, } else { - if (c->type == set_cmd && **line != '\0' && !isspace (**line)) + if (c->type == set_cmd && **line != '\0' && !c_isspace (**line)) error (_("Argument must be preceded by space.")); /* We've got something. It may still not be what the caller @@ -2527,23 +2530,23 @@ lookup_cmd_exact (const char *name, deprecated and a warning message should be generated. This function decodes TEXT and potentially generates a warning message as outlined below. - + Example for 'set endian big' which has a fictitious alias 'seb'. - + If alias wasn't used in TEXT, and the command is deprecated: - "warning: 'set endian big' is deprecated." - + "warning: 'set endian big' is deprecated." + If alias was used, and only the alias is deprecated: "warning: 'seb' an alias for the command 'set endian big' is deprecated." - + If alias was used and command is deprecated (regardless of whether the alias itself is deprecated: - + "warning: 'set endian big' (seb) is deprecated." After the message has been sent, clear the appropriate flags in the command and/or the alias so the user is no longer bothered. - + */ void deprecated_cmd_warning (const char *text, struct cmd_list_element *list) @@ -2833,7 +2836,7 @@ cmd_func (struct cmd_list_element *cmd, const char *args, int from_tty) int cli_user_command_p (struct cmd_list_element *cmd) { - return cmd->theclass == class_user && cmd->func == do_simple_func; + return (cmd->theclass & class_user) != 0 && cmd->func == do_simple_func; } /* See cli-decode.h. */ diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h index 217afbc..2aeed81 100644 --- a/gdb/cli/cli-decode.h +++ b/gdb/cli/cli-decode.h @@ -47,7 +47,7 @@ enum cmd_types struct cmd_list_element { - cmd_list_element (const char *name_, enum command_class theclass_, + cmd_list_element (const char *name_, command_classes theclass_, const char *doc_) : name (name_), theclass (theclass_), @@ -62,6 +62,8 @@ struct cmd_list_element type (not_set_cmd), doc (doc_) { + gdb_assert (name != nullptr); + gdb_assert (doc != nullptr); memset (&function, 0, sizeof (function)); } @@ -100,6 +102,9 @@ struct cmd_list_element bool is_prefix () const { return this->subcommands != nullptr; } + bool is_essential () const + { return (this->theclass & class_essential) != 0; } + /* Return true if this command is a "command class help" command. For instance, a "stack" dummy command is registered so that one can do "help stack" and show help for all commands of the "stack" class. */ @@ -121,8 +126,9 @@ struct cmd_list_element /* Name of this command. */ const char *name; - /* Command class; class values are chosen by application program. */ - enum command_class theclass; + /* Command classes; class values are chosen by application program + and are stored as a bitmask. */ + command_classes theclass; /* When 1 indicated that this command is deprecated. It may be removed from gdb's command set in the future. */ diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c index 0ecc7b0..73ba572 100644 --- a/gdb/cli/cli-dump.c +++ b/gdb/cli/cli-dump.c @@ -23,9 +23,7 @@ #include "cli/cli-cmds.h" #include "value.h" #include "completer.h" -#include <ctype.h> #include "target.h" -#include "readline/tilde.h" #include "gdbcore.h" #include "cli/cli-utils.h" #include "gdb_bfd.h" @@ -78,7 +76,7 @@ scan_filename (const char **cmd, const char *defname) } gdb_assert (filename != NULL); - return gdb::unique_xmalloc_ptr<char> (tilde_expand (filename.get ())); + return gdb_rl_tilde_expand (filename.get ()); } static gdb_bfd_ref_ptr @@ -129,7 +127,7 @@ static struct cmd_list_element *binary_dump_cmdlist; static struct cmd_list_element *binary_append_cmdlist; static void -dump_binary_file (const char *filename, const char *mode, +dump_binary_file (const char *filename, const char *mode, const bfd_byte *buf, ULONGEST len) { int status; @@ -144,8 +142,8 @@ dump_binary_file (const char *filename, const char *mode, } static void -dump_bfd_file (const char *filename, const char *mode, - const char *target, CORE_ADDR vaddr, +dump_bfd_file (const char *filename, const char *mode, + const char *target, CORE_ADDR vaddr, const bfd_byte *buf, ULONGEST len) { asection *osection; @@ -193,7 +191,7 @@ dump_memory_to_file (const char *cmd, const char *mode, const char *file_format) value. */ gdb::byte_vector buf (count); read_memory (lo, buf.data (), count); - + /* Have everything. Open/write the data. */ if (file_format == NULL || strcmp (file_format, "binary") == 0) dump_binary_file (filename.get (), mode, buf.data (), count); @@ -241,7 +239,7 @@ dump_value_to_file (const char *cmd, const char *mode, const char *file_format) } dump_bfd_file (filename.get (), mode, file_format, vaddr, - val->contents ().data (), + val->contents ().data (), val->type ()->length ()); } } @@ -347,7 +345,7 @@ add_dump_command (const char *name, struct cmd_list_element *c; struct dump_context *d; - c = add_cmd (name, all_commands, descr, &dump_cmdlist); + c = add_cmd (name, no_class, descr, &dump_cmdlist); set_cmd_completer (c, deprecated_filename_completer); d = XNEW (struct dump_context); d->func = func; @@ -355,7 +353,7 @@ add_dump_command (const char *name, c->set_context (d); c->func = call_dump_func; - c = add_cmd (name, all_commands, descr, &append_cmdlist); + c = add_cmd (name, no_class, descr, &append_cmdlist); set_cmd_completer (c, deprecated_filename_completer); d = XNEW (struct dump_context); d->func = func; @@ -365,10 +363,10 @@ add_dump_command (const char *name, /* Replace "Dump " at start of docstring with "Append " (borrowed from [deleted] deprecated_add_show_from_set). */ - if ( c->doc[0] == 'W' - && c->doc[1] == 'r' + if ( c->doc[0] == 'W' + && c->doc[1] == 'r' && c->doc[2] == 'i' - && c->doc[3] == 't' + && c->doc[3] == 't' && c->doc[4] == 'e' && c->doc[5] == ' ') c->doc = concat ("Append ", c->doc + 6, (char *)NULL); @@ -397,8 +395,8 @@ restore_one_section (bfd *ibfd, asection *isec, if (sec_end <= load_start || (load_end > 0 && sec_start >= load_end)) { - /* No, no useable data in this section. */ - gdb_printf (_("skipping section %s...\n"), + /* No, no usable data in this section. */ + gdb_printf (_("skipping section %s...\n"), bfd_section_name (isec)); return; } @@ -416,12 +414,12 @@ restore_one_section (bfd *ibfd, asection *isec, /* Get the data. */ gdb::byte_vector buf (size); if (!bfd_get_section_contents (ibfd, isec, buf.data (), 0, size)) - error (_("Failed to read bfd file %s: '%s'."), bfd_get_filename (ibfd), + error (_("Failed to read bfd file %s: '%s'."), bfd_get_filename (ibfd), bfd_errmsg (bfd_get_error ())); gdb_printf ("Restoring section %s (0x%lx to 0x%lx)", - bfd_section_name (isec), - (unsigned long) sec_start, + bfd_section_name (isec), + (unsigned long) sec_start, (unsigned long) sec_end); if (load_offset != 0 || load_start != 0 || load_end != 0) @@ -464,7 +462,7 @@ restore_binary_file (const char *filename, CORE_ADDR load_offset, perror_with_name (filename); if (len <= load_start) - error (_("Start address is greater than length of binary file %s."), + error (_("Start address is greater than length of binary file %s."), filename); /* Chop off "len" if it exceeds the requested load_end addr. */ @@ -474,9 +472,9 @@ restore_binary_file (const char *filename, CORE_ADDR load_offset, if (load_start > 0) len -= load_start; - gdb_printf - ("Restoring binary file %s into memory (0x%lx to 0x%lx)\n", - filename, + gdb_printf + ("Restoring binary file %s into memory (0x%lx to 0x%lx)\n", + filename, (unsigned long) (load_start + load_offset), (unsigned long) (load_start + load_offset + len)); @@ -564,9 +562,7 @@ restore_command (const char *args, int from_tty) } } -void _initialize_cli_dump (); -void -_initialize_cli_dump () +INIT_GDB_FILE (cli_dump) { struct cmd_list_element *c; @@ -581,119 +577,119 @@ _initialize_cli_dump () 0/*allow-unknown*/, &cmdlist); - add_dump_command ("memory", dump_memory_command, "\ + add_dump_command ("memory", dump_memory_command, _("\ Write contents of memory to a raw binary file.\n\ Arguments are FILE START STOP. Writes the contents of memory within the\n\ -range [START .. STOP) to the specified FILE in raw target ordered bytes."); +range [START .. STOP) to the specified FILE in raw target ordered bytes.")); - add_dump_command ("value", dump_value_command, "\ + add_dump_command ("value", dump_value_command, _("\ Write the value of an expression to a raw binary file.\n\ Arguments are FILE EXPRESSION. Writes the value of EXPRESSION to\n\ -the specified FILE in raw target ordered bytes."); +the specified FILE in raw target ordered bytes.")); - add_basic_prefix_cmd ("srec", all_commands, + add_basic_prefix_cmd ("srec", no_class, _("Write target code/data to an srec file."), &srec_cmdlist, - 0 /*allow-unknown*/, + 0 /*allow-unknown*/, &dump_cmdlist); - add_basic_prefix_cmd ("ihex", all_commands, + add_basic_prefix_cmd ("ihex", no_class, _("Write target code/data to an intel hex file."), &ihex_cmdlist, - 0 /*allow-unknown*/, + 0 /*allow-unknown*/, &dump_cmdlist); - add_basic_prefix_cmd ("verilog", all_commands, + add_basic_prefix_cmd ("verilog", no_class, _("Write target code/data to a verilog hex file."), &verilog_cmdlist, 0 /*allow-unknown*/, &dump_cmdlist); - add_basic_prefix_cmd ("tekhex", all_commands, + add_basic_prefix_cmd ("tekhex", no_class, _("Write target code/data to a tekhex file."), &tekhex_cmdlist, - 0 /*allow-unknown*/, + 0 /*allow-unknown*/, &dump_cmdlist); - add_basic_prefix_cmd ("binary", all_commands, + add_basic_prefix_cmd ("binary", no_class, _("Write target code/data to a raw binary file."), &binary_dump_cmdlist, - 0 /*allow-unknown*/, + 0 /*allow-unknown*/, &dump_cmdlist); - add_basic_prefix_cmd ("binary", all_commands, + add_basic_prefix_cmd ("binary", no_class, _("Append target code/data to a raw binary file."), &binary_append_cmdlist, - 0 /*allow-unknown*/, + 0 /*allow-unknown*/, &append_cmdlist); - add_cmd ("memory", all_commands, dump_srec_memory, _("\ + add_cmd ("memory", no_class, dump_srec_memory, _("\ Write contents of memory to an srec file.\n\ Arguments are FILE START STOP. Writes the contents of memory\n\ within the range [START .. STOP) to the specified FILE in srec format."), &srec_cmdlist); - add_cmd ("value", all_commands, dump_srec_value, _("\ + add_cmd ("value", no_class, dump_srec_value, _("\ Write the value of an expression to an srec file.\n\ Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\ to the specified FILE in srec format."), &srec_cmdlist); - add_cmd ("memory", all_commands, dump_ihex_memory, _("\ + add_cmd ("memory", no_class, dump_ihex_memory, _("\ Write contents of memory to an ihex file.\n\ Arguments are FILE START STOP. Writes the contents of memory within\n\ the range [START .. STOP) to the specified FILE in intel hex format."), &ihex_cmdlist); - add_cmd ("value", all_commands, dump_ihex_value, _("\ + add_cmd ("value", no_class, dump_ihex_value, _("\ Write the value of an expression to an ihex file.\n\ Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\ to the specified FILE in intel hex format."), &ihex_cmdlist); - add_cmd ("memory", all_commands, dump_verilog_memory, _("\ + add_cmd ("memory", no_class, dump_verilog_memory, _("\ Write contents of memory to a verilog hex file.\n\ Arguments are FILE START STOP. Writes the contents of memory within\n\ the range [START .. STOP) to the specified FILE in verilog hex format."), &verilog_cmdlist); - add_cmd ("value", all_commands, dump_verilog_value, _("\ + add_cmd ("value", no_class, dump_verilog_value, _("\ Write the value of an expression to a verilog hex file.\n\ Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\ to the specified FILE in verilog hex format."), &verilog_cmdlist); - add_cmd ("memory", all_commands, dump_tekhex_memory, _("\ + add_cmd ("memory", no_class, dump_tekhex_memory, _("\ Write contents of memory to a tekhex file.\n\ Arguments are FILE START STOP. Writes the contents of memory\n\ within the range [START .. STOP) to the specified FILE in tekhex format."), &tekhex_cmdlist); - add_cmd ("value", all_commands, dump_tekhex_value, _("\ + add_cmd ("value", no_class, dump_tekhex_value, _("\ Write the value of an expression to a tekhex file.\n\ Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\ to the specified FILE in tekhex format."), &tekhex_cmdlist); - add_cmd ("memory", all_commands, dump_binary_memory, _("\ + add_cmd ("memory", no_class, dump_binary_memory, _("\ Write contents of memory to a raw binary file.\n\ Arguments are FILE START STOP. Writes the contents of memory\n\ within the range [START .. STOP) to the specified FILE in binary format."), &binary_dump_cmdlist); - add_cmd ("value", all_commands, dump_binary_value, _("\ + add_cmd ("value", no_class, dump_binary_value, _("\ Write the value of an expression to a raw binary file.\n\ Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\ to the specified FILE in raw target ordered bytes."), &binary_dump_cmdlist); - add_cmd ("memory", all_commands, append_binary_memory, _("\ + add_cmd ("memory", no_class, append_binary_memory, _("\ Append contents of memory to a raw binary file.\n\ Arguments are FILE START STOP. Writes the contents of memory within the\n\ range [START .. STOP) to the specified FILE in raw target ordered bytes."), &binary_append_cmdlist); - add_cmd ("value", all_commands, append_binary_value, _("\ + add_cmd ("value", no_class, append_binary_value, _("\ Append the value of an expression to a raw binary file.\n\ Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\ to the specified FILE in raw target ordered bytes."), diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c index 32ba9d9..d7b73df 100644 --- a/gdb/cli/cli-interp.c +++ b/gdb/cli/cli-interp.c @@ -321,9 +321,7 @@ cli_interp_factory (const char *name) /* Standard gdb initialization hook. */ -void _initialize_cli_interp (); -void -_initialize_cli_interp () +INIT_GDB_FILE (cli_interp) { interp_factory_register (INTERP_CONSOLE, cli_interp_factory); } diff --git a/gdb/cli/cli-logging.c b/gdb/cli/cli-logging.c index d225533..9727b5a 100644 --- a/gdb/cli/cli-logging.c +++ b/gdb/cli/cli-logging.c @@ -167,7 +167,7 @@ set_logging_on (const char *args, int from_tty) handle_redirections (from_tty); } -static void +static void set_logging_off (const char *args, int from_tty) { if (saved_filename.empty ()) @@ -202,9 +202,7 @@ show_logging_enabled (struct ui_file *file, int from_tty, gdb_printf (file, _("off: Logging is disabled.\n")); } -void _initialize_cli_logging (); -void -_initialize_cli_logging () +INIT_GDB_FILE (cli_logging) { static struct cmd_list_element *set_logging_cmdlist, *show_logging_cmdlist; diff --git a/gdb/cli/cli-option.c b/gdb/cli/cli-option.c index a30261e..5da8c73 100644 --- a/gdb/cli/cli-option.c +++ b/gdb/cli/cli-option.c @@ -227,7 +227,7 @@ parse_option (gdb::array_view<const option_def_group> options_group, match = &o; match_ctx = grp.ctx; - if ((isspace (arg[len]) || arg[len] == '\0') + if ((c_isspace (arg[len]) || arg[len] == '\0') && strlen (o.name) == len) break; /* Exact match. */ } @@ -635,7 +635,7 @@ complete_options (completion_tracker &tracker, if (ov && !tracker.have_completions () && **args == '\0' - && *args > text && !isspace ((*args)[-1])) + && *args > text && !c_isspace ((*args)[-1])) { tracker.advance_custom_word_point_by (*args - text); diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index bdbf850..31be114 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -19,7 +19,6 @@ #include "event-top.h" #include "value.h" -#include <ctype.h> #include "ui-out.h" #include "top.h" @@ -361,14 +360,13 @@ public: { } + DISABLE_COPY_AND_ASSIGN (scoped_restore_hook_in); + ~scoped_restore_hook_in () { m_cmd->hook_in = 0; } - scoped_restore_hook_in (const scoped_restore_hook_in &) = delete; - scoped_restore_hook_in &operator= (const scoped_restore_hook_in &) = delete; - private: struct cmd_list_element *m_cmd; @@ -829,7 +827,7 @@ locate_arg (const char *p) while ((p = strchr (p, '$'))) { if (startswith (p, "$arg") - && (isdigit (p[4]) || p[4] == 'c')) + && (c_isdigit (p[4]) || p[4] == 'c')) return p; p++; } @@ -932,7 +930,7 @@ line_first_arg (const char *p) { const char *first_arg = p + find_command_name_length (p); - return skip_spaces (first_arg); + return skip_spaces (first_arg); } /* Process one input line. If the command is an "end", return such an @@ -1324,9 +1322,9 @@ validate_comname (const char **comname) /* Find the last word of the argument. */ p = *comname + strlen (*comname); - while (p > *comname && isspace (p[-1])) + while (p > *comname && c_isspace (p[-1])) p--; - while (p > *comname && !isspace (p[-1])) + while (p > *comname && !c_isspace (p[-1])) p--; last_word = p; @@ -1384,7 +1382,7 @@ do_define_command (const char *comname, int from_tty, const char *comfull; int hook_type = CMD_NO_HOOK; int hook_name_size = 0; - + #define HOOK_STRING "hook-" #define HOOK_LEN 5 #define HOOK_POST_STRING "hookpost-" @@ -1751,9 +1749,7 @@ show_user_1 (struct cmd_list_element *c, const char *prefix, const char *name, } -void _initialize_cli_script (); -void -_initialize_cli_script () +INIT_GDB_FILE (cli_script) { struct cmd_list_element *c; diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c index 4d4695f..a97cd1b 100644 --- a/gdb/cli/cli-setshow.c +++ b/gdb/cli/cli-setshow.c @@ -15,9 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "readline/tilde.h" #include "value.h" -#include <ctype.h> #include "arch-utils.h" #include "observable.h" #include "interps.h" @@ -49,7 +47,7 @@ parse_auto_binary_operation (const char *arg) { int length = strlen (arg); - while (isspace (arg[length - 1]) && length > 0) + while (c_isspace (arg[length - 1]) && length > 0) length--; /* Note that "o" is ambiguous. */ @@ -119,7 +117,7 @@ parse_cli_boolean_value (const char *arg) static void -deprecated_show_value_hack (struct ui_file *ignore_file, +deprecated_show_value_hack (struct ui_file *file, int ignore_from_tty, struct cmd_list_element *c, const char *value) @@ -130,7 +128,7 @@ deprecated_show_value_hack (struct ui_file *ignore_file, /* Print doc minus "Show " at start. Tell print_doc_line that this is for a 'show value' prefix. */ - print_doc_line (gdb_stdout, c->doc + 5, true); + print_doc_line (file, c->doc + 5, true); gdb_assert (c->var.has_value ()); @@ -139,17 +137,17 @@ deprecated_show_value_hack (struct ui_file *ignore_file, case var_string: case var_string_noescape: case var_enum: - gdb_printf ((" is \"%s\".\n"), value); + gdb_printf (file, _(" is \"%s\".\n"), value); break; case var_optional_filename: case var_filename: - gdb_printf ((" is \"%ps\".\n"), + gdb_printf (file, _(" is \"%ps\".\n"), styled_string (file_name_style.style (), value)); break; default: - gdb_printf ((" is %s.\n"), value); + gdb_printf (file, _(" is %s.\n"), value); break; } } @@ -386,7 +384,7 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c) [[fallthrough]]; case var_optional_filename: { - char *val = NULL; + gdb::unique_xmalloc_ptr<char> val; if (*arg != '\0') { @@ -398,14 +396,13 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c) gdb::unique_xmalloc_ptr<char> copy = make_unique_xstrndup (arg, ptr + 1 - arg); - val = tilde_expand (copy.get ()); + val = gdb_rl_tilde_expand (copy.get ()); } else - val = xstrdup (""); + val = make_unique_xstrdup (""); option_changed - = c->var->set<std::string> (std::string (val)); - xfree (val); + = c->var->set<std::string> (std::string (val.get ())); } break; case var_boolean: @@ -748,5 +745,3 @@ cmd_show_list (struct cmd_list_element *list, int from_tty) } } } - - diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c index 30c7afb..d6829f0 100644 --- a/gdb/cli/cli-style.c +++ b/gdb/cli/cli-style.c @@ -23,6 +23,7 @@ #include "cli/cli-style.h" #include "source-cache.h" #include "observable.h" +#include "charset.h" /* True if styling is enabled. */ @@ -42,6 +43,10 @@ bool source_styling = true; bool disassembler_styling = true; +/* User-settable variable controlling emoji output. */ + +static auto_boolean emoji_styling = AUTO_BOOLEAN_AUTO; + /* Names of intensities; must correspond to ui_file_style::intensity. */ static const char * const cli_intensities[] = { @@ -410,9 +415,86 @@ show_style_disassembler (struct ui_file *file, int from_tty, gdb_printf (file, _("Disassembler output styling is disabled.\n")); } -void _initialize_cli_style (); +/* Implement 'show style emoji'. */ + +static void +show_emoji_styling (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + if (emoji_styling == AUTO_BOOLEAN_TRUE) + gdb_printf (file, _("CLI emoji styling is enabled.\n")); + else if (emoji_styling == AUTO_BOOLEAN_FALSE) + gdb_printf (file, _("CLI emoji styling is disabled.\n")); + else + gdb_printf (file, _("CLI emoji styling is automatic (currently %s).\n"), + emojis_ok () ? _("enabled") : _("disabled")); +} + +/* See cli-style.h. */ + +bool +emojis_ok () +{ + if (!cli_styling || emoji_styling == AUTO_BOOLEAN_FALSE) + return false; + if (emoji_styling == AUTO_BOOLEAN_TRUE) + return true; + return strcmp (host_charset (), "UTF-8") == 0; +} + +/* See cli-style.h. */ + +void +no_emojis () +{ + emoji_styling = AUTO_BOOLEAN_FALSE; +} + +/* Emoji warning prefix. */ +static std::string warning_prefix = "⚠️ "; + +/* Implement 'show style warning-prefix'. */ + +static void +show_warning_prefix (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + gdb_printf (file, _("Warning prefix is \"%s\".\n"), + warning_prefix.c_str ()); +} + +/* See cli-style.h. */ + +void +print_warning_prefix (ui_file *file) +{ + if (emojis_ok ()) + gdb_puts (warning_prefix.c_str (), file); +} + +/* Emoji error prefix. */ +static std::string error_prefix = "❌️ "; + +/* Implement 'show style error-prefix'. */ + +static void +show_error_prefix (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + gdb_printf (file, _("Error prefix is \"%s\".\n"), + error_prefix.c_str ()); +} + +/* See cli-style.h. */ + void -_initialize_cli_style () +print_error_prefix (ui_file *file) +{ + if (emojis_ok ()) + gdb_puts (error_prefix.c_str (), file); +} + +INIT_GDB_FILE (cli_style) { add_setshow_prefix_cmd ("style", no_class, _("\ @@ -431,6 +513,13 @@ If enabled, output to the terminal is styled."), set_style_enabled, show_style_enabled, &style_set_list, &style_show_list); + add_setshow_auto_boolean_cmd ("emoji", no_class, &emoji_styling, _("\ +Set whether emoji output is enabled."), _("\ +Show whether emoji output is enabled."), _("\ +If enabled, emojis may be displayed."), + nullptr, show_emoji_styling, + &style_set_list, &style_show_list); + add_setshow_boolean_cmd ("sources", no_class, &source_styling, _("\ Set whether source code styling is enabled."), _("\ Show whether source code styling is enabled."), _("\ @@ -627,4 +716,23 @@ coming from your source code."), &style_disasm_set_list); add_alias_cmd ("symbol", function_prefix_cmds.show, no_class, 0, &style_disasm_show_list); + + add_setshow_string_cmd ("warning-prefix", no_class, + &warning_prefix, + _("Set the warning prefix text."), + _("Show the warning prefix text."), + _("\ +The warning prefix text is displayed before any warning, when\n\ +emoji output is enabled."), + nullptr, show_warning_prefix, + &style_set_list, &style_show_list); + add_setshow_string_cmd ("error-prefix", no_class, + &error_prefix, + _("Set the error prefix text."), + _("Show the error prefix text."), + _("\ +The error prefix text is displayed before any error, when\n\ +emoji output is enabled."), + nullptr, show_error_prefix, + &style_set_list, &style_show_list); } diff --git a/gdb/cli/cli-style.h b/gdb/cli/cli-style.h index 77f4ac2..b1a950a 100644 --- a/gdb/cli/cli-style.h +++ b/gdb/cli/cli-style.h @@ -190,4 +190,18 @@ private: bool m_old_value; }; +/* Return true if emoji styling is allowed. */ +extern bool emojis_ok (); + +/* Disable emoji styling. This is here so that Windows can disable + emoji when the console is in use. It shouldn't be called + elsewhere. */ +extern void no_emojis (); + +/* Print the warning prefix, if desired. */ +extern void print_warning_prefix (ui_file *file); + +/* Print the error prefix, if desired. */ +extern void print_error_prefix (ui_file *file); + #endif /* GDB_CLI_CLI_STYLE_H */ diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c index 23706e0..3d0034e 100644 --- a/gdb/cli/cli-utils.c +++ b/gdb/cli/cli-utils.c @@ -20,7 +20,6 @@ #include "cli/cli-utils.h" #include "value.h" -#include <ctype.h> /* See documentation in cli-utils.h. */ @@ -46,7 +45,7 @@ get_ulongest (const char **pp, int trailer) /* Internal variable. Make a copy of the name, so we can null-terminate it to pass to lookup_internalvar(). */ const char *start = ++p; - while (isalnum (*p) || *p == '_') + while (c_isalnum (*p) || *p == '_') p++; std::string varname (start, p - start); if (!get_internalvar_integer (lookup_internalvar (varname.c_str ()), @@ -67,7 +66,7 @@ get_ulongest (const char **pp, int trailer) p = end; } - if (!(isspace (*p) || *p == '\0' || *p == trailer)) + if (!(c_isspace (*p) || *p == '\0' || *p == trailer)) error (_("Trailing junk at: %s"), p); p = skip_spaces (p); *pp = p; @@ -111,7 +110,7 @@ get_number_trailer (const char **pp, int trailer) const char *start = ++p; LONGEST longest_val; - while (isalnum (*p) || *p == '_') + while (c_isalnum (*p) || *p == '_') p++; varname = (char *) alloca (p - start + 1); strncpy (varname, start, p - start); @@ -136,7 +135,7 @@ get_number_trailer (const char **pp, int trailer) /* There is no number here. (e.g. "cond a == b"). */ { /* Skip non-numeric token. */ - while (*p && !isspace((int) *p)) + while (*p && !c_isspace((int) *p)) ++p; /* Return zero, which caller must interpret as error. */ retval = 0; @@ -144,10 +143,10 @@ get_number_trailer (const char **pp, int trailer) else retval = atoi (p1); } - if (!(isspace (*p) || *p == '\0' || *p == trailer)) + if (!(c_isspace (*p) || *p == '\0' || *p == trailer)) { /* Trailing junk: return 0 and let caller print error msg. */ - while (!(isspace (*p) || *p == '\0' || *p == trailer)) + while (!(c_isspace (*p) || *p == '\0' || *p == trailer)) ++p; retval = 0; } @@ -262,8 +261,8 @@ number_or_range_parser::get_number () option rather than an incomplete range, so check for end of string as well. */ if (m_cur_tok[0] == '-' - && !(isspace (m_cur_tok[-1]) - && (isalpha (m_cur_tok[1]) + && !(c_isspace (m_cur_tok[-1]) + && (c_isalpha (m_cur_tok[1]) || m_cur_tok[1] == '-' || m_cur_tok[1] == '\0'))) { @@ -293,7 +292,7 @@ number_or_range_parser::get_number () } else { - if (isdigit (*(m_cur_tok + 1))) + if (c_isdigit (*(m_cur_tok + 1))) error (_("negative value")); if (*(m_cur_tok + 1) == '$') { @@ -330,17 +329,17 @@ number_or_range_parser::finished () const integer, convenience var or negative convenience var. */ return (m_cur_tok == NULL || *m_cur_tok == '\0' || (!m_in_range - && !(isdigit (*m_cur_tok) || *m_cur_tok == '$') + && !(c_isdigit (*m_cur_tok) || *m_cur_tok == '$') && !(*m_cur_tok == '-' - && (isdigit (m_cur_tok[1]) || m_cur_tok[1] == '$')))); + && (c_isdigit (m_cur_tok[1]) || m_cur_tok[1] == '$')))); } -/* Accept a number and a string-form list of numbers such as is +/* Accept a number and a string-form list of numbers such as is accepted by get_number_or_range. Return TRUE if the number is in the list. - By definition, an empty list includes all numbers. This is to - be interpreted as typing a command such as "delete break" with + By definition, an empty list includes all numbers. This is to + be interpreted as typing a command such as "delete break" with no arguments. */ int @@ -370,7 +369,7 @@ number_is_in_list (const char *list, int number) const char * remove_trailing_whitespace (const char *start, const char *s) { - while (s > start && isspace (*(s - 1))) + while (s > start && c_isspace (*(s - 1))) --s; return s; @@ -420,7 +419,7 @@ int check_for_argument (const char **str, const char *arg, int arg_len) { if (strncmp (*str, arg, arg_len) == 0 - && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) + && ((*str)[arg_len] == '\0' || c_isspace ((*str)[arg_len]))) { *str += arg_len; *str = skip_spaces (*str); @@ -437,4 +436,3 @@ validate_flags_qcs (const char *which_command, qcs_flags *flags) if (flags->cont && flags->silent) error (_("%s: -c and -s are mutually exclusive"), which_command); } - diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h index f9b0123..22db7c1 100644 --- a/gdb/cli/cli-utils.h +++ b/gdb/cli/cli-utils.h @@ -145,12 +145,12 @@ private: bool m_in_range; }; -/* Accept a number and a string-form list of numbers such as is +/* Accept a number and a string-form list of numbers such as is accepted by get_number_or_range. Return TRUE if the number is in the list. - By definition, an empty list includes all numbers. This is to - be interpreted as typing a command such as "delete break" with + By definition, an empty list includes all numbers. This is to + be interpreted as typing a command such as "delete break" with no arguments. */ extern int number_is_in_list (const char *list, int number); |
