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 2/3] Use ui-out in core_target::info_proc_mappings
Date: Sun, 03 Mar 2024 11:43:04 -0700	[thread overview]
Message-ID: <20240303-info-proc-ui-out-v2-2-cf3d2013b33e@tromey.com> (raw)
In-Reply-To: <20240303-info-proc-ui-out-v2-0-cf3d2013b33e@tromey.com>

This changes core_target::info_proc_mappings to use a ui-out table.
It also changes the output to style the file names.
---
 gdb/corelow.c | 54 ++++++++++++++++++++++--------------------------------
 1 file changed, 22 insertions(+), 32 deletions(-)

diff --git a/gdb/corelow.c b/gdb/corelow.c
index f291b2aba19..5c9268efa24 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -54,6 +54,7 @@
 #include "gdbcmd.h"
 #include "xml-tdesc.h"
 #include "memtag.h"
+#include "cli/cli-style.h"
 
 #ifndef O_LARGEFILE
 #define O_LARGEFILE 0
@@ -1444,25 +1445,21 @@ get_current_core_target ()
 void
 core_target::info_proc_mappings (struct gdbarch *gdbarch)
 {
-  if (!m_core_file_mappings.empty ())
-    {
-      gdb_printf (_("Mapped address spaces:\n\n"));
-      if (gdbarch_addr_bit (gdbarch) == 32)
-	{
-	  gdb_printf ("\t%10s %10s %10s %10s %s\n",
-		      "Start Addr",
-		      "  End Addr",
-		      "      Size", "    Offset", "objfile");
-	}
-      else
-	{
-	  gdb_printf ("  %18s %18s %10s %10s %s\n",
-		      "Start Addr",
-		      "  End Addr",
-		      "      Size", "    Offset", "objfile");
-	}
-    }
+  if (m_core_file_mappings.empty ())
+    return;
 
+  struct ui_out *uiout = current_uiout;
+  uiout->text (_("Mapped address spaces:\n\n"));
+  ui_out_emit_table table_emitter (uiout, 5, -1, "mappings");
+  int width = gdbarch_addr_bit (gdbarch) == 32 ? 10 : 18;
+  uiout->table_header (width, ui_right, "start", "Start Addr");
+  uiout->table_header (width, ui_right, "end", "End Addr");
+  uiout->table_header (10, ui_right, "size", "Size");
+  uiout->table_header (10, ui_right, "offset", "Offset");
+  uiout->table_header (10, ui_left, "objfile", "objfile");
+
+  uiout->table_body ();
+  ui_file_style filenames = file_name_style.style ();
   for (const target_section &tsp : m_core_file_mappings)
     {
       ULONGEST start = tsp.addr;
@@ -1470,20 +1467,13 @@ core_target::info_proc_mappings (struct gdbarch *gdbarch)
       ULONGEST file_ofs = tsp.the_bfd_section->filepos;
       const char *filename = bfd_get_filename (tsp.the_bfd_section->owner);
 
-      if (gdbarch_addr_bit (gdbarch) == 32)
-	gdb_printf ("\t%10s %10s %10s %10s %s\n",
-		    paddress (gdbarch, start),
-		    paddress (gdbarch, end),
-		    hex_string (end - start),
-		    hex_string (file_ofs),
-		    filename);
-      else
-	gdb_printf ("  %18s %18s %10s %10s %s\n",
-		    paddress (gdbarch, start),
-		    paddress (gdbarch, end),
-		    hex_string (end - start),
-		    hex_string (file_ofs),
-		    filename);
+      ui_out_emit_tuple tuple_emitter (uiout, nullptr);
+      uiout->field_core_addr ("start", gdbarch, start);
+      uiout->field_core_addr ("end", gdbarch, end);
+      uiout->field_string ("size", hex_string (end - start));
+      uiout->field_string ("offset", hex_string (file_ofs));
+      uiout->field_string ("objfile", filename, filenames);
+      uiout->text ("\n");
     }
 }
 

-- 
2.43.0


  parent 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 ` [PATCH v2 1/3] Use ui-out in maintenance_print_user_registers Tom Tromey
2024-03-03 18:43 ` Tom Tromey [this message]
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-2-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).