diff options
author | Pierre-Marie de Rodat <derodat@adacore.com> | 2015-12-17 14:09:45 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2015-12-17 14:09:45 +0000 |
commit | eb59e42800b805e0bcced98ad2383c66a5839acc (patch) | |
tree | 1954e1f36ee22fe1453b3126d1e77a2db664d746 /gcc/ada/gcc-interface/misc.c | |
parent | 986ccd2171a7fd8e7d221c2d0b49aad844da836f (diff) | |
download | gcc-eb59e42800b805e0bcced98ad2383c66a5839acc.zip gcc-eb59e42800b805e0bcced98ad2383c66a5839acc.tar.gz gcc-eb59e42800b805e0bcced98ad2383c66a5839acc.tar.bz2 |
DWARF: add a language hook to override types in debugging information
Many artificial types are introduced by GNAT in order to satisfy
constraints in GCC's internal trees or to generate optimal code. These
hide original types from sources and miss useful information in the
debugging information or add noise to it and make debugging confusing.
This change introduces a new language hook to give a chance to
front-ends to restore the source types in the debugging information.
This change also enhance the array descriptor language hook to handle
array-wide bit/byte stride. Some arrays may contain dynamically-sized
objects. Debuggers need for these a hint to know the size allocated for
each element, hence the need for the array-wide bit/byte stride.
The Ada front-end is enhanced to take advantage of both hooks when
-fgnat-encodings=minimal, in order to keep compatibility with GDB.
gcc/ada/ChangeLog:
* gcc-interface/ada-tree.h (struct lang_type): Rename the t
field as t1 and add a t2 one.
(get_lang_specific): New.
(GET_TYPE_LANG_SPECIFIC): Refactor to use get_lang_specific.
(SET_TYPE_LANG_SPECIFIC): Likewise.
(GET_TYPE_LANG_SPECIFIC2): New macro.
(SET_TYPE_LANG_SPECIFIC2): New macro.
(TYPE_DEBUG_TYPE): New macro.
(SET_TYPE_DEBUG_TYPE): New macro.
* gcc-interface/decl.c (gnat_to_gnu_entity): When
-fgnat-encodings=minimal, set padding types' debug type to the
padded one (i.e. strip ___PAD GNAT encodings) and set
constrained record subtypes's debug type to the base type.
* gcc-interface/misc.c (gnat_print_type): Print debug types.
(gnat_get_debug_type): New.
(gnat_get_array_descr_info): When -fgnat-encodings=minimal, set
a byte stride for arrays that contain a type whose debug type
has variable length.
(LANG_HOOKS_GET_DEBUG_TYPE): Redefine macro to implement the
debug type language hook.
* gcc-interface/utils.c (maybe_pad_type): When
-fgnat-encodings=minimal, set padding types' debug type to the
padded one. Restore XVZ variables creation when
-fgnat-encodings-minimal and use them to hold padding types'
byte size. For library-level padding types, share this variable
across translation units. Tag XVZ variables as artificial.
gcc/ChangeLog:
* langhooks.h (struct lang_hooks_for_types): Add a
get_debug_type field.
* langhooks-def.h (LANG_HOOKS_GET_DEBUG_TYPE): New macro.
(LANG_HOOKS_FOR_TYPES_INITIALIZER): Initialize the
get_debug_type field.
* dwarf2out.h (struct array_descr_info): Add an array-wide
stride field.
* dwarf2out.c (modified_type_die): Invoke the get_debug_type
language hook, process its result instead, if any.
(gen_descr_array_type_die): Add array-wide stride processing.
From-SVN: r231763
Diffstat (limited to 'gcc/ada/gcc-interface/misc.c')
-rw-r--r-- | gcc/ada/gcc-interface/misc.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/gcc/ada/gcc-interface/misc.c b/gcc/ada/gcc-interface/misc.c index ef0fe3f..e9df63c 100644 --- a/gcc/ada/gcc-interface/misc.c +++ b/gcc/ada/gcc-interface/misc.c @@ -524,6 +524,10 @@ gnat_print_type (FILE *file, tree node, int indent) default: break; } + + if (TYPE_DEBUG_TYPE (node) != NULL_TREE) + print_node_brief (file, "debug type", TYPE_DEBUG_TYPE (node), + indent + 4); } /* Return the name to be printed for DECL. */ @@ -565,6 +569,15 @@ gnat_descriptive_type (const_tree type) return NULL_TREE; } +/* Return the type to used for debugging information instead of TYPE, if any. + NULL_TREE if TYPE is fine. */ + +static tree +gnat_get_debug_type (const_tree type) +{ + return TYPE_DEBUG_TYPE (type); +} + /* Return true if types T1 and T2 are identical for type hashing purposes. Called only after doing all language independent checks. At present, this function is only called when both types are FUNCTION_TYPE. */ @@ -697,6 +710,33 @@ gnat_get_array_descr_info (const_tree type, struct array_descr_info *info) info->element_type = TREE_TYPE (last_dimen); + /* When arrays contain dynamically-sized elements, we usually wrap them in + padding types, or we create constrained types for them. Then, if such + types are stripped in the debugging information output, the debugger needs + a way to know the size that is reserved for each element. This is why we + emit a stride in such situations. */ + if (gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL) + { + tree source_element_type = info->element_type; + + while (1) + { + if (TYPE_DEBUG_TYPE (source_element_type) != NULL_TREE) + source_element_type = TYPE_DEBUG_TYPE (source_element_type); + else if (TYPE_IS_PADDING_P (source_element_type)) + source_element_type + = TREE_TYPE (TYPE_FIELDS (source_element_type)); + else + break; + } + + if (TREE_CODE (TYPE_SIZE_UNIT (source_element_type)) != INTEGER_CST) + { + info->stride = TYPE_SIZE_UNIT (info->element_type); + info->stride_in_bits = false; + } + } + return true; } @@ -947,6 +987,17 @@ gnat_init_ts (void) MARK_TS_TYPED (EXIT_STMT); } +/* Return the lang specific structure attached to NODE. Allocate it (cleared) + if needed. */ + +struct lang_type * +get_lang_specific (tree node) +{ + if (!TYPE_LANG_SPECIFIC (node)) + TYPE_LANG_SPECIFIC (node) = ggc_cleared_alloc<struct lang_type> (); + return TYPE_LANG_SPECIFIC (node); +} + /* Definitions for our language-specific hooks. */ #undef LANG_HOOKS_NAME @@ -999,6 +1050,8 @@ gnat_init_ts (void) #define LANG_HOOKS_GET_SUBRANGE_BOUNDS gnat_get_subrange_bounds #undef LANG_HOOKS_DESCRIPTIVE_TYPE #define LANG_HOOKS_DESCRIPTIVE_TYPE gnat_descriptive_type +#undef LANG_HOOKS_GET_DEBUG_TYPE +#define LANG_HOOKS_GET_DEBUG_TYPE gnat_get_debug_type #undef LANG_HOOKS_ATTRIBUTE_TABLE #define LANG_HOOKS_ATTRIBUTE_TABLE gnat_internal_attribute_table #undef LANG_HOOKS_BUILTIN_FUNCTION |