[2/2] Use ui-out tables in "maint print user-regs"

Message ID 20241006-more-use-of-ui-table-v1-2-baf53ee69161@tromey.com
State New
Headers
Series More use of ui-out tables |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom Tromey Oct. 6, 2024, 7:02 p.m. UTC
  This changes "maint print user-regs" to use ui-out tables rather than
printfs.
---
 gdb/testsuite/gdb.base/completion.exp |  2 +-
 gdb/user-regs.c                       | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)
  

Comments

Andrew Burgess Oct. 7, 2024, 9:19 a.m. UTC | #1
Tom Tromey <tom@tromey.com> writes:

> This changes "maint print user-regs" to use ui-out tables rather than
> printfs.
> ---
>  gdb/testsuite/gdb.base/completion.exp |  2 +-
>  gdb/user-regs.c                       | 14 ++++++++++++--
>  2 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
> index 4a0a373fe1f553c5b9670de5bd5ded59d884cabf..57b4d1c1045a2fad8d947fd804f3698a32960b52 100644
> --- a/gdb/testsuite/gdb.base/completion.exp
> +++ b/gdb/testsuite/gdb.base/completion.exp
> @@ -145,7 +145,7 @@ 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] {
> +foreach {- reg} [regexp -all -inline -line {^\s*(\w+)} $regs_output] {

With the register name left aligned, is there actually any way that we
can get a space before the name?  I think you should just remove the
'\s*' completely.  With that:

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew


>      lappend all_regs $reg
>  }
>  
> diff --git a/gdb/user-regs.c b/gdb/user-regs.c
> index ac04f63dbb805a9f1263b8b5f7d991f313665c97..2ace46eda1d2d728dcdf5a757a9345d5e6316d32 100644
> --- a/gdb/user-regs.c
> +++ b/gdb/user-regs.c
> @@ -222,9 +222,19 @@ maintenance_print_user_registers (const char *args, int from_tty)
>    struct gdb_user_regs *regs = get_user_regs (gdbarch);
>    regnum = gdbarch_num_cooked_regs (gdbarch);
>  
> -  gdb_printf (" %-11s %3s\n", "Name", "Nr");
> +  ui_out_emit_table emitter (current_uiout, 2, -1, "UserRegs");
> +
> +  current_uiout->table_header (11, ui_left, "name", "Name");
> +  current_uiout->table_header (3, ui_left, "regnum", "Nr");
> +  current_uiout->table_body ();
> +
>    for (reg = regs->first; reg != NULL; reg = reg->next, ++regnum)
> -    gdb_printf (" %-11s %3d\n", reg->name, regnum);
> +    {
> +      ui_out_emit_tuple tuple_emitter (current_uiout, nullptr);
> +      current_uiout->field_string ("name", reg->name);
> +      current_uiout->field_signed ("regnum", regnum);
> +      current_uiout->text ("\n");
> +    }
>  }
>  
>  void _initialize_user_regs ();
>
> -- 
> 2.46.1
  
Tom Tromey Oct. 8, 2024, 11:55 p.m. UTC | #2
>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:

Andrew> With the register name left aligned, is there actually any way that we
Andrew> can get a space before the name?  I think you should just remove the
Andrew> '\s*' completely.  With that:

It's needed to match the "mt print registers" and "mt print reggroups"
output.

Those should probably be converted to use ui-out as well but I didn't
look into it yet.

Tom
  
Andrew Burgess Oct. 14, 2024, 2:05 p.m. UTC | #3
Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>
> Andrew> With the register name left aligned, is there actually any way that we
> Andrew> can get a space before the name?  I think you should just remove the
> Andrew> '\s*' completely.  With that:
>
> It's needed to match the "mt print registers" and "mt print reggroups"
> output.
>
> Those should probably be converted to use ui-out as well but I didn't
> look into it yet.

Ahh, that makes sense.  No change needed then.

Thanks,
Andrew
  

Patch

diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index 4a0a373fe1f553c5b9670de5bd5ded59d884cabf..57b4d1c1045a2fad8d947fd804f3698a32960b52 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -145,7 +145,7 @@  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] {
+foreach {- reg} [regexp -all -inline -line {^\s*(\w+)} $regs_output] {
     lappend all_regs $reg
 }
 
diff --git a/gdb/user-regs.c b/gdb/user-regs.c
index ac04f63dbb805a9f1263b8b5f7d991f313665c97..2ace46eda1d2d728dcdf5a757a9345d5e6316d32 100644
--- a/gdb/user-regs.c
+++ b/gdb/user-regs.c
@@ -222,9 +222,19 @@  maintenance_print_user_registers (const char *args, int from_tty)
   struct gdb_user_regs *regs = get_user_regs (gdbarch);
   regnum = gdbarch_num_cooked_regs (gdbarch);
 
-  gdb_printf (" %-11s %3s\n", "Name", "Nr");
+  ui_out_emit_table emitter (current_uiout, 2, -1, "UserRegs");
+
+  current_uiout->table_header (11, ui_left, "name", "Name");
+  current_uiout->table_header (3, ui_left, "regnum", "Nr");
+  current_uiout->table_body ();
+
   for (reg = regs->first; reg != NULL; reg = reg->next, ++regnum)
-    gdb_printf (" %-11s %3d\n", reg->name, regnum);
+    {
+      ui_out_emit_tuple tuple_emitter (current_uiout, nullptr);
+      current_uiout->field_string ("name", reg->name);
+      current_uiout->field_signed ("regnum", regnum);
+      current_uiout->text ("\n");
+    }
 }
 
 void _initialize_user_regs ();