From: Andrew Burgess <aburgess@redhat.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/6] gdb: use TARGET_CHAR_BIT more in dwarf2/expr.c
Date: Fri, 15 May 2026 13:00:11 +0100 [thread overview]
Message-ID: <87y0hkdgs4.fsf@redhat.com> (raw)
In-Reply-To: <87tssbl58d.fsf@tromey.com>
Tom Tromey <tom@tromey.com> writes:
>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>
> Andrew> A later commit in this series touches some code in dwarf2/expr.c that
> Andrew> used "8 * some_byte_count" to convert to a bit count. It seemed
> Andrew> natural to change this to "TARGET_CHAR_BIT * some_byte_count", but
> Andrew> when I started looking I realised there's a lot of places in
> Andrew> dwarf2/expr.c that use "8" instead of "TARGET_CHAR_BIT".
>
> Andrew> So I split out this commit to change all of the uses of "8" to
> Andrew> "TARGET_CHAR_BIT". I believe everywhere I've changed really is doing
> Andrew> conversions between bits and bytes, so this change is appropriate.
>
> FWIW I think there's a lot more code around using '8' (not your problem
> obviously); but more importantly that TARGET_CHAR_BIT can't really be
> the correct approach to this problem.
>
> For TARGET_CHAR_BIT to work, I think we'd instead have to change all
> these spots to reference some gdbarch (i.e. in addition to its other
> problems, "TARGET" is a misnomer).
>
> Also, I think some places using TARGET_CHAR_BIT incorrectly mix host and
> target side data.
>
> But, luckily, I also tend to think it's a problem that won't ever need
> solving.
>
> Andrew> if (!check_optimized)
> Andrew> copy_bitwise (v_contents, offset,
> Andrew> - buffer.data (), bits_to_skip % 8,
> Andrew> + buffer.data (), bits_to_skip % TARGET_CHAR_BIT,
> Andrew> this_size_bits, bits_big_endian);
>
> In this situation it seems to me that gdb is manipulating host-side data.
Aren't the value contents pulled from the inferior though? And
bits_to_skip and this_size_bits are all from DWARF properties that
describe the inferior's data, so I don't understand why TARGET_CHAR_BIT
wouldn't be correct? I got really confused trying to reason this all
through.
Maybe the 8-bit byte assumption is just baked into GDB too much? In
this case the BUFFER is filled by get_frame_register_bytes. Is this
host bytes? Target bytes? Is the '%' here trying to adjust the
inferior bits_to_skip so we can index into a host byte buffer? Or
express a target bits_to_skip and copy_bitwise will figure out any
conversion? Of course copy_bitwise actually just hard-codes '8'
everywhere, so the question is mostly pointless.
I eventually just decided to drop this patch from the series. There
were just 3 lines in the final patch where I wanted to change from '8'
to 'TARGET_CHAR_BIT', and in that case I think it's much clearer that
TARGET_CHAR_BIT is the correct choice.
This patch started as me factoring out those 3 lines, and then thinking:
I wonder if there are other places that I could update.
But it's now just a distraction from getting the actual fixes into GDB,
so I'd rather just get those merged, and return to this another day.
Thanks for looking at this series. I've now pushed all the other
patches.
Thanks,
Andrew
next prev parent reply other threads:[~2026-05-15 12:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 10:07 [PATCH 0/6] Fix aggregate types, synthetic pointers, and computed locations bug Andrew Burgess
2026-05-12 10:07 ` [PATCH 1/6] gdb: int to bool conversion in valprint.{c,h} Andrew Burgess
2026-05-13 14:48 ` Tom Tromey
2026-05-12 10:07 ` [PATCH 2/6] gdb: use TARGET_CHAR_BIT more in dwarf2/expr.c Andrew Burgess
2026-05-13 15:05 ` Tom Tromey
2026-05-15 12:00 ` Andrew Burgess [this message]
2026-05-15 14:44 ` Tom Tromey
2026-05-12 10:07 ` [PATCH 3/6] gdb: fix coerce_pieced_ref for multi-piece values Andrew Burgess
2026-05-14 18:53 ` Tom Tromey
2026-05-12 10:07 ` [PATCH 4/6] gdb: rename argument in valprint_check_validity Andrew Burgess
2026-05-13 16:23 ` Tom Tromey
2026-05-12 10:07 ` [PATCH 5/6] gdb: remove embedded_offset argument that is always 0 Andrew Burgess
2026-05-13 15:27 ` Tom Tromey
2026-05-12 10:07 ` [PATCH 6/6] gdb: use value::embedded_offset in check_pieced_synthetic_pointer Andrew Burgess
2026-05-14 19:00 ` 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=87y0hkdgs4.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--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