Provide useful completer for "info registers"
Commit Message
Provide a new completion function for the argument of "info
registers", "info all-registers", and the "lr" command in dbx mode.
Without this patch the default symbol completer is used, which is more
confusing than helpful.
gdb/ChangeLog:
* completer.c: Include "target.h" and "reggroups.h".
(reg_or_group_completer): New.
* completer.h (reg_or_group_completer): Declare.
* infcmd.c (_initialize_infcmd): Set reg_or_group_completer for
the "info registers" and "info all-registers" commands and the
dbx-mode "lr" command.
---
gdb/completer.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
gdb/completer.h | 3 +++
gdb/infcmd.c | 12 +++++++++---
3 files changed, 63 insertions(+), 3 deletions(-)
Comments
Also, ...
On 11/25/2014 05:28 PM, Andreas Arnez wrote:
> + for (i = 0; i < n_regs; i++)
> + {
> + const char *reg_name = gdbarch_register_name (gdbarch, i);
> +
> + if (reg_name != NULL && strncmp (text, reg_name, len) == 0)
> + VEC_safe_push (char_ptr, result, xstrdup (reg_name));
Not sure under which conditions "len" could be zero here. If it may,
note that some registers have empty names. See default_print_registers_info:
/* If the register name is empty, it is undefined for this
processor, so don't display anything. */
if (gdbarch_register_name (gdbarch, i) == NULL
|| *(gdbarch_register_name (gdbarch, i)) == '\0')
continue;
> + }
> + }
Thanks,
Pedro Alves
On Thu, Dec 04 2014, Pedro Alves wrote:
> Also, ...
>
> On 11/25/2014 05:28 PM, Andreas Arnez wrote:
>> + for (i = 0; i < n_regs; i++)
>> + {
>> + const char *reg_name = gdbarch_register_name (gdbarch, i);
>> +
>> + if (reg_name != NULL && strncmp (text, reg_name, len) == 0)
>> + VEC_safe_push (char_ptr, result, xstrdup (reg_name));
>
> Not sure under which conditions "len" could be zero here. If it may,
> note that some registers have empty names. See default_print_registers_info:
>
> /* If the register name is empty, it is undefined for this
> processor, so don't display anything. */
> if (gdbarch_register_name (gdbarch, i) == NULL
> || *(gdbarch_register_name (gdbarch, i)) == '\0')
> continue;
>
>> + }
>> + }
Good point. This is fixed in the new version; registers with empty
names are skipped now.
@@ -23,6 +23,8 @@
#include "filenames.h" /* For DOSish file names. */
#include "language.h"
#include "gdb_signals.h"
+#include "target.h"
+#include "reggroups.h"
#include "cli/cli-decode.h"
@@ -836,6 +838,55 @@ signal_completer (struct cmd_list_element *ignore,
return return_val;
}
+/* Complete on a register or reggroup. */
+
+VEC (char_ptr) *
+reg_or_group_completer (struct cmd_list_element *ignore,
+ const char *text, const char *word)
+{
+ VEC (char_ptr) *result = NULL;
+ size_t len = strlen (text);
+ struct frame_info *frame;
+ struct gdbarch *gdbarch;
+
+ if (!target_has_registers)
+ return result;
+
+ frame = get_selected_frame (NULL);
+ gdbarch = get_frame_arch (frame);
+
+ {
+ int i;
+ int n_regs = (gdbarch_num_regs (gdbarch)
+ + gdbarch_num_pseudo_regs (gdbarch));
+
+ for (i = 0; i < n_regs; i++)
+ {
+ const char *reg_name = gdbarch_register_name (gdbarch, i);
+
+ if (reg_name != NULL && strncmp (text, reg_name, len) == 0)
+ VEC_safe_push (char_ptr, result, xstrdup (reg_name));
+ }
+ }
+
+ {
+ struct reggroup *group;
+
+ for (group = reggroup_next (gdbarch, NULL);
+ group != NULL;
+ group = reggroup_next (gdbarch, group))
+ {
+ const char *group_name = reggroup_name (group);
+
+ if (strncmp (text, group_name, len) == 0)
+ VEC_safe_push (char_ptr, result, xstrdup (group_name));
+ }
+ }
+
+ return result;
+}
+
+
/* Get the list of chars that are considered as word breaks
for the current command. */
@@ -45,6 +45,9 @@ extern VEC (char_ptr) *command_completer (struct cmd_list_element *,
extern VEC (char_ptr) *signal_completer (struct cmd_list_element *,
const char *, const char *);
+extern VEC (char_ptr) *reg_or_group_completer (struct cmd_list_element *,
+ const char *, const char *);
+
extern char *get_gdb_completer_quote_characters (void);
extern char *gdb_completion_word_break_characters (void);
@@ -3235,18 +3235,24 @@ If non-stop mode is enabled, interrupt only the current thread,\n\
otherwise all the threads in the program are stopped. To \n\
interrupt all running threads in non-stop mode, use the -a option."));
- add_info ("registers", nofp_registers_info, _("\
+ c = add_info ("registers", nofp_registers_info, _("\
List of integer registers and their contents, for selected stack frame.\n\
Register name as argument means describe only that register."));
add_info_alias ("r", "registers", 1);
+ set_cmd_completer (c, reg_or_group_completer);
if (xdb_commands)
- add_com ("lr", class_info, nofp_registers_info, _("\
+ {
+ c = add_com ("lr", class_info, nofp_registers_info, _("\
List of integer registers and their contents, for selected stack frame.\n\
Register name as argument means describe only that register."));
- add_info ("all-registers", all_registers_info, _("\
+ set_cmd_completer (c, reg_or_group_completer);
+ }
+
+ c = add_info ("all-registers", all_registers_info, _("\
List of all registers and their contents, for selected stack frame.\n\
Register name as argument means describe only that register."));
+ set_cmd_completer (c, reg_or_group_completer);
add_info ("program", program_info,
_("Execution status of the program."));