+2014-12-12 Andreas Arnez <arnez@linux.vnet.ibm.com>
+
+ * completer.c: Include "target.h", "reggroups.h", and
+ "user-regs.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.
+
2014-12-12 Andreas Arnez <arnez@linux.vnet.ibm.com>
* user-regs.c: Include "arch-utils.h", "command.h", and
#include "filenames.h" /* For DOSish file names. */
#include "language.h"
#include "gdb_signals.h"
+#include "target.h"
+#include "reggroups.h"
+#include "user-regs.h"
#include "cli/cli-decode.h"
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 (word);
+ struct gdbarch *gdbarch;
+ struct reggroup *group;
+ const char *name;
+ int i;
+
+ if (!target_has_registers)
+ return result;
+
+ gdbarch = get_frame_arch (get_selected_frame (NULL));
+
+ for (i = 0;
+ (name = user_reg_map_regnum_to_name (gdbarch, i)) != NULL;
+ i++)
+ {
+ if (*name != '\0' && strncmp (word, name, len) == 0)
+ VEC_safe_push (char_ptr, result, xstrdup (name));
+ }
+
+ for (group = reggroup_next (gdbarch, NULL);
+ group != NULL;
+ group = reggroup_next (gdbarch, group))
+ {
+ name = reggroup_name (group);
+ if (strncmp (word, name, len) == 0)
+ VEC_safe_push (char_ptr, result, xstrdup (name));
+ }
+
+ return result;
+}
+
+
/* Get the list of chars that are considered as word breaks
for the current command. */
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);
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."));
+2014-12-12 Andreas Arnez <arnez@linux.vnet.ibm.com>
+
+ * gdb.base/completion.exp: Add test for completion of "info
+ registers ".
+
2014-12-12 Maciej W. Rozycki <macro@codesourcery.com>
* gdb.base/func-ptrs.c: New file.
gdb_test "complete set trace-buffer-size " "set trace-buffer-size unlimited"
gdb_test "complete set trace-buffer-size unl" "set trace-buffer-size unlimited"
+# Test "info registers" completion: First determine this
+# architecture's registers and reggroups...
+
+set regs_output [capture_command_output "mt print registers" \
+ ".*Name.*Nr.*Rel.*Offset.*Size.*Type.\[^\n\]*\n"]
+append regs_output "\n"
+append regs_output [capture_command_output "mt print reggroups" \
+ ".*Group.*Type\[^\n]*\n"]
+set all_regs {}
+foreach {- reg} [regexp -all -inline -line {^\s+(\w+)} $regs_output] {
+ lappend all_regs $reg
+}
+
+set regs_output [capture_command_output "mt print user-registers" \
+ ".*Nr.*Name\[^\n]*\n"]
+foreach {- reg} [regexp -all -inline -line {^\s+\d+\s+(\w+)} $regs_output] {
+ lappend all_regs $reg
+}
+
+set all_regs [join [lsort -unique $all_regs]]
+
+# ... and then compare them to the completion of "info registers".
+
+set regs_output [capture_command_output "complete info registers " ""]
+set completed_regs {}
+foreach {-> reg} [regexp -all -inline -line {^info registers (\w+\S*)} $regs_output] {
+ lappend completed_regs $reg
+}
+set completed_regs [join [lsort $completed_regs]]
+gdb_assert {{$all_regs eq $completed_regs}} "complete 'info registers '"
+
# Tests below are about tab-completion, which doesn't work if readline
# library isn't used. Check it first.