public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v4 1/2] Add new GDB command "maint print user-registers"
  2014-12-11 11:49 [PATCH v4 0/2] Provide useful completer for "info registers" Andreas Arnez
  2014-12-11 11:49 ` [PATCH v4 2/2] Provide " Andreas Arnez
@ 2014-12-11 11:49 ` Andreas Arnez
  2014-12-12 13:19   ` Pedro Alves
  1 sibling, 1 reply; 10+ messages in thread
From: Andreas Arnez @ 2014-12-11 11:49 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 "arch-utils.h", "command.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     | 24 ++++++++++++++++++++++++
 3 files changed, 39 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..4986a68 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 @dfn{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..adaa959 100644
--- a/gdb/user-regs.c
+++ b/gdb/user-regs.c
@@ -23,6 +23,9 @@
 #include "user-regs.h"
 #include "gdbtypes.h"
 #include "frame.h"
+#include "arch-utils.h"
+#include "command.h"
+#include "cli/cli-cmds.h"
 
 /* A table of user registers.
 
@@ -215,10 +218,31 @@ 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 = get_current_arch ();
+  struct gdb_user_regs *regs;
+  struct user_reg *reg;
+  int regnum;
+
+  regs = gdbarch_data (gdbarch, user_regs_data);
+  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, ++regnum)
+    fprintf_unfiltered (gdb_stdout, "%3d  %s\n", regnum, reg->name);
+}
+
 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] 10+ messages in thread

* [PATCH v4 0/2] Provide useful completer for "info registers"
@ 2014-12-11 11:49 Andreas Arnez
  2014-12-11 11:49 ` [PATCH v4 2/2] Provide " Andreas Arnez
  2014-12-11 11:49 ` [PATCH v4 1/2] Add new GDB command "maint print user-registers" Andreas Arnez
  0 siblings, 2 replies; 10+ messages in thread
From: Andreas Arnez @ 2014-12-11 11:49 UTC (permalink / raw)
  To: gdb-patches

Last version here:

  https://sourceware.org/ml/gdb-patches/2014-12/msg00212.html

New in v4:

* In maintenance_print_user_registers, no longer require
  target_has_registers, but get the gdbarch with get_current_arch().

* Cosmetic changes in maintenance_print_user_registers: Rename the
  variable "nr" to "regnum"; increment regnum in the for-loop
  iterator instead of the loop body.

* In the documentation for the new command, enclose the first
  occurrence of "user registers" in @dfn{}.


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                       | 24 ++++++++++++++++++++
 7 files changed, 124 insertions(+), 3 deletions(-)

-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v4 2/2] Provide completer for "info registers"
  2014-12-11 11:49 [PATCH v4 0/2] Provide useful completer for "info registers" Andreas Arnez
@ 2014-12-11 11:49 ` Andreas Arnez
  2014-12-12 13:20   ` Pedro Alves
  2014-12-11 11:49 ` [PATCH v4 1/2] Add new GDB command "maint print user-registers" Andreas Arnez
  1 sibling, 1 reply; 10+ messages in thread
From: Andreas Arnez @ 2014-12-11 11:49 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] 10+ messages in thread

* Re: [PATCH v4 1/2] Add new GDB command "maint print user-registers"
  2014-12-11 11:49 ` [PATCH v4 1/2] Add new GDB command "maint print user-registers" Andreas Arnez
@ 2014-12-12 13:19   ` Pedro Alves
  0 siblings, 0 replies; 10+ messages in thread
From: Pedro Alves @ 2014-12-12 13:19 UTC (permalink / raw)
  To: Andreas Arnez, gdb-patches

On 12/11/2014 11:49 AM, Andreas Arnez wrote:
> 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 "arch-utils.h", "command.h", and
> 	"cli/cli-cmds.h".
> 	(maintenance_print_user_registers): New.
> 	(_initialize_user_regs): Register new "maint print user-registers"
> 	subcommand.

This looks good to me.  Thanks for doing this.

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/2] Provide completer for "info registers"
  2014-12-11 11:49 ` [PATCH v4 2/2] Provide " Andreas Arnez
@ 2014-12-12 13:20   ` Pedro Alves
  2014-12-12 15:20     ` Andreas Arnez
  0 siblings, 1 reply; 10+ messages in thread
From: Pedro Alves @ 2014-12-12 13:20 UTC (permalink / raw)
  To: Andreas Arnez, gdb-patches

On 12/11/2014 11:49 AM, Andreas Arnez wrote:

> +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] {

This "->" here confused me a little.  AFAIK, $- is a more common "don't care"
variable (and what foreach's documentation suggests).  Any reason to
pick -> instead?

Also, why do we need the "\S*" ?  I'd assume {^\s+(\w+)} works just as well.

> +    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] {

Likewise.

Otherwise this looks good to me.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/2] Provide completer for "info registers"
  2014-12-12 13:20   ` Pedro Alves
