Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org>
To: Christian Biesinger <cbiesinger@google.com>
Cc: gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH/committed] sim: rx: cast bfd_vma when printing
Date: Mon, 3 May 2021 16:57:32 -0400	[thread overview]
Message-ID: <YJBjvE8LMXQ8C7TC@vapier> (raw)
In-Reply-To: <CAPTJ0XEPNKNZ-bknVsgvk5Jcrm6ScW11x117Akik6xa_Qr3zQA@mail.gmail.com>

On 03 May 2021 11:20, Christian Biesinger wrote:
> On Sat, May 1, 2021, 15:29 Mike Frysinger wrote:
> > A bit of a hack, but it's what we've been doing so far when printing
> > bfd_vma's since bfd doesn't provide PRI helper types for us to use.
> >
> > --- a/sim/rx/load.c
> > +++ b/sim/rx/load.c
> > @@ -151,7 +151,7 @@ rx_load (bfd *prog, host_callback *callback)
> >         }
> >        if (bfd_bread (buf, size, prog) != size)
> >         {
> > -         fprintf (stderr, "Failed to read %lx bytes\n", size);
> > +         fprintf (stderr, "Failed to read %lx bytes\n", (long) size);
> 
> Wouldn't it be better to use "long long", especially for mingw?

not sure why mingw is special here.  but let's ignore that.

bfd_vma printing is poorly handled in many places in sim when bfd_vma is 64-bit
but the host cpu is 32-bit (i.e. sizeof(long) == 4).  the (long) cast pattern
that i used here for printing is based on those.  i don't think sim is the only
place that does this poorly tbh, it's just what i'm focusing on.

imo picking any type to cast to and copying & pasting that everywhere is a bit
of a losing proposition.  imo we should provide a PRI constant for code to use
as that'll align with other fixed types (e.g. uint64_t).  that makes it obvious
when code is doing it correctly vs the compiler not happening to warn because
the current configuration provides typedefs that align with the hardcoded sizes.
but i don't really have the energy to take on that work.

specifically for the rx_load code, this stuff needs to get deleted entirely and
switched to the existing common/ logic.  which is why i preferred a hacky patch
here rather than diving deeper into the problem.

so you're not wrong, i'm just not investing in code that i know will die :).
-mike

  reply	other threads:[~2021-05-03 20:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-01 20:29 Mike Frysinger via Gdb-patches
2021-05-03 16:20 ` Christian Biesinger via Gdb-patches
2021-05-03 20:57   ` Mike Frysinger via Gdb-patches [this message]
2021-05-03 21:47     ` Christian Biesinger via Gdb-patches
2021-05-04  0:47       ` Mike Frysinger via Gdb-patches
2021-05-04  2:54         ` Mike Frysinger via Gdb-patches
2021-05-04 12:17           ` [PATCH/committed] sim: clean up bfd_vma printing Mike Frysinger via Gdb-patches

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=YJBjvE8LMXQ8C7TC@vapier \
    --to=gdb-patches@sourceware.org \
    --cc=cbiesinger@google.com \
    --cc=vapier@gentoo.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