From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 2/6] gdb: use TARGET_CHAR_BIT more in dwarf2/expr.c
Date: Tue, 12 May 2026 11:07:23 +0100 [thread overview]
Message-ID: <7865aefc9044e187b325f71ed2443f1ccf43c30e.1778579473.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1778579473.git.aburgess@redhat.com>
A later commit in this series touches some code in dwarf2/expr.c that
used "8 * some_byte_count" to convert to a bit count. It seemed
natural to change this to "TARGET_CHAR_BIT * some_byte_count", but
when I started looking I realised there's a lot of places in
dwarf2/expr.c that use "8" instead of "TARGET_CHAR_BIT".
So I split out this commit to change all of the uses of "8" to
"TARGET_CHAR_BIT". I believe everywhere I've changed really is doing
conversions between bits and bytes, so this change is appropriate.
There should be no user visible changes after this commit.
---
gdb/dwarf2/expr.c | 84 ++++++++++++++++++++++++++---------------------
1 file changed, 47 insertions(+), 37 deletions(-)
diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index 38b77f31741..af39ec08385 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -168,24 +168,24 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
from_contents = nullptr;
}
- ULONGEST bits_to_skip = 8 * v->offset ();
+ ULONGEST bits_to_skip = TARGET_CHAR_BIT * v->offset ();
if (v->bitsize ())
{
- bits_to_skip += (8 * v->parent ()->offset ()
+ bits_to_skip += (TARGET_CHAR_BIT * v->parent ()->offset ()
+ v->bitpos ());
if (from != nullptr
&& (type_byte_order (from->type ())
== BFD_ENDIAN_BIG))
{
/* Use the least significant bits of FROM. */
- max_offset = 8 * from->type ()->length ();
+ max_offset = TARGET_CHAR_BIT * from->type ()->length ();
offset = max_offset - v->bitsize ();
}
else
max_offset = v->bitsize ();
}
else
- max_offset = 8 * v->type ()->length ();
+ max_offset = TARGET_CHAR_BIT * v->type ()->length ();
/* Advance to the first non-skipped piece. */
for (i = 0; i < c->pieces.size () && bits_to_skip >= c->pieces[i].size; i++)
@@ -208,7 +208,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
= get_next_frame_sentinel_okay (frame_find_by_id (c->frame_id));
gdbarch *arch = frame_unwind_arch (next_frame);
int gdb_regnum = dwarf_reg_to_regnum_or_error (arch, p->v.regno);
- ULONGEST reg_bits = 8 * register_size (arch, gdb_regnum);
+ ULONGEST reg_bits = TARGET_CHAR_BIT * register_size (arch, gdb_regnum);
bool optim, unavail;
if (p->offset + p->size < reg_bits)
@@ -222,9 +222,11 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
/* If the piece is located in a register, but does not
occupy the entire register, the placement of the piece
within that register is defined by the ABI. */
+ ULONGEST piece_bytes = p->size / TARGET_CHAR_BIT;
bits_to_skip
- += 8 * gdbarch_dwarf2_reg_piece_offset (arch, gdb_regnum,
- p->size / 8);
+ += (TARGET_CHAR_BIT
+ * gdbarch_dwarf2_reg_piece_offset (arch, gdb_regnum,
+ piece_bytes));
}
else if (p->op == DW_OP_bit_piece)
{
@@ -246,8 +248,8 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
{
/* Read mode. */
if (!get_frame_register_bytes (next_frame, gdb_regnum,
- bits_to_skip / 8, buffer,
- &optim, &unavail))
+ bits_to_skip / TARGET_CHAR_BIT,
+ buffer, &optim, &unavail))
{
if (optim)
{
@@ -264,19 +266,20 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
if (!check_optimized)
copy_bitwise (v_contents, offset,
- buffer.data (), bits_to_skip % 8,
+ buffer.data (), bits_to_skip % TARGET_CHAR_BIT,
this_size_bits, bits_big_endian);
}
else
{
/* Write mode. */
- if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0)
+ if (bits_to_skip % TARGET_CHAR_BIT != 0
+ || this_size_bits % TARGET_CHAR_BIT != 0)
{
/* Data is copied non-byte-aligned into the register.
Need some bits from original register value. */
get_frame_register_bytes (next_frame, gdb_regnum,
- bits_to_skip / 8, buffer, &optim,
- &unavail);
+ bits_to_skip / TARGET_CHAR_BIT,
+ buffer, &optim, &unavail);
if (optim)
throw_error (OPTIMIZED_OUT_ERROR,
_("Can't do read-modify-write to "
@@ -289,11 +292,12 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
"is unavailable"));
}
- copy_bitwise (buffer.data (), bits_to_skip % 8,
+ copy_bitwise (buffer.data (), bits_to_skip % TARGET_CHAR_BIT,
from_contents, offset,
this_size_bits, bits_big_endian);
put_frame_register_bytes (next_frame, gdb_regnum,
- bits_to_skip / 8, buffer);
+ bits_to_skip / TARGET_CHAR_BIT,
+ buffer);
}
}
break;
@@ -305,23 +309,27 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
bits_to_skip += p->offset;
- CORE_ADDR start_addr = p->v.mem.addr + bits_to_skip / 8;
+ CORE_ADDR start_addr = (p->v.mem.addr
+ + bits_to_skip / TARGET_CHAR_BIT);
- if (bits_to_skip % 8 == 0 && this_size_bits % 8 == 0
- && offset % 8 == 0)
+ if (bits_to_skip % TARGET_CHAR_BIT == 0
+ && this_size_bits % TARGET_CHAR_BIT == 0
+ && offset % TARGET_CHAR_BIT == 0)
{
/* Everything is byte-aligned; no buffer needed. */
if (from != nullptr)
write_memory_with_notification (start_addr,
(from_contents
- + offset / 8),
- this_size_bits / 8);
+ + offset / TARGET_CHAR_BIT),
+ (this_size_bits
+ / TARGET_CHAR_BIT));
else
read_value_memory (v, offset,
p->v.mem.in_stack_memory,
- p->v.mem.addr + bits_to_skip / 8,
- v_contents + offset / 8,
- this_size_bits / 8);
+ (p->v.mem.addr
+ + bits_to_skip / TARGET_CHAR_BIT),
+ v_contents + offset / TARGET_CHAR_BIT,
+ this_size_bits / TARGET_CHAR_BIT);
break;
}
@@ -333,16 +341,18 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
/* Read mode. */
read_value_memory (v, offset,
p->v.mem.in_stack_memory,
- p->v.mem.addr + bits_to_skip / 8,
+ (p->v.mem.addr
+ + bits_to_skip / TARGET_CHAR_BIT),
buffer.data (), this_size);
copy_bitwise (v_contents, offset,
- buffer.data (), bits_to_skip % 8,
+ buffer.data (), bits_to_skip % TARGET_CHAR_BIT,
this_size_bits, bits_big_endian);
}
else
{
/* Write mode. */
- if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0)
+ if (bits_to_skip % TARGET_CHAR_BIT != 0
+ || this_size_bits % TARGET_CHAR_BIT != 0)
{
if (this_size <= 8)
{
@@ -360,7 +370,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
}
}
- copy_bitwise (buffer.data (), bits_to_skip % 8,
+ copy_bitwise (buffer.data (), bits_to_skip % TARGET_CHAR_BIT,
from_contents, offset,
this_size_bits, bits_big_endian);
write_memory_with_notification (start_addr,
@@ -383,7 +393,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
gdbarch *objfile_gdbarch = c->per_objfile->objfile->arch ();
ULONGEST stack_value_size_bits
- = 8 * p->v.value->type ()->length ();
+ = TARGET_CHAR_BIT * p->v.value->type ()->length ();
/* Use zeroes if piece reaches beyond stack value. */
if (p->offset + p->size > stack_value_size_bits)
@@ -413,7 +423,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
break;
}
- ULONGEST literal_size_bits = 8 * p->v.literal.length;
+ ULONGEST literal_size_bits = TARGET_CHAR_BIT * p->v.literal.length;
size_t n = this_size_bits;
/* Cut off at the end of the implicit value. */
@@ -492,7 +502,7 @@ check_pieced_synthetic_pointer (const value *value, LONGEST bit_offset,
piece_closure *c = (piece_closure *) value->computed_closure ();
int i;
- bit_offset += 8 * value->offset ();
+ bit_offset += TARGET_CHAR_BIT * value->offset ();
if (value->bitsize ())
bit_offset += value->bitpos ();
@@ -537,8 +547,8 @@ indirect_pieced_value (value *value)
if (type->code () != TYPE_CODE_PTR)
return NULL;
- int bit_length = 8 * type->length ();
- LONGEST bit_offset = 8 * value->offset ();
+ int bit_length = TARGET_CHAR_BIT * type->length ();
+ LONGEST bit_offset = TARGET_CHAR_BIT * value->offset ();
if (value->bitsize ())
bit_offset += value->bitpos ();
@@ -720,13 +730,13 @@ dwarf_expr_context::address_type () const
ndx = 2;
else
error (_("Unsupported address size in DWARF expressions: %d bits"),
- 8 * this->m_addr_size);
+ TARGET_CHAR_BIT * this->m_addr_size);
if (types->dw_types[ndx] == NULL)
{
type_allocator alloc (arch);
types->dw_types[ndx]
- = init_integer_type (alloc, 8 * this->m_addr_size,
+ = init_integer_type (alloc, TARGET_CHAR_BIT * this->m_addr_size,
0, "<signed DWARF address type>");
}
@@ -977,7 +987,7 @@ dwarf_expr_context::fetch_result (struct type *type, struct type *subobj_type,
bit_size += piece.size;
/* Complain if the expression is larger than the size of the
outer type. */
- if (bit_size > 8 * type->length ())
+ if (bit_size > TARGET_CHAR_BIT * type->length ())
invalid_synthetic_pointer ();
piece_closure *c
@@ -2235,7 +2245,7 @@ dwarf_expr_context::execute_stack_op (gdb::array_view<const gdb_byte> expr)
/* Record the piece. */
op_ptr = safe_read_uleb128 (op_ptr, op_end, &size);
- add_piece (8 * size, 0, op);
+ add_piece (TARGET_CHAR_BIT * size, 0, op);
/* Pop off the address/regnum, and reset the location
type. */
@@ -2477,7 +2487,7 @@ dwarf_expr_context::execute_stack_op (gdb::array_view<const gdb_byte> expr)
pointer, then make a pieced value. This is ok because we can't
have implicit pointers in contexts where pieces are invalid. */
if (this->m_location == DWARF_VALUE_IMPLICIT_POINTER)
- add_piece (8 * this->m_addr_size, 0, DW_OP_implicit_pointer);
+ add_piece (TARGET_CHAR_BIT * this->m_addr_size, 0, DW_OP_implicit_pointer);
this->m_recursion_depth--;
gdb_assert (this->m_recursion_depth >= 0);
--
2.25.4
next prev parent reply other threads:[~2026-05-12 10:08 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 ` Andrew Burgess [this message]
2026-05-13 15:05 ` [PATCH 2/6] gdb: use TARGET_CHAR_BIT more in dwarf2/expr.c Tom Tromey
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=7865aefc9044e187b325f71ed2443f1ccf43c30e.1778579473.git.aburgess@redhat.com \
--to=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