Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH] [gdb] Improve debug print of gdb_mpz
Date: Thu, 10 Sep 2026 15:47:01 +0200	[thread overview]
Message-ID: <20260910134701.2983889-1-tdevries@suse.de> (raw)

I came across void debug (const gdb_mpz &val) and tried it out:
...
(gdb) call debug (*this)
-9223372036854775808
...

It occurred to me that showing the hexadecimal value as well could be useful.

Add this:
...
(gdb) call debug (*this)
-9223372036854775808 (-0x8000000000000000)
(gdb)
...
---
 gdb/gmp-utils.c | 4 +++-
 gdb/gmp-utils.h | 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/gmp-utils.c b/gdb/gmp-utils.c
index b7fed9a82d1..814b4972efb 100644
--- a/gdb/gmp-utils.c
+++ b/gdb/gmp-utils.c
@@ -47,7 +47,9 @@ extern void ATTRIBUTE_USED debug (const gdb_mpz &);
 void ATTRIBUTE_USED
 debug (const gdb_mpz &val)
 {
-  gdb_printf (gdb_stdlog, "%s\n", val.str ().c_str ());
+  std::string dec = val.str ();
+  std::string hex = val.hex ();
+  gdb_printf (gdb_stdlog, "%s (%s)\n", dec.c_str (), hex.c_str ());
   gdb_flush (gdb_stdlog);
 }
 
diff --git a/gdb/gmp-utils.h b/gdb/gmp-utils.h
index 965d3b59dd8..04f8d0c83dc 100644
--- a/gdb/gmp-utils.h
+++ b/gdb/gmp-utils.h
@@ -161,6 +161,9 @@ struct gdb_mpz
   /* Return a string containing VAL.  */
   std::string str () const { return gmp_string_printf ("%Zd", m_val); }
 
+  /* As str, but in hex.  */
+  std::string hex () const { return gmp_string_printf ("%#Zx", m_val); }
+
   /* The destructor.  */
   ~gdb_mpz () { mpz_clear (m_val); }
 

base-commit: 0b1fba3c49986faa9e310415e2ff666a7d8d8e6e
-- 
2.51.0


             reply	other threads:[~2026-09-10 13:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 13:47 Tom de Vries [this message]
2026-09-11 13:58 ` 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=20260910134701.2983889-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --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