Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gcc-patches@sourceware.org, gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 4/6] gdb/gmp-utils: rename gdb_mp{z,q,f}::str to to_string
Date: Mon, 19 Oct 2026 12:58:20 -0400	[thread overview]
Message-ID: <20261019165929.792697-5-simon.marchi@efficios.com> (raw)
In-Reply-To: <20261019165929.792697-1-simon.marchi@efficios.com>

This makes the following patch a bit easier, allowing those objects to
be printed as part of a SELF_CHECK expression.  Rename hex to
to_hex_string, for symmetry.

Change-Id: I65333129d7074a167f19abae63b3b82da7c1b6a7
---
 gdb/ada-typeprint.c  |  2 +-
 gdb/cp-name-parser.c |  2 +-
 gdb/expprint.c       |  3 ++-
 gdb/gdbtypes.c       |  2 +-
 gdb/gmp-utils.c      | 10 +++++-----
 gdb/gmp-utils.h      | 12 +++++++-----
 gdb/typeprint.c      |  2 +-
 gdb/valprint.c       |  2 +-
 8 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index 15045a02f356..eaceac9cc3a6 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -1050,7 +1050,7 @@ ada_print_type (struct type *type0, const char *varstring,
 	      }
 	    else
 	      modulus = 0;
-	    gdb_printf (stream, "mod %s", modulus.str ().c_str ());
+	    gdb_printf (stream, "mod %s", modulus.to_string ().c_str ());
 	  }
 	else
 	  {
diff --git a/gdb/cp-name-parser.c b/gdb/cp-name-parser.c
index fe2ffd61a6c8..0c34942ff678 100644
--- a/gdb/cp-name-parser.c
+++ b/gdb/cp-name-parser.c
@@ -342,7 +342,7 @@ cpname_state::parse_number (const char *p, int len, int parsed_float,
       value += dig;
     }
 
-  std::string printed = value.str ();
+  std::string printed = value.to_string ();
   const char *copy = obstack_strdup (&demangle_info->obstack, printed);
 
   if (long_p == 0)
diff --git a/gdb/expprint.c b/gdb/expprint.c
index 4859d48f6a4e..26f54eed0d78 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -102,7 +102,8 @@ dump_for_expression (struct ui_file *stream, int depth, CORE_ADDR addr)
 void
 dump_for_expression (struct ui_file *stream, int depth, const gdb_mpz &val)
 {
-  gdb_printf (stream, _("%*sConstant: %s\n"), depth, "", val.str ().c_str ());
+  gdb_printf (stream, _("%*sConstant: %s\n"), depth, "",
+	      val.to_string ().c_str ());
 }
 
 void
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index e0c25c58d83b..2db3f7ebe733 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -4881,7 +4881,7 @@ static void
 print_fixed_point_type_info (struct type *type, int spaces)
 {
   gdb_printf ("%*sscaling factor: %s\n", spaces + 2, "",
-	      type->fixed_point_scaling_factor ().str ().c_str ());
+	      type->fixed_point_scaling_factor ().to_string ().c_str ());
 }
 
 static struct obstack dont_print_type_obstack;
diff --git a/gdb/gmp-utils.c b/gdb/gmp-utils.c
index 6438a4615d42..fb9548d2b6ed 100644
--- a/gdb/gmp-utils.c
+++ b/gdb/gmp-utils.c
@@ -47,8 +47,8 @@ extern void ATTRIBUTE_USED debug (const gdb_mpz &);
 void ATTRIBUTE_USED
 debug (const gdb_mpz &val)
 {
-  std::string dec = val.str ();
-  std::string hex = val.hex ();
+  std::string dec = val.to_string ();
+  std::string hex = val.to_hex_string ();
   gdb_printf (gdb_stdlog, "%s (%s)\n", dec.c_str (), hex.c_str ());
   gdb_flush (gdb_stdlog);
 }