@ 2014-12-12 15:20     ` Andreas Arnez
  2014-12-12 15:30       ` Pedro Alves
  2014-12-12 17:45       ` Doug Evans
  0 siblings, 2 replies; 10+ messages in thread
From: Andreas Arnez @ 2014-12-12 15:20 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Fri, Dec 12 2014, Pedro Alves wrote:

> On 12/11/2014 11:49 AM, Andreas Arnez wrote:
>
>> +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] {
>
> This "->" here confused me a little.  AFAIK, $- is a more common "don't care"
> variable (and what foreach's documentation suggests).  Any reason to
> pick -> instead?

I think I've borrowed this from an example in the regexp's
documentation:

  regexp {\mfoo(?!bar\M)(\w*)} $string -> restOfWord

Admittedly, in the foreach case this does not look as nicely.  So I will
change it to "-", as suggested.

> Also, why do we need the "\S*" ?  I'd assume {^\s+(\w+)} works just as well.

OK, all existing register and reggroup names consist wholly of
alphanumeric and underscore characters.  So I will change the pattern as
suggested.

>
>> +    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] {
>
> Likewise.

Yes.  And looking at it again, I think that this pattern should be more
consistent with the one above and match the whole beginning of a line.
Thus I will rephrase it to {^\s+\d+\s+(\w+)}.  In this way the command
can add more columns in the future without having to adjust the pattern
here.

> Otherwise this looks good to me.

Thanks.  Will push this then with changes below.

--

--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -146,13 +146,13 @@ 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] {
+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 {\d+\s+(\w+\S*)} $regs_output] {
+foreach {- reg} [regexp -all -inline -line {^\s+\d+\s+(\w+)} $regs_output] {
     lappend all_regs $reg
 }

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/2] Provide completer for "info registers"
  2014-12-12 15:20     ` Andreas Arnez
@ 2014-12-12 15:30       ` Pedro Alves
  2014-12-12 17:45       ` Doug Evans
  1 sibling, 0 replies; 10+ messages in thread
From: Pedro Alves @ 2014-12-12 15:30 UTC (permalink / raw)
  To: Andreas Arnez; +Cc: gdb-patches

On 12/12/2014 03:20 PM, Andreas Arnez wrote:

> Thanks.  Will push this then with changes below.

Great, that looks good.

Thanks again for doing this.

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/2] Provide completer for "info registers"
  2014-12-12 15:20     ` Andreas Arnez
  2014-12-12 15:30       ` Pedro Alves
@ 2014-12-12 17:45       ` Doug Evans
  2014-12-12 19:04         ` Andreas Arnez
  1 sibling, 1 reply; 10+ messages in thread
From: Doug Evans @ 2014-12-12 17:45 UTC (permalink / raw)
  To: Andreas Arnez; +Cc: Pedro Alves, gdb-patches

