public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 1/3] Use ui-out in maintenance_print_user_registers
Date: Sun, 03 Mar 2024 11:43:03 -0700	[thread overview]
Message-ID: <20240303-info-proc-ui-out-v2-1-cf3d2013b33e@tromey.com> (raw)
In-Reply-To: <20240303-info-proc-ui-out-v2-0-cf3d2013b33e@tromey.com>

This changes maintenance_print_user_registers to use a ui-out table.
---
 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 3dbdd0f428b..127ec235371 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 d1b510a7927..36661471595 100644
--- a/gdb/user-regs.c
+++ b/gdb/user-regs.c
@@ -223,9 +223,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");
+  struct ui_out *uiout = current_uiout;
+  ui_out_emit_table table_emitter (uiout, 2, -1, "user-registers");
+  uiout->table_header (11, ui_left, "name", "Name");
+  uiout->table_header (3, ui_right, "number", "Nr");
+
+  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 (uiout, nullptr);
+      uiout->field_string ("name", reg->name);
+      uiout->field_signed ("number", regnum);
+      uiout->text ("\n");
+    }
 }
 
 void _initialize_user_regs ();

-- 
2.43.0


  reply	other threads:[~2024-03-03 18:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-03 18:43 [PATCH v2 0/3] Use ui-out tables in a few spots Tom Tromey
2024-03-03 18:43 ` Tom Tromey [this message]
2024-03-03 18:43 ` [PATCH v2 2/3] Use ui-out in core_target::info_proc_mappings Tom Tromey
2024-03-03 18:43 ` [PATCH v2 3/3] Use ui-out tables in linux-tdep.c Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240303-info-proc-ui-out-v2-1-cf3d2013b33e@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).