diff options
Diffstat (limited to 'gdb/tui')
-rw-r--r-- | gdb/tui/tui-regs.c | 165 |
1 files changed, 105 insertions, 60 deletions
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 6ac3c2b..a61fadb 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -39,6 +39,7 @@ #include "tui/tui-io.h" #include "reggroups.h" #include "valprint.h" +#include "completer.h" #include "gdb_curses.h" @@ -556,74 +557,135 @@ tui_display_register (struct tui_data_element *data, } } -static void -tui_reg_next_command (char *arg, int from_tty) +/* Helper for "tui reg next", wraps a call to REGGROUP_NEXT, but adds wrap + around behaviour. Returns the next register group, or NULL if the + register window is not currently being displayed. */ + +static struct reggroup * +tui_reg_next (struct gdbarch *gdbarch) { - struct gdbarch *gdbarch = get_current_arch (); + struct reggroup *group = NULL; if (TUI_DATA_WIN != NULL) { - struct reggroup *group - = TUI_DATA_WIN->detail.data_display_info.current_group; - + group = TUI_DATA_WIN->detail.data_display_info.current_group; group = reggroup_next (gdbarch, group); if (group == NULL) group = reggroup_next (gdbarch, NULL); - - if (group != NULL) - tui_show_registers (group); } + return group; } -/* Implementation of the "tui reg prev" command. Cycle the register group - displayed in the tui REG window, moving backwards through the list of - available register groups. */ +/* Helper for "tui reg prev", wraps a call to REGGROUP_PREV, but adds wrap + around behaviour. Returns the previous register group, or NULL if the + register window is not currently being displayed. */ -static void -tui_reg_prev_command (char *arg, int from_tty) +static struct reggroup * +tui_reg_prev (struct gdbarch *gdbarch) { - struct gdbarch *gdbarch = get_current_arch (); + struct reggroup *group = NULL; if (TUI_DATA_WIN != NULL) { - struct reggroup *group - = TUI_DATA_WIN->detail.data_display_info.current_group; - + group = TUI_DATA_WIN->detail.data_display_info.current_group; group = reggroup_prev (gdbarch, group); if (group == NULL) group = reggroup_prev (gdbarch, NULL); - - if (group != NULL) - tui_show_registers (group); } + return group; } -static void -tui_reg_float_command (char *arg, int from_tty) -{ - tui_show_registers (float_reggroup); -} +/* Implement the 'tui reg' command. Changes the register group displayed + in the tui register window. Displays the tui register window if it is + not already on display. */ static void -tui_reg_general_command (char *arg, int from_tty) +tui_reg_command (char *args, int from_tty) { - tui_show_registers (general_reggroup); -} + struct gdbarch *gdbarch = get_current_arch (); -static void -tui_reg_system_command (char *arg, int from_tty) -{ - tui_show_registers (system_reggroup); + if (args != NULL) + { + struct reggroup *group, *match = NULL; + size_t len = strlen (args); + + /* Make sure the curses mode is enabled. */ + tui_enable (); + + /* Make sure the register window is visible. If not, select an + appropriate layout. We need to do this before trying to run the + 'next' or 'prev' commands. */ + if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->generic.is_visible) + tui_set_layout_by_name (DATA_NAME); + + if (strncmp (args, "next", len) == 0) + match = tui_reg_next (gdbarch); + else if (strncmp (args, "prev", len) == 0) + match = tui_reg_prev (gdbarch); + + /* This loop matches on the initial part of a register group + name. If this initial part in ARGS matches only one register + group then the switch is made. */ + for (group = reggroup_next (gdbarch, NULL); + group != NULL; + group = reggroup_next (gdbarch, group)) + { + if (strncmp (reggroup_name (group), args, len) == 0) + { + if (match != NULL) + error (_("ambiguous register group name '%s'"), args); + match = group; + } + } + + if (match == NULL) + error (_("unknown register group '%s'"), args); + + tui_show_registers (match); + } + else + { + struct reggroup *group; + int first; + + printf_unfiltered (_("\"tui reg\" must be followed by the name of " + "either a register group,\nor one of 'next' " + "or 'prev'. Known register groups are:\n")); + + for (first = 1, group = reggroup_next (gdbarch, NULL); + group != NULL; + first = 0, group = reggroup_next (gdbarch, group)) + { + if (!first) + printf_unfiltered (", "); + printf_unfiltered ("%s", reggroup_name (group)); + } + + printf_unfiltered ("\n"); + } } -static struct cmd_list_element *tuireglist; +/* Complete names of register groups, and add the special "prev" and "next" + names. */ -static void -tui_reg_command (char *args, int from_tty) +static VEC (char_ptr) * +tui_reggroup_completer (struct cmd_list_element *ignore, + const char *text, const char *word) { - printf_unfiltered (_("\"tui reg\" must be followed by the name of a " - "tui reg command.\n")); - help_list (tuireglist, "tui reg ", all_commands, gdb_stdout); + VEC (char_ptr) *result = NULL; + static const char *extra[] = { "next", "prev", NULL }; + size_t len = strlen (word); + const char **tmp; + + result = reggroup_completer (ignore, text, word); + + for (tmp = extra; *tmp != NULL; ++tmp) + { + if (strncmp (word, *tmp, len) == 0) + VEC_safe_push (char_ptr, result, xstrdup (*tmp)); + } + + return result; } /* Provide a prototype to silence -Wmissing-prototypes. */ @@ -632,30 +694,13 @@ extern initialize_file_ftype _initialize_tui_regs; void _initialize_tui_regs (void) { - struct cmd_list_element **tuicmd; + struct cmd_list_element **tuicmd, *cmd; tuicmd = tui_get_cmd_list (); - add_prefix_cmd ("reg", class_tui, tui_reg_command, - _("TUI commands to control the register window."), - &tuireglist, "tui reg ", 0, - tuicmd); - - add_cmd ("float", class_tui, tui_reg_float_command, - _("Display only floating point registers."), - &tuireglist); - add_cmd ("general", class_tui, tui_reg_general_command, - _("Display only general registers."), - &tuireglist); - add_cmd ("system", class_tui, tui_reg_system_command, - _("Display only system registers."), - &tuireglist); - add_cmd ("next", class_tui, tui_reg_next_command, - _("Display next register group."), - &tuireglist); - add_cmd ("prev", class_tui, tui_reg_prev_command, - _("Display previous register group."), - &tuireglist); + cmd = add_cmd ("reg", class_tui, tui_reg_command, _("\ +TUI command to control the register window."), tuicmd); + set_cmd_completer (cmd, tui_reggroup_completer); } |