* [PATCH] [gdb] Improve debug print of gdb_mpz
@ 2026-09-10 13:47 Tom de Vries
2026-09-11 13:58 ` Tom Tromey
0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2026-09-10 13:47 UTC (permalink / raw)
To: gdb-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] [gdb] Improve debug print of gdb_mpz
2026-09-10 13:47 [PATCH] [gdb] Improve debug print of gdb_mpz Tom de Vries
@ 2026-09-11 13:58 ` Tom Tromey
0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2026-09-11 13:58 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> It occurred to me that showing the hexadecimal value as well could be useful.
Ok.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-11 13:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-10 13:47 [PATCH] [gdb] Improve debug print of gdb_mpz Tom de Vries
2026-09-11 13:58 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox