Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Tom Tromey <tom@tromey.com>
Cc: Lancelot SIX <Lancelot.Six@amd.com>,
	Tankut Baris Aktemur <tankutbaris.aktemur@amd.com>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb, amd-dbgapi-target: use PRIu64 and PRIu32
Date: Fri, 3 Jul 2026 20:18:53 +0100	[thread overview]
Message-ID: <b5d88f07-7f6c-4f5b-9f37-517211570e16@palves.net> (raw)
In-Reply-To: <87wlvcgcry.fsf@tromey.com>

On 2026-07-03 19:15, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:
> 
> Pedro> Agreed.  And it's also a portability hazard, like other printf
> Pedro> formats, as you have to match the printf format to the type of
> Pedro> the variable.
> 
> Yeah, I meant to point this out as well.
> 
> For pulongest you really only need to know whether the type is signed;
> and we could easily fix that if we cared to.
> 
> Pedro> (std::cout << ... << ... tends to be unreadable too IMHO, but we don't use that, thankfully).
> 
> I thought about this for ui_file but meh.  It's kind of i18n-unfriendly
> as well.

Yeah, like, very unfriendly, similar to how ui_out is unfriendly, with the message split
over several calls.

BTW, we should look into actually doing i18n, like send the .po files to a translation team.
Maybe we can convince one of the new release managers to integrate the flow into the
release process.  :-)

I think Ubuntu had GDB translations at some point.  Haven't checked in a long while.

> 
> Pedro> {fmt} would be better, but that's either a new external dependency, or 
> Pedro> bump to c++20 for std::format, or c++23 for widely available std::print.
> 
> I looked into this but it is also i18n-unfriendly, since as far as I can
> tell it requires you to either give up gettext or give up any sort of
> format checking.  For printf this isn't an issue because GCC understands
> that _() is "transparent".
> 

Ah, yeah, if you run the format string via gettext, that returns a runtime string, so
we'd need to use std::vformat, which as you say, loses compile-time checking:

 std::vformat (_("Hello, {0}!"), std::make_format_args (name));

But I think we could make it work, with a wrapper, which is what we'd do anyhow to
work with ui_file.  But we make the wrapper a template, which itself does the
format checking at compile time.  Like:

  template<typename... Args>
  void
  gdb_format (std::format_string<Args...> f, Args&&... args)
  {
    std::string s
      = std::vformat (gettext (f.get ()), std::make_format_args (args...));
    gdb_stdout->puts (s.c_str ());
  }

then with:

  gdb_printf ("stopped at {}\n", addr);

the literal "stopped at {}\n" gets bound to the format_string<Args...> parameter.
format_string's ctor parses the literal and checks placeholders against Args..., at compile
time, and a mismatch results in a compile error.  If that compiles successfully, then we
call gettext and use std::vformat without the checking, which we no longer need as it's
already validated when we get there.

Note, written in email client, completely untested.

> Also of course switching to fmt would be a colossal effort.
No doubt.  Could be incremental, though.


  reply	other threads:[~2026-07-03 19:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 14:28 Tankut Baris Aktemur
2026-07-01 15:16 ` Lancelot SIX
2026-07-01 16:56   ` Aktemur, Baris
2026-07-02 20:15   ` Tom Tromey
2026-07-03 12:59     ` Simon Marchi
2026-07-03 13:47     ` Pedro Alves
2026-07-03 18:15       ` Tom Tromey
2026-07-03 19:18         ` Pedro Alves [this message]
2026-07-03 19:22           ` Pedro Alves
2026-07-03 11:03 ` [PATCH v2] gdb, amd-dbgapi-target: use pulongest to print id handles Tankut Baris Aktemur
2026-07-03 11:22   ` Lancelot SIX

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=b5d88f07-7f6c-4f5b-9f37-517211570e16@palves.net \
    --to=pedro@palves.net \
    --cc=Lancelot.Six@amd.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tankutbaris.aktemur@amd.com \
    --cc=tom@tromey.com \
    /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