From: Tom Tromey <tom@tromey.com>
To: Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/6] gdb: use TARGET_CHAR_BIT more in dwarf2/expr.c
Date: Wed, 13 May 2026 09:05:38 -0600 [thread overview]
Message-ID: <87tssbl58d.fsf@tromey.com> (raw)
In-Reply-To: <7865aefc9044e187b325f71ed2443f1ccf43c30e.1778579473.git.aburgess@redhat.com> (Andrew Burgess's message of "Tue, 12 May 2026 11:07:23 +0100")
>>>>> "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.
So here, using '8' (really HOST_CHAR_BIT) seems more appropriate, since
otherwise the wrong number of bits will be manipulated.
I didn't go through all the spots to find which are which. And TBH
unless someone is really porting to such an architecture, it seems a
little pointless, in the sense that there isn't a good way to test this
anyway -- and even if we came up with one through some heroics, would we
really want to bother?
Andrew> - bit_offset += 8 * value->offset ();
Andrew> + bit_offset += TARGET_CHAR_BIT * value->offset ();
Other spots like this do make sense, because the bit offset is a
function of the size of a target byte.
Anyway, despite all this I have no objection to this patch and I even
approve it, with my reasons being that (1) TARGET_CHAR_BIT at least
indicates places that maybe need to be examined should anyone ever do
this work (though searching for "8" does the same); (2) anyway there are
probably already many incorrect uses in the tree; and (3) using a name
is better than "8".
Approved-By: Tom Tromey <tom@tromey.com>
Tom
next prev parent reply other threads:[~2026-05-13 15:06 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 [this message]
2026-05-15 12:00 ` Andrew Burgess
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=87tssbl58d.fsf@tromey.com \
--to=tom@tromey.com \
--cc=aburgess@redhat.com \
--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