On Fri, Dec 12, 2014 at 7:20 AM, Andreas Arnez <arnez@linux.vnet.ibm.com> wrote:
> On Fri, Dec 12 2014, Pedro Alves wrote:
>
>> On 12/11/2014 11:49 AM, Andreas Arnez wrote:
>>
>>> +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] {
>>
>> This "->" here confused me a little.  AFAIK, $- is a more common "don't care"
>> variable (and what foreach's documentation suggests).  Any reason to
>> pick -> instead?
>
> I think I've borrowed this from an example in the regexp's
> documentation:
>
>   regexp {\mfoo(?!bar\M)(\w*)} $string -> restOfWord
>
> Admittedly, in the foreach case this does not look as nicely.  So I will
> change it to "-", as suggested.
>
>> Also, why do we need the "\S*" ?  I'd assume {^\s+(\w+)} works just as well.
>
> OK, all existing register and reggroup names consist wholly of
> alphanumeric and underscore characters.  So I will change the pattern as
> suggested.
>
>>
>>> +    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] {
>>
>> Likewise.
>
> Yes.  And looking at it again, I think that this pattern should be more
> consistent with the one above and match the whole beginning of a line.
> Thus I will rephrase it to {^\s+\d+\s+(\w+)}.  In this way the command
> can add more columns in the future without having to adjust the pattern
> here.
>
>> Otherwise this looks good to me.
>
> Thanks.  Will push this then with changes below.
>
> --
>
> --- a/gdb/testsuite/gdb.base/completion.exp
> +++ b/gdb/testsuite/gdb.base/completion.exp
> @@ -146,13 +146,13 @@ 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] {
> +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 {\d+\s+(\w+\S*)} $regs_output] {
> +foreach {- reg} [regexp -all -inline -line {^\s+\d+\s+(\w+)} $regs_output] {
>      lappend all_regs $reg
>  }
>


Hi.
I'm seeing the following new failure on amd64-linux:

(gdb) complete info registers ^M
info registers ah^M
info registers al^M
...
info registers ymm9^M
info registers ymm9h^M
(gdb) FAIL: gdb.base/completion.exp: complete 'info registers '

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/2] Provide completer for "info registers"
  2014-12-12 17:45       ` Doug Evans
@ 2014-12-12 19:04         ` Andreas Arnez
  2014-12-15 12:41           ` Pedro Alves
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Arnez @ 2014-12-12 19:04 UTC (permalink / raw)
  To: Doug Evans; +Cc: Pedro Alves, gdb-patches

On Fri, Dec 12 2014, Doug Evans wrote:

> I'm seeing the following new failure on amd64-linux:
>
> (gdb) complete info registers ^M
> info registers ah^M
> info registers al^M
> ...
> info registers ymm9^M
> info registers ymm9h^M
> (gdb) FAIL: gdb.base/completion.exp: complete 'info registers '

Oops.  This is because the user registers have 3-digit numbers and thus
occupy the first column in the output of "maint print user-registers".
This doesn't match the latest version of the regexp in completion.exp.

In fact, this is a useful finding, because the output of "maint print
user-registers" should actually be indented.

Here's a suggested fix.


-- >8 --
Subject: [PATCH] Fix indentation of "maint print user-registers"

This fixes a failure of the test case "complete 'info registers '" in
completion.exp on architectures where the user registers have numbers
above 99.  In that case the output of "maint print user-registers" was
no longer indented, and the regexp in the test case failed to add them
to the list of expected completion results.  The fix also swaps the
columns "Name" and "Nr", such that the indentation is always the same,
and to be consistent with the output of "maint print registers".

gdb/ChangeLog:

	* user-regs.c (maintenance_print_user_registers): Swap "Nr" and
	"Name" columns.  Assure that the output is always indented.

gdb/testsuite/ChangeLog:

	* gdb.base/completion.exp: Adjust to format changes of "maint
	print user-registers".


diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index 08e1a52..9c79a29 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -145,17 +145,14 @@ set regs_output [capture_command_output "mt print registers" \
 append regs_output "\n"
 append regs_output [capture_command_output "mt print reggroups" \
 			".*Group.*Type\[^\n]*\n"]
+append regs_output "\n"
+append regs_output [capture_command_output "mt print user-registers" \
+		     ".*Name.*Nr\[^\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".
diff --git a/gdb/user-regs.c b/gdb/user-regs.c
index adaa959..6cdea16 100644
--- a/gdb/user-regs.c
+++ b/gdb/user-regs.c
@@ -229,9 +229,9 @@ maintenance_print_user_registers (char *args, int from_tty)
   regs = gdbarch_data (gdbarch, user_regs_data);
   regnum = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
 
-  fprintf_unfiltered (gdb_stdout, " Nr  Name\n");
+  fprintf_unfiltered (gdb_stdout, " %-11s %3s\n", "Name", "Nr");
   for (reg = regs->first; reg != NULL; reg = reg->next, ++regnum)
-    fprintf_unfiltered (gdb_stdout, "%3d  %s\n", regnum, reg->name);
+    fprintf_unfiltered (gdb_stdout, " %-11s %3d\n", reg->name, regnum);
 }
 
 extern initialize_file_ftype _initialize_user_regs; /* -Wmissing-prototypes */

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/2] Provide completer for "info registers"
  2014-12-12 19:04         ` Andreas Arnez
@ 2014-12-15 12:41           ` Pedro Alves
  0 siblings, 0 replies; 10+ messages in thread
From: Pedro Alves @ 2014-12-15 12:41 UTC (permalink / raw)
  To: Andreas Arnez, Doug Evans; +Cc: gdb-patches

On 12/12/2014 07:04 PM, Andreas Arnez wrote:
> On Fri, Dec 12 2014, Doug Evans wrote:
> 
>> I'm seeing the following new failure on amd64-linux:
>>
>> (gdb) complete info registers ^M
>> info registers ah^M
>> info registers al^M
>> ...
>> info registers ymm9^M
>> info registers ymm9h^M
>> (gdb) FAIL: gdb.base/completion.exp: complete 'info registers '
> 
> Oops.  This is because the user registers have 3-digit numbers and thus
> occupy the first column in the output of "maint print user-registers".
> This doesn't match the latest version of the regexp in completion.exp.
> 
> In fact, this is a useful finding, because the output of "maint print
> user-registers" should actually be indented.
> 
> Here's a suggested fix.

OK, thanks.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-12-15 12:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-11 11:49 [PATCH v4 0/2] Provide useful completer for "info registers" Andreas Arnez
2014-12-11 11:49 ` [PATCH v4 2/2] Provide " Andreas Arnez
2014-12-12 13:20   ` Pedro Alves
2014-12-12 15:20     ` Andreas Arnez
2014-12-12 15:30       ` Pedro Alves
2014-12-12 17:45       ` Doug Evans
2014-12-12 19:04         ` Andreas Arnez
2014-12-15 12:41           ` Pedro Alves
2014-12-11 11:49 ` [PATCH v4 1/2] Add new GDB command "maint print user-registers" Andreas Arnez
2014-12-12 13:19   ` Pedro Alves

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).