binutils-gdb/gdb/testsuite/gdb.ada
Joel Brobecker 2a62dfa93f (Ada) assigning packed array aggregate with variable as component
Consider a variable "PRA" defined as a packed array of packed
records as follow:

   subtype Int is Integer range 0 .. 7;
   type Packed_Rec is record
      X, Y : Int;
      W    : Integer;
   end record;
   pragma Pack (Packed_Rec);
   type Packed_RecArr is array (Integer range <>) of Packed_Rec;
   pragma Pack (Packed_RecArr);

   PRA : Packed_RecArr (1 .. 3);

Consider also a variable "PR", which is a Packed_Rec record,
declared as follow:

   PR : Packed_Rec := (2, 2, 2);

Trying to assign a new value to PRA using an aggregate expression
where one of the components is our variable PR yields the wrong
result on big-endian machines (e.g. on ppc-linux):

    (gdb) p pra := (pr, (2,2,2), (2,2,2))
    $6 = ((x => 1, y => 0, w => 8), [...]

On the other hand, replacing "pr" by "(2,2,2)" does work.

I tracked the issue down to the bit offset we use to extract
the value of "PR" and copy it inside PRA. in value_assign_to_component,
we have:

  if (gdbarch_bits_big_endian (get_type_arch (value_type (container))))
    move_bits ([target buffer], [bit offset in target buffer],
               [source buffer where PR is stored],
               TYPE_LENGTH (value_type (component)) * TARGET_CHAR_BIT - bits,
               bits, 1);

The issue is with the third-to-last argument, which provides the bit
offset where the value of PR is stored relative to its start address,
and therefore the bit offset relative to the start of the source
buffer passed as the previous argument.

In our case, component is a 38bit packed record whose TYPE_LENGTH
is 5 bytes, so the bit-offset that gets calculated is 2 (bits).
However, that formula only really applies to scalars, whereas
in our case, we have a record (struct). The offset in the non-scalar
case should be zero.

gdb/ChangeLog:

        * ada-lang.c (value_assign_to_component): In the case of
        big-endian targets, extract the bits of the given VAL
        using an src_offset of zero if container is not a scalar.

gdb/testsuite/ChangeLog:

        * gdb.ada/packed_array_assign: New testcase.
2018-09-08 17:44:36 -04:00
..
access_tagged_param
access_to_packed_array
addr_arith
aliased_array
arr_acc_idx_w_gap
arr_arr
arr_enum_idx_w_gap
array_bounds
array_char_idx
array_of_variable_length
array_ptr_renaming
array_return
array_subscript_addr
arraydim
arrayidx
arrayparam
arrayptr
assign_arr
atomic_enum
attr_ref_and_charlit
bad-task-bp-keyword
bp_c_mixed_case
bp_enum_homonym
bp_fun_addr inadvertent language switch during breakpoint_re_set_one 2018-06-01 09:36:59 -07:00
bp_inlined_func
bp_on_var
bp_range_type
bp_reset
byte_packed_arr
call_pn
catch_assert_if
catch_ex
char_enum
char_param
complete
cond_lang
convvar_comp
disc_arr_bound
dot_all
dyn_arrayidx
dyn_loc
dyn_stride
enum_idx_packed
excep_handle
exec_changed
expr_delims
exprs
fin_fun_out
fixed_cmp
fixed_points
float_param
formatted_ref
frame_args
fullname_bp
fun_addr
fun_in_declare
fun_overload_menu
fun_renaming
funcall_char
funcall_param
funcall_ptr
funcall_ref
homonym
info_addr_mixed_case
info_exc
info_locals_renaming
int_deref
interface
iwide
lang_switch
maint_with_ada
mi_catch_assert (Ada/MI) Add testcase for mi catch assert with condition 2018-01-31 13:42:30 +01:00
mi_catch_ex
mi_catch_ex_hand (Ada) Add gdb-mi support for stopping at start of exception handler. 2018-01-31 13:42:30 +01:00
mi_dyn_arr
mi_ex_cond
mi_exc_info
mi_interface
mi_task_arg
mi_task_info
mi_var_array
minsyms
mod_from_name
n_arr_bound
nested
notcplusplus problem looking up some symbols when they have a linkage name 2018-03-27 09:57:16 -04:00
null_array
null_record
O2_float_param
operator_bp
optim_drec
out_of_line_in_inlined
packed_array
packed_array_assign (Ada) assigning packed array aggregate with variable as component 2018-09-08 17:44:36 -04:00
packed_tagged
pckd_arr_ren
pckd_neg
pkd_arr_elem
pp-rec-component
print_chars
ptr_typedef
ptype_field
ptype_tagged_param
py_range
rdv_wait
rec_comp
rec_return
ref_param
ref_tick_size
rename_subscript_param
repeat_dyn
same_component_name
same_enum
scoped_watch
set_pckd_arr_elt
set_wstr
small_reg_param
start
str_binop_equal
str_ref_cmp
str_uninit
sym_print_name
taft_type
tagged
tagged_access
tagged_not_init
task_bp
task_switch_in_core
tasks
tick_last_segv
tick_length_array_enum_idx
type_coercion
unc_arr_ptr_in_var_rec
uninitialized_vars
var_arr_attrs
var_arr_typedef
var_rec_arr
variant_record_packed_array
varsize_limit set varsize-limit: New GDB setting for maximum dynamic object size 2018-03-27 10:17:45 -04:00
watch_arg
whatis_array_val
widewide
win_fu_syms
access_tagged_param.exp
access_to_packed_array.exp
addr_arith.exp
aliased_array.exp
arr_acc_idx_w_gap.exp
arr_arr.exp
arr_enum_idx_w_gap.exp
array_bounds.exp
array_char_idx.exp
array_of_variable_length.exp
array_ptr_renaming.exp
array_return.exp
array_subscript_addr.exp
arraydim.exp
arrayidx.exp
arrayparam.exp
arrayptr.exp
assign_1.exp
assign_arr.exp
atomic_enum.exp
attr_ref_and_charlit.exp
bad-task-bp-keyword.exp
boolean_expr.exp
bp_c_mixed_case.exp
bp_enum_homonym.exp
bp_fun_addr.exp inadvertent language switch during breakpoint_re_set_one 2018-06-01 09:36:59 -07:00
bp_inlined_func.exp [gdb/testsuite/ada] Fix number-of-bp test in bp_inlined_func.exp 2018-06-18 09:04:38 +02:00
bp_on_var.exp
bp_range_type.exp
bp_reset.exp
byte_packed_arr.exp
call_pn.exp
catch_assert_if.exp
catch_ex.exp
char_enum.exp
char_param.exp
complete.exp
cond_lang.exp
convvar_comp.exp
disc_arr_bound.exp
dot_all.exp
dyn_arrayidx.exp
dyn_loc.exp
dyn_stride.exp
enum_idx_packed.exp
excep_handle.exp
exec_changed.exp Testsuite: fully migrate to use_gdb_stub convenience func 2018-03-23 10:38:23 +01:00
expr_delims.exp
exprs.exp
fin_fun_out.exp
fixed_cmp.exp
fixed_points.exp
float_param.exp
formatted_ref.exp
frame_args.exp
fullname_bp.exp
fun_addr.exp
fun_in_declare.exp
fun_overload_menu.exp
fun_renaming.exp
funcall_char.exp
funcall_param.exp
funcall_ptr.exp
funcall_ref.exp
homonym.exp
info_addr_mixed_case.exp
info_exc.exp
info_locals_renaming.exp
info_types.c
info_types.exp Show line numbers in output for "info var/func/type" 2018-04-13 19:26:05 +02:00
int_deref.exp
interface.exp
iwide.exp
lang_switch.exp
maint_with_ada.exp problem looking up some symbols when they have a linkage name 2018-03-27 09:57:16 -04:00
mi_catch_assert.exp (Ada/MI) Add testcase for mi catch assert with condition 2018-01-31 13:42:30 +01:00
mi_catch_ex_hand.exp (Ada) Add gdb-mi support for stopping at start of exception handler. 2018-01-31 13:42:30 +01:00
mi_catch_ex.exp
mi_dyn_arr.exp
mi_ex_cond.exp
mi_exc_info.exp
mi_interface.exp
mi_task_arg.exp
mi_task_info.exp
mi_var_array.exp
minsyms.exp
mod_from_name.exp
n_arr_bound.exp
nested.exp
notcplusplus.exp problem looking up some symbols when they have a linkage name 2018-03-27 09:57:16 -04:00
null_array.exp
null_record.exp
O2_float_param.exp
operator_bp.exp
optim_drec.exp
out_of_line_in_inlined.exp
packed_array_assign.exp (Ada) assigning packed array aggregate with variable as component 2018-09-08 17:44:36 -04:00
packed_array.exp
packed_tagged.exp
pckd_arr_ren.exp
pckd_neg.exp
pkd_arr_elem.exp
pp-rec-component.exp
pp-rec-component.py
print_chars.exp
print_pc.exp
ptr_typedef.exp
ptype_arith_binop.exp
ptype_field.exp
ptype_tagged_param.exp
py_range.exp
rdv_wait.exp
rec_comp.exp
rec_return.exp
ref_param.exp
ref_tick_size.exp
rename_subscript_param.exp
repeat_dyn.exp
same_component_name.exp
same_enum.exp
scoped_watch.exp
set_pckd_arr_elt.exp
set_wstr.exp
small_reg_param.exp
start.exp Testsuite: fully migrate to use_gdb_stub convenience func 2018-03-23 10:38:23 +01:00
str_binop_equal.exp
str_ref_cmp.exp
str_uninit.exp
sym_print_name.exp
taft_type.exp
tagged_access.exp
tagged_not_init.exp
tagged.exp
task_bp.exp
task_switch_in_core.exp
tasks.exp
tick_last_segv.exp
tick_length_array_enum_idx.exp
type_coercion.exp
unc_arr_ptr_in_var_rec.exp
uninitialized_vars.exp
var_arr_attrs.exp
var_arr_typedef.exp
var_rec_arr.exp
variant_record_packed_array.exp
varsize_limit.exp set varsize-limit: New GDB setting for maximum dynamic object size 2018-03-27 10:17:45 -04:00
watch_arg.exp
whatis_array_val.exp
widewide.exp
win_fu_syms.exp