Hi,
this patch makes the compiler generate the DW_AT_endianity attribute in DWARF
3 or above in conjunction with the scalar_storage_order attribute, namely when
the latter attribute specifies the reverse endianness wrt that of the target.
The scalar_storage_order attribute is either on a structure/union type and
specifies that its scalar fields (and arrays thereof in C) are stored in the
specified endianness (other fields are unaffected by the attribute) or on an
array type (including stand-alone in Ada) whose element type is scalar and
specifies that the elements are stored in the specified endianness. Therefore
the patch adds the DW_AT_endianity attribute to the DW_TAG_member DIE of
scalar fields and to the DW_TAG_array_type DIE of array types; this should
cover all the cases for the languages supporting the attribute and means that
the debugger only needs to look at the immediate parent of the scalar type
DIEs to determine the endianness of the scalars.
Tested on x86_64-suse-linux, OK for the mainline?
2015-11-13 Eric Botcazou <ebotca...@adacore.com>
* dwarf2out.c (gen_array_type_die): Add DW_AT_endianity attribute on
an array type with reverse storage order.
(gen_field_die): Likewise on a scalar field if the context has reverse
storage order.
2015-11-13 Eric Botcazou <ebotca...@adacore.com>
* gcc.dg/debug/dwarf2/sso.c: New test.
--
Eric Botcazou
Index: dwarf2out.c
===================================================================
--- dwarf2out.c (revision 230204)
+++ dwarf2out.c (working copy)
@@ -17744,6 +17744,12 @@ gen_array_type_die (tree type, dw_die_re
&& !TYPE_STRING_FLAG (TREE_TYPE (type)))
add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
+ if ((dwarf_version >= 3 || !dwarf_strict)
+ && TREE_CODE (type) == ARRAY_TYPE
+ && TYPE_REVERSE_STORAGE_ORDER (type))
+ add_AT_unsigned (array_die, DW_AT_endianity,
+ BYTES_BIG_ENDIAN ? DW_END_little : DW_END_big);
+
#if 0
/* We default the array ordering. SDB will probably do
the right things even if DW_AT_ordering is not present. It's not even
@@ -20010,6 +20016,13 @@ gen_field_die (tree decl, dw_die_ref con
add_bit_offset_attribute (decl_die, decl);
}
+ if ((dwarf_version >= 3 || !dwarf_strict)
+ && TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl))
+ && !AGGREGATE_TYPE_P (TREE_TYPE (decl))
+ && !VECTOR_TYPE_P (TREE_TYPE (decl)))
+ add_AT_unsigned (decl_die, DW_AT_endianity,
+ BYTES_BIG_ENDIAN ? DW_END_little : DW_END_big);
+
if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
add_data_member_location_attribute (decl_die, decl);
/* { dg-do compile } */
/* { dg-options "-gdwarf-3 -dA" } */
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define REVERSE_SSO __attribute__((scalar_storage_order("big-endian")));
#else
#define REVERSE_SSO __attribute__((scalar_storage_order("little-endian")));
#endif
struct S0 { int i; };
struct S1 { int i; struct S0 s; } REVERSE_SSO;
struct S2 { int a[4]; struct S0 s; } REVERSE_SSO;
struct S0 s0;
struct S1 s1;
struct S2 s2;
/* Verify that we have endianity on 'i' in S1 and the type of 'a' in S2. */
/* { dg-final { scan-assembler-times " DW_AT_endianity" 2 } } */