* [PATCH v3 1/2] Add new GDB command "maint print user-registers"
2014-12-10 17:22 [PATCH v3 0/2] Provide useful completer for "info registers" Andreas Arnez
@ 2014-12-10 17:22 ` Andreas Arnez
2014-12-10 17:38 ` Doug Evans
2014-12-10 18:14 ` Eli Zaretskii
2014-12-10 17:22 ` [PATCH v3 2/2] Provide completer for "info registers" Andreas Arnez
1 sibling, 2 replies; 8+ messages in thread
From: Andreas Arnez @ 2014-12-10 17:22 UTC (permalink / raw)
To: gdb-patches
This adds a command for listing the "user" registers. So far GDB
offered no means of determining the set of user registers and omitted
them from all other register listings.
gdb/ChangeLog:
* user-regs.c: Include "target.h" and "cli/cli-cmds.h".
(maintenance_print_user_registers): New.
(_initialize_user_regs): Register new "maint print user-registers"
subcommand.
* NEWS: Mention new GDB command "maint print user-registers".
gdb/doc/ChangeLog:
* gdb.texinfo: Document "maint print user-registers".
---
gdb/NEWS | 3 +++
gdb/doc/gdb.texinfo | 12 ++++++++++++
gdb/user-regs.c | 30 ++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+)
diff --git a/gdb/NEWS b/gdb/NEWS
index 6a2cb9b..a47dfbf 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -45,6 +45,9 @@ add-auto-load-scripts-directory directory
Add entries to the list of directories from which to load auto-loaded
scripts.
+maint print user-registers
+ List all currently available "user" registers.
+
* On resume, GDB now always passes the signal the program had stopped
for to the thread the signal was sent to, even if the user changed
threads before resuming. Previously GDB would often (but not
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 670c369..c321605 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -10256,6 +10256,7 @@ the selected stack frame. The @var{regname} may be any register name valid on
the machine you are using, with or without the initial @samp{$}.
@end table
+@anchor{standard registers}
@cindex stack pointer register
@cindex program counter register
@cindex process status register
@@ -33435,6 +33436,17 @@ If @var{regexp} is specified, only print object files whose names
match @var{regexp}. For each object file, this command prints its name,
address in memory, and all of its psymtabs and symtabs.
+@kindex maint print user-registers
+@cindex user registers
+@item maint print user-registers
+List all currently available ``user'' registers. User registers
+typically provide alternate names for actual hardware registers. They
+include the four ``standard'' registers @code{$fp}, @code{$pc},
+@code{$sp}, and @code{$ps}. @xref{standard registers}. User
+registers can be used in expressions in the same way as the canonical
+register names, but only the latter are listed by the @code{info
+registers} and @code{maint print registers} commands.
+
@kindex maint print section-scripts
@cindex info for known .debug_gdb_scripts-loaded scripts
@item maint print section-scripts [@var{regexp}]
diff --git a/gdb/user-regs.c b/gdb/user-regs.c
index 35d64ec..84ecf3a 100644
--- a/gdb/user-regs.c
+++ b/gdb/user-regs.c
@@ -23,6 +23,8 @@
#include "user-regs.h"
#include "gdbtypes.h"
#include "frame.h"
+#include "target.h"
+#include "cli/cli-cmds.h"
/* A table of user registers.
@@ -215,10 +217,38 @@ value_of_user_reg (int regnum, struct frame_info *frame)
return reg->read (frame, reg->baton);
}
+static void
+maintenance_print_user_registers (char *args, int from_tty)
+{
+ struct gdbarch *gdbarch;
+ struct gdb_user_regs *regs;
+ struct user_reg *reg;
+ int nr;
+
+ if (!target_has_registers)
+ error (_("The program has no registers now."));
+
+ gdbarch = get_frame_arch (get_selected_frame (NULL));
+ regs = gdbarch_data (gdbarch, user_regs_data);
+ nr = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
+
+ fprintf_unfiltered (gdb_stdout, " Nr Name\n");
+ for (reg = regs->first; reg != NULL; reg = reg->next)
+ {
+ fprintf_unfiltered (gdb_stdout, "%3d %s\n", nr, reg->name);
+ nr++;
+ }
+}
+
extern initialize_file_ftype _initialize_user_regs; /* -Wmissing-prototypes */
void
_initialize_user_regs (void)
{
user_regs_data = gdbarch_data_register_post_init (user_regs_init);
+
+ add_cmd ("user-registers", class_maintenance,
+ maintenance_print_user_registers,
+ _("List the names of the current user registers.\n"),
+ &maintenanceprintlist);
}
--
1.8.4.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 2/2] Provide completer for "info registers"
2014-12-10 17:22 [PATCH v3 0/2] Provide useful completer for "info registers" Andreas Arnez
2014-12-10 17:22 ` [PATCH v3 1/2] Add new GDB command "maint print user-registers" Andreas Arnez
@ 2014-12-10 17:22 ` Andreas Arnez
1 sibling, 0 replies; 8+ messages in thread
From: Andreas Arnez @ 2014-12-10 17:22 UTC (permalink / raw)
To: gdb-patches
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.
Also add a test for this new feature to "completion.exp": Determine
the target's available set of registers/reggroups and compare this to
the completion of "info registers ". For determining the available
registers involve the new "maint print user-registers" command.
gdb/ChangeLog:
* 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.
gdb/testsuite/ChangeLog:
* gdb.base/completion.exp: Add test for completion of "info
registers ".
---
gdb/completer.c | 42 +++++++++++++++++++++++++++++++++++
gdb/completer.h | 3 +++
gdb/infcmd.c | 12 +++++++---
gdb/testsuite/gdb.base/completion.exp | 31 ++++++++++++++++++++++++++
4 files changed, 85 insertions(+), 3 deletions(-)
diff --git a/gdb/completer.c b/gdb/completer.c
index a0f3fa3..6767225 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -23,6 +23,9 @@
#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"
@@ -836,6 +839,45 @@ 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 (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. */
diff --git a/gdb/completer.h b/gdb/completer.h
index bc7ed96..5e91030 100644
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -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);
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 4415b31..de0d24d 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -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."));
diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index c633a51..080a7c2 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -137,6 +137,37 @@ gdb_test "complete set listsize unl" "set listsize unlimited"
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+\S*)} $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 {\d+\s+(\w+\S*)} $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.
--
1.8.4.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 0/2] Provide useful completer for "info registers"
@ 2014-12-10 17:22 Andreas Arnez
2014-12-10 17:22 ` [PATCH v3 1/2] Add new GDB command "maint print user-registers" Andreas Arnez
2014-12-10 17:22 ` [PATCH v3 2/2] Provide completer for "info registers" Andreas Arnez
0 siblings, 2 replies; 8+ messages in thread
From: Andreas Arnez @ 2014-12-10 17:22 UTC (permalink / raw)
To: gdb-patches
Last version here:
https://sourceware.org/ml/gdb-patches/2014-11/msg00720.html
New in v3:
* Omit registers with an empty name from the completion result.
* Add user registers to the completion result.
* Add a new GDB command "maint print user-registers". Exploit this in
the test case for "info registers".
Andreas Arnez (2):
Add new GDB command "maint print user-registers"
Provide completer for "info registers"
gdb/NEWS | 3 +++
gdb/completer.c | 42 +++++++++++++++++++++++++++++++++++
gdb/completer.h | 3 +++
gdb/doc/gdb.texinfo | 12 ++++++++++
gdb/infcmd.c | 12 +++++++---
gdb/testsuite/gdb.base/completion.exp | 31 ++++++++++++++++++++++++++
gdb/user-regs.c | 30 +++++++++++++++++++++++++
7 files changed, 130 insertions(+), 3 deletions(-)
--
1.8.4.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 1/2] Add new GDB command "maint print user-registers"
2014-12-10 17:22 ` [PATCH v3 1/2] Add new GDB command "maint print user-registers" Andreas Arnez
@ 2014-12-10 17:38 ` Doug Evans
2014-12-10 18:29 ` Andreas Arnez
2014-12-10 18:14 ` Eli Zaretskii
1 sibling, 1 reply; 8+ messages in thread
From: Doug Evans @ 2014-12-10 17:38 UTC (permalink / raw)
To: Andreas Arnez; +Cc: gdb-patches
Andreas Arnez <arnez@linux.vnet.ibm.com> writes:
> [...]
> @@ -215,10 +217,38 @@ value_of_user_reg (int regnum, struct frame_info *frame)
> return reg->read (frame, reg->baton);
> }
>
> +static void
> +maintenance_print_user_registers (char *args, int from_tty)
> +{
> + struct gdbarch *gdbarch;
> + struct gdb_user_regs *regs;
> + struct user_reg *reg;
> + int nr;
> +
> + if (!target_has_registers)
> + error (_("The program has no registers now."));
> +
> + gdbarch = get_frame_arch (get_selected_frame (NULL));
> + regs = gdbarch_data (gdbarch, user_regs_data);
> + nr = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
> +
> + fprintf_unfiltered (gdb_stdout, " Nr Name\n");
> + for (reg = regs->first; reg != NULL; reg = reg->next)
> + {
> + fprintf_unfiltered (gdb_stdout, "%3d %s\n", nr, reg->name);
> + nr++;
> + }
> +}
> +
> [...]
Hi.
Nit: I realize the rest of the file uses "nr" but
it's a horrible name. I hadn't read user-regs.c
in awhile, and was reading your patch absent that context.
I read "nr" and think "number of registers",
and that's the only thing that comes to mind
as a possible interpretation.
I'm not asking you to change any other uses,
but can I ask that "nr" here be named "regnum" or some such.
In the column title you could use "Num" or some such.
Also, I think the loop would be more readable thusly:
+ for (reg = regs->first; reg != NULL; reg = reg->next, regnum++)
I have a slight preference for this instead:
+ for (reg = regs->first; reg != NULL; reg = reg->next, ++regnum)
but the rest of the file uses post-inc, so whatever.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 1/2] Add new GDB command "maint print user-registers"
2014-12-10 17:22 ` [PATCH v3 1/2] Add new GDB command "maint print user-registers" Andreas Arnez
2014-12-10 17:38 ` Doug Evans
@ 2014-12-10 18:14 ` Eli Zaretskii
2014-12-10 18:33 ` Andreas Arnez
1 sibling, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2014-12-10 18:14 UTC (permalink / raw)
To: Andreas Arnez; +Cc: gdb-patches
> From: Andreas Arnez <arnez@linux.vnet.ibm.com>
> Date: Wed, 10 Dec 2014 18:22:38 +0100
>
> This adds a command for listing the "user" registers. So far GDB
> offered no means of determining the set of user registers and omitted
> them from all other register listings.
Thanks.
> +@kindex maint print user-registers
> +@cindex user registers
> +@item maint print user-registers
> +List all currently available ``user'' registers. User registers
When you first introduce new terminology, it is best to use @dfn, like
this:
List all currently available @dfn{user registers}.
This will look prettier in print, and will have the same effect as
``..'' in the Info manual.
Other than that, the documentation parts are OK.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 1/2] Add new GDB command "maint print user-registers"
2014-12-10 17:38 ` Doug Evans
@ 2014-12-10 18:29 ` Andreas Arnez
2014-12-11 18:35 ` Doug Evans
0 siblings, 1 reply; 8+ messages in thread
From: Andreas Arnez @ 2014-12-10 18:29 UTC (permalink / raw)
To: Doug Evans; +Cc: gdb-patches
On Wed, Dec 10 2014, Doug Evans wrote:
> Nit: I realize the rest of the file uses "nr" but
> it's a horrible name. I hadn't read user-regs.c
> in awhile, and was reading your patch absent that context.
> I read "nr" and think "number of registers",
> and that's the only thing that comes to mind
> as a possible interpretation.
>
> I'm not asking you to change any other uses,
> but can I ask that "nr" here be named "regnum" or some such.
Yes, I agree that "nr" is a bad name. I will rename the variable to
"regnum" instead.
> In the column title you could use "Num" or some such.
Hm, that would be inconsistent with "maint print registers", which uses
"Nr" in the title as well. IMHO all user-visible interfaces should use
the same title for this column. Maybe we can change that in a separate
patch.
> Also, I think the loop would be more readable thusly:
>
> + for (reg = regs->first; reg != NULL; reg = reg->next, regnum++)
>
> I have a slight preference for this instead:
>
> + for (reg = regs->first; reg != NULL; reg = reg->next, ++regnum)
>
> but the rest of the file uses post-inc, so whatever.
Right, this reduces code and improves clarity. Will change as
suggested.
Based on your suggestions, I will adjust the patch as indicated below.
-- >8 --
Subject: Style improvements for maintenance_print_user_registers
diff --git a/gdb/user-regs.c b/gdb/user-regs.c
index 84ecf3a..b70dd45 100644
--- a/gdb/user-regs.c
+++ b/gdb/user-regs.c
@@ -223,21 +223,18 @@ maintenance_print_user_registers (char *args, int from_tty)
struct gdbarch *gdbarch;
struct gdb_user_regs *regs;
struct user_reg *reg;
- int nr;
+ int regnum;
if (!target_has_registers)
error (_("The program has no registers now."));
gdbarch = get_frame_arch (get_selected_frame (NULL));
regs = gdbarch_data (gdbarch, user_regs_data);
- nr = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
+ regnum = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
fprintf_unfiltered (gdb_stdout, " Nr Name\n");
- for (reg = regs->first; reg != NULL; reg = reg->next)
- {
- fprintf_unfiltered (gdb_stdout, "%3d %s\n", nr, reg->name);
- nr++;
- }
+ for (reg = regs->first; reg != NULL; reg = reg->next, ++regnum)
+ fprintf_unfiltered (gdb_stdout, "%3d %s\n", regnum, reg->name);
}
extern initialize_file_ftype _initialize_user_regs; /* -Wmissing-prototypes */
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 1/2] Add new GDB command "maint print user-registers"
2014-12-10 18:14 ` Eli Zaretskii
@ 2014-12-10 18:33 ` Andreas Arnez
0 siblings, 0 replies; 8+ messages in thread
From: Andreas Arnez @ 2014-12-10 18:33 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
On Wed, Dec 10 2014, Eli Zaretskii wrote:
> When you first introduce new terminology, it is best to use @dfn, like
> this:
>
> List all currently available @dfn{user registers}.
>
> This will look prettier in print, and will have the same effect as
> ``..'' in the Info manual.
Sure, I will include this change in the next version.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 1/2] Add new GDB command "maint print user-registers"
2014-12-10 18:29 ` Andreas Arnez
@ 2014-12-11 18:35 ` Doug Evans
0 siblings, 0 replies; 8+ messages in thread
From: Doug Evans @ 2014-12-11 18:35 UTC (permalink / raw)
To: Andreas Arnez; +Cc: gdb-patches
On Wed, Dec 10, 2014 at 10:29 AM, Andreas Arnez
<arnez@linux.vnet.ibm.com> wrote:
>> In the column title you could use "Num" or some such.
>
> Hm, that would be inconsistent with "maint print registers", which uses
> "Nr" in the title as well. IMHO all user-visible interfaces should use
> the same title for this column. Maybe we can change that in a separate
> patch.
No disagreement there.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-12-11 18:35 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-10 17:22 [PATCH v3 0/2] Provide useful completer for "info registers" Andreas Arnez
2014-12-10 17:22 ` [PATCH v3 1/2] Add new GDB command "maint print user-registers" Andreas Arnez
2014-12-10 17:38 ` Doug Evans
2014-12-10 18:29 ` Andreas Arnez
2014-12-11 18:35 ` Doug Evans
2014-12-10 18:14 ` Eli Zaretskii
2014-12-10 18:33 ` Andreas Arnez
2014-12-10 17:22 ` [PATCH v3 2/2] Provide completer for "info registers" Andreas Arnez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).