]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb: resolve dynamic type in one value_cast case
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 18 Nov 2025 03:38:25 +0000 (22:38 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 24 Nov 2025 04:39:53 +0000 (23:39 -0500)
commite5ef00196e3a5e8667b342bc287fc63e31f3db75
treea7e9107acf4aff52d17521dc42ca5e5585280b41
parentc051369369eb0442f73528f38eaa63eea4d72174
gdb: resolve dynamic type in one value_cast case

This particular path for value_cast does not attempt to resolve a
dynamic target type before assigning it to the new value.  Having a
value with a dynamic type that hasn't been resolved causes an assert
later, when printing the value.  For instance, running the added test
without the fix yields:

    (gdb) p (outer_type) g_outer_as_char_array
    $7 = ( /home/smarchi/src/binutils-gdb/gdb/value.c:3111: internal-error: primitive_field: Assertion `type->dyn_prop (DYN_PROP_DATA_LOCATION)->is_constant ()' failed.

This code path is taken when the value being cast has the same size as
the target type, and no earlier more specific rule matched.  Fix it by
adding a call to resolve_dynamic_type before assigning the target type
to the value.

The test exercises this by defining a char array
(`g_outer_as_char_array`) with the same size as `outer_type` in the
DWARF info, then casting it to `outer_type`.  Without the fix, this
triggers the assertion when printing the result.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33575
Change-Id: I547da32bbd24462b779e76bceb6e0a87859188d1
Approved-By: Tom Tromey <tom@tromey.com>
gdb/testsuite/gdb.dwarf2/data-loc-cast.exp
gdb/valops.c