On Mon, Nov 03, 2025 at 09:14:15AM +0000, Yury Khrustalev wrote:
> Lack of DW_AT_bit_stride in a DW_TAG_array_type entry causes GDB to infer
> incorrect element size for vector types. The causes incorrect display of
> SVE predicate variables as well as out of bounds memory access when reading
> contents of SVE predicates from memory in GDB.
>
> We also locate DIE referenced by DW_AT_type and set DW_AT_bit_size 1 in it.
>
> PR debug/121964
>
> gcc/
> * dwarf2out.cc (gen_array_type_die): Add DW_AT_bit_stride attribute
> for array types based on element type bit precision for integer and
> boolean element types.
>
> gcc/testsuite/
> * g++.target/aarch64/dwarf-bit-stride-func.C: New test.
> * g++.target/aarch64/dwarf-bit-stride-pragma.C: New test.
> * g++.target/aarch64/dwarf-bit-stride-pragma-sme.C: New test.
> * g++.target/aarch64/sve/dwarf-bit-stride.C: New test.
> * gcc.target/aarch64/dwarf-bit-stride-func.c: New test.
> * gcc.target/aarch64/dwarf-bit-stride-pragma.c: New test.
> * gcc.target/aarch64/dwarf-bit-stride-pragma-sme.c: New test.
> * gcc.target/aarch64/sve/dwarf-bit-stride.c: New test.
LGTM, except one formatting nit.
> + /* Add bit stride information to boolean vectors of single bits so that
> + elements can be correctly read and displayed by a debugger. */
> + if (VECTOR_BOOLEAN_TYPE_P (type))
> + {
> + enum machine_mode tmode = TYPE_MODE_RAW (type);
> + if (GET_MODE_CLASS (tmode) == MODE_VECTOR_BOOL)
> + {
> + /* Calculate bit-size of element based on mnode. */
> + poly_uint16 bit_size = exact_div (GET_MODE_BITSIZE (tmode),
> + GET_MODE_NUNITS (tmode));
> + /* Set bit stride in the array type DIE. */
> + add_AT_unsigned (array_die, DW_AT_bit_stride, bit_size.coeffs[0]);
> + /* Find DIE corresponding to the element type so that we could
> + add DW_AT_bit_size to it. */
> + dw_die_ref elem_die = get_AT_ref (array_die, DW_AT_type);
> + /* Avoid adding DW_AT_bit_size twice. */
> + if (get_AT (elem_die, DW_AT_bit_size) == NULL)
> + add_AT_unsigned (elem_die, DW_AT_bit_size,
> + TYPE_PRECISION (element_type));
TYPE_PRECISION should be aligned below elem_die on the earlier line,
not just 2 columns to the right of add_AT_unsigned.
Jakub