From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 5/6] gdb: remove embedded_offset argument that is always 0
Date: Tue, 12 May 2026 11:07:26 +0100 [thread overview]
Message-ID: <1281d9563073d028c50690fa26bbe165b9c7beff.1778579473.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1778579473.git.aburgess@redhat.com>
For the background and motivation for this patch you should read the
previous commit.
The goal of this commit started as similar to the previous one; rename
the embedded_offset argument to generic_val_print_ref. To do this I
started tracing back which values are passed into this function so I
could make sure the new argument name matched the usage.
But it turns out that the only value that is ever passed to this
function is zero.
I believe that, like the last commit, the embedded_offset is actually
representing the offset of a field within a value. However, in all of
the use cases, the "field" being accessed is the entire value, hence
why we always pass 0, we are asking about the whole value starting
from the very beginning.
Given this, I couldn't bring myself to rename the argument. Let's just
remove it. It turns out that there's a bunch of functions in
valprint.c that take an argument called embedded_offset, which are
always zero.
This commit removes the argument, and updates the code to assume zero.
There should be no user visible changes after this commit.
---
gdb/valprint.c | 50 ++++++++++++++++++--------------------------------
1 file changed, 18 insertions(+), 32 deletions(-)
diff --git a/gdb/valprint.c b/gdb/valprint.c
index ca4a064a7c5..482069fbbaa 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -59,7 +59,6 @@ static void set_output_radix_1 (int, unsigned);
static void val_print_type_code_flags (struct type *type,
struct value *original_value,
- int embedded_offset,
struct ui_file *stream);
/* Start print_max at this value. */
@@ -561,14 +560,13 @@ generic_value_print_ptr (struct value *val, struct ui_file *stream,
static void
print_ref_address (struct type *type, const gdb_byte *address_buffer,
- int embedded_offset, struct ui_file *stream)
+ struct ui_file *stream)
{
struct gdbarch *gdbarch = type->arch ();
if (address_buffer != NULL)
{
- CORE_ADDR address
- = extract_typed_address (address_buffer + embedded_offset, type);
+ CORE_ADDR address = extract_typed_address (address_buffer, type);
gdb_printf (stream, "@");
fputs_styled (paddress (gdbarch, address), address_style.style (),
@@ -598,15 +596,15 @@ get_value_addr_contents (struct value *deref_val)
static void
generic_val_print_ref (struct type *type,
- int embedded_offset, struct ui_file *stream, int recurse,
+ struct ui_file *stream, int recurse,
struct value *original_value,
const struct value_print_options *options)
{
struct type *elttype = check_typedef (type->target_type ());
struct value *deref_val = NULL;
const bool value_is_synthetic
- = original_value->bits_synthetic_pointer (TARGET_CHAR_BIT * embedded_offset,
- TARGET_CHAR_BIT * type->length ());
+ = original_value->bits_synthetic_pointer (0, (TARGET_CHAR_BIT
+ * type->length ()));
const bool must_coerce_ref = ((options->addressprint && value_is_synthetic)
|| options->deref_ref);
const bool type_is_defined = elttype->code () != TYPE_CODE_UNDEF;
@@ -616,14 +614,9 @@ generic_val_print_ref (struct type *type,
{
deref_val = coerce_ref_if_computed (original_value);
- if (deref_val != NULL)
- {
- /* More complicated computed references are not supported. */
- gdb_assert (embedded_offset == 0);
- }
- else
+ if (deref_val == nullptr)
deref_val = value_at (type->target_type (),
- unpack_pointer (type, valaddr + embedded_offset));
+ unpack_pointer (type, valaddr));
}
/* Else, original_value isn't a synthetic reference or we don't have to print
the reference's contents.
@@ -643,7 +636,7 @@ generic_val_print_ref (struct type *type,
? get_value_addr_contents (deref_val)
: valaddr);
- print_ref_address (type, address, embedded_offset, stream);
+ print_ref_address (type, address, stream);
if (options->deref_ref)
gdb_puts (": ", stream);
@@ -747,20 +740,15 @@ generic_val_print_enum_1 (struct type *type, LONGEST val,
/* generic_val_print helper for TYPE_CODE_ENUM. */
static void
-generic_val_print_enum (struct type *type,
- int embedded_offset, struct ui_file *stream,
+generic_val_print_enum (struct type *type, struct ui_file *stream,
struct value *original_value,
const struct value_print_options *options)
{
- LONGEST val;
- struct gdbarch *gdbarch = type->arch ();
- int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
-
gdb_assert (!options->format);
const gdb_byte *valaddr = original_value->contents_for_printing ().data ();
- val = unpack_long (type, valaddr + embedded_offset * unit_size);
+ LONGEST val = unpack_long (type, valaddr);
generic_val_print_enum_1 (type, val, stream);
}
@@ -768,8 +756,7 @@ generic_val_print_enum (struct type *type,
/* generic_val_print helper for TYPE_CODE_FUNC and TYPE_CODE_METHOD. */
static void
-generic_val_print_func (struct type *type,
- int embedded_offset, CORE_ADDR address,
+generic_val_print_func (struct type *type, CORE_ADDR address,
struct ui_file *stream,
struct value *original_value,
const struct value_print_options *options)
@@ -980,7 +967,7 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
case TYPE_CODE_REF:
case TYPE_CODE_RVALUE_REF:
- generic_val_print_ref (type, 0, stream, recurse,
+ generic_val_print_ref (type, stream, recurse,
val, options);
break;
@@ -988,14 +975,14 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
if (options->format)
value_print_scalar_formatted (val, options, 0, stream);
else
- generic_val_print_enum (type, 0, stream, val, options);
+ generic_val_print_enum (type, stream, val, options);
break;
case TYPE_CODE_FLAGS:
if (options->format)
value_print_scalar_formatted (val, options, 0, stream);
else
- val_print_type_code_flags (type, val, 0, stream);
+ val_print_type_code_flags (type, val, stream);
break;
case TYPE_CODE_FUNC:
@@ -1003,7 +990,7 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
if (options->format)
value_print_scalar_formatted (val, options, 0, stream);
else
- generic_val_print_func (type, 0, val->address (), stream,
+ generic_val_print_func (type, val->address (), stream,
val, options);
break;
@@ -1257,10 +1244,9 @@ debug_val (struct value *val)
static void
val_print_type_code_flags (struct type *type, struct value *original_value,
- int embedded_offset, struct ui_file *stream)
+ struct ui_file *stream)
{
- const gdb_byte *valaddr = (original_value->contents_for_printing ().data ()
- + embedded_offset);
+ const gdb_byte *valaddr = (original_value->contents_for_printing ().data ());
ULONGEST val = unpack_long (type, valaddr);
int field, nfields = type->num_fields ();
struct gdbarch *gdbarch = type->arch ();
@@ -2626,7 +2612,7 @@ test_print_flags (gdbarch *arch)
store_unsigned_integer (contents, 4, gdbarch_byte_order (arch), 0xaa);
string_file out;
- val_print_type_code_flags (flags_type, val, 0, &out);
+ val_print_type_code_flags (flags_type, val, &out);
SELF_CHECK (out.string () == "[ A=2 B=1 C=5 ]");
}
--
2.25.4
next prev parent reply other threads:[~2026-05-12 10:10 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
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 ` Andrew Burgess [this message]
2026-05-13 15:27 ` [PATCH 5/6] gdb: remove embedded_offset argument that is always 0 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=1281d9563073d028c50690fa26bbe165b9c7beff.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