Fix crash in value_print_array_elements

A user noticed that gdb would crash when printing a packed array after
doing "set lang c".  Packed arrays don't exist in C, but it's
occasionally useful to print things in C mode when working in a non-C
language -- this lets you see under the hood a little bit.

The bug here is that generic value printing does not handle packed
arrays at all.  This patch fixes the bug by introducing a new function
to extract a value from a bit offset and width.

The new function includes a hack to avoid problems with some existing
test cases when using -fgnat-encodings=all.  Cleaning up this code
looked difficult, and since "all" is effectively deprecated, I thought
it made sense to simply work around the problems.
This commit is contained in:
Tom Tromey
2022-09-27 12:53:25 -06:00
parent 6c849804cf
commit e379f6521a
4 changed files with 126 additions and 7 deletions

View File

@ -599,6 +599,12 @@ extern bool value_contents_eq (const struct value *val1, LONGEST offset1,
const struct value *val2, LONGEST offset2,
LONGEST length);
/* An overload of value_contents_eq that compares the entirety of both
values. */
extern bool value_contents_eq (const struct value *val1,
const struct value *val2);
/* Read LENGTH addressable memory units starting at MEMADDR into BUFFER,
which is (or will be copied to) VAL's contents buffer offset by
BIT_OFFSET bits. Marks value contents ranges as unavailable if
@ -687,6 +693,21 @@ extern struct value *value_from_history_ref (const char *, const char **);
extern struct value *value_from_component (struct value *, struct type *,
LONGEST);
/* Create a new value by extracting it from WHOLE. TYPE is the type
of the new value. BIT_OFFSET and BIT_LENGTH describe the offset
and field width of the value to extract from WHOLE -- BIT_LENGTH
may differ from TYPE's length in the case where WHOLE's type is
packed.
When the value does come from a non-byte-aligned offset or field
width, it will be marked non_lval. */
extern struct value *value_from_component_bitsize (struct value *whole,
struct type *type,
LONGEST bit_offset,
LONGEST bit_length);
extern struct value *value_at (struct type *type, CORE_ADDR addr);
extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);