@@ -123,11 +123,11 @@ gdb_mpz::export_bits (gdb::array_view<gdb_byte> buf, int endian, bool unsigned_p
       if (mpz_cmp (m_val, lo.m_val) < 0 || mpz_cmp (m_val, hi.m_val) > 0)
 	error (_("Cannot export value %s as %zu-bits %s integer"
 		 " (must be between %s and %s)"),
-	       this->str ().c_str (),
+	       this->to_string ().c_str (),
 	       max_usable_bits,
 	       unsigned_p ? _("unsigned") : _("signed"),
-	       lo.str ().c_str (),
-	       hi.str ().c_str ());
+	       lo.to_string ().c_str (),
+	       hi.to_string ().c_str ());
     }
 
   gdb_mpz truncated = *this;
diff --git a/gdb/gmp-utils.h b/gdb/gmp-utils.h
index 04f8d0c83dc4..92a21457895f 100644
--- a/gdb/gmp-utils.h
+++ b/gdb/gmp-utils.h
@@ -159,10 +159,12 @@ struct gdb_mpz
   }
 
   /* Return a string containing VAL.  */
-  std::string str () const { return gmp_string_printf ("%Zd", m_val); }
+  std::string to_string () const
+  { return gmp_string_printf ("%Zd", m_val); }
 
-  /* As str, but in hex.  */
-  std::string hex () const { return gmp_string_printf ("%#Zx", m_val); }
+  /* As to_string, but in hex.  */
+  std::string to_hex_string () const
+  { return gmp_string_printf ("%#Zx", m_val); }
 
   /* The destructor.  */
   ~gdb_mpz () { mpz_clear (m_val); }
@@ -540,7 +542,7 @@ struct gdb_mpq
   }
 
   /* Return a string representing VAL as "<numerator> / <denominator>".  */
-  std::string str () const { return gmp_string_printf ("%Qd", m_val); }
+  std::string to_string () const { return gmp_string_printf ("%Qd", m_val); }
 
   /* Return VAL rounded to the nearest integer.  */
   gdb_mpz get_rounded () const;
@@ -621,7 +623,7 @@ struct gdb_mpf
 
   /* Convert this value to a string.  FMT is the format to use, and
      should have a single '%' substitution.  */
-  std::string str (const char *fmt) const
+  std::string to_string (const char *fmt) const
   { return gmp_string_printf (fmt, m_val); }
 
   /* The destructor.  */
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index a23b5b54c0ab..2fd023bce60e 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -619,7 +619,7 @@ print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
 void
 print_type_fixed_point (struct type *type, struct ui_file *stream)
 {
-  std::string small_img = type->fixed_point_scaling_factor ().str ();
+  std::string small_img = type->fixed_point_scaling_factor ().to_string ();
 
   gdb_printf (stream, "%s-byte fixed point (small = %s)",
 	      pulongest (type->length ()), small_img.c_str ());
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 7e41943f66fa..affddc387de9 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -876,7 +876,7 @@ generic_val_print_fixed_point (struct value *val, struct ui_file *stream,
 			  type->fixed_point_scaling_factor ());
 
       const char *fmt = type->length () < 4 ? "%.11Fg" : "%.17Fg";
-      std::string str = f.str (fmt);
+      std::string str = f.to_string (fmt);
       gdb_printf (stream, "%s", str.c_str ());
     }
 }
-- 
2.56.0


  parent reply	other threads:[~2026-10-19 17:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19 16:58 [PATCH 0/6] Make SELF_CHECK print operands of comparisons Simon Marchi
2026-10-19 16:58 ` [PATCH 1/6] gdb/unittests: catch gdb_exception_error in scoped_mmap test Simon Marchi
2026-10-19 16:58 ` [PATCH 2/6] gdbsupport/selftest: print expression when selftest fails and re-format Simon Marchi
2026-10-19 16:58 ` [PATCH 3/6] include/diagnostics.h: add DIAGNOSTIC_IGNORE_PARENTHESES Simon Marchi
2026-10-19 16:58 ` Simon Marchi [this message]
2026-10-19 16:58 ` [PATCH 5/6] gdbsupport/selftest: print operand values when a SELF_CHECK fails Simon Marchi
2026-10-27 14:13   ` Tom Tromey
2026-10-27 17:06     ` Simon Marchi
2026-10-19 16:58 ` [PATCH 6/6] gdb: remove manual printing of values in some selftests Simon Marchi

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=20261019165929.792697-5-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gcc-patches@sourceware.org \
    --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