Patchwork Emit DW_AT_artificial for types

login
register
mail settings
Submitter Eric Botcazou
Date April 10, 2011, 10:26 a.m.
Message ID <201104101226.14527.ebotcazou@adacore.com>
Download mbox | patch
Permalink /patch/90504/
State New
Headers show

Comments

Eric Botcazou - April 10, 2011, 10:26 a.m.
Hi,

as permitted by the DWARF-[234] standards, this patch makes the compiler emit 
the DW_AT_artificial attribute for compiler-generated types; there are a lot 
of them in Ada.  GDB doesn't use it (yet), but other debuggers do use it to 
speed up type lookups.

Tested on i586-suse-linux, OK for the mainline?


2011-04-10  Eric Botcazou  <ebotcazou@adacore.com>
            Olivier Hainque  <hainque@adacore.com>
            Nicolas Setton  <setton@adacore.com>

	* tree.h (TYPE_ARTIFICIAL): New flag.
	* dwarf2out.c (modified_type_die): Add a DW_AT_artificial attribute to
	the DIE of the type if it is artificial.
	(gen_array_type_die): Likewise.
	(gen_enumeration_type_die): Likewise.
	(gen_struct_or_union_type_die): Likewise.
ada/
	* gcc-interface/utils.c (record_builtin_type): Set TYPE_ARTIFICIAL on
	the type according to the ARTIFICIAL_P parameter.
	(create_type_decl): Likewise.
	(create_type_stub_decl): Set TYPE_ARTIFICIAL on the type to 1.


2011-04-10  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/specs/debug1.ads: New test.

Patch

Index: tree.h
===================================================================
--- tree.h	(revision 172224)
+++ tree.h	(working copy)
@@ -631,6 +631,9 @@  struct GTY(()) tree_common {
            all expressions
            all decls
 
+       TYPE_ARTIFICIAL in
+           all types
+
    default_def_flag:
 
        TYPE_VECTOR_OPAQUE in
@@ -1175,6 +1178,9 @@  extern void omp_clause_range_check_faile
    emitted.  */
 #define TREE_NO_WARNING(NODE) ((NODE)->base.nowarning_flag)
 
+/* Used to indicate that this TYPE represents a compiler-generated entity.  */
+#define TYPE_ARTIFICIAL(NODE) (TYPE_CHECK (NODE)->base.nowarning_flag)
+
 /* In an IDENTIFIER_NODE, this means that assemble_name was called with
    this string as an argument.  */
 #define TREE_SYMBOL_REFERENCED(NODE) \
Index: dwarf2out.c
===================================================================
--- dwarf2out.c	(revision 172224)
+++ dwarf2out.c	(working copy)
@@ -12877,6 +12877,8 @@  modified_type_die (tree type, int is_con
 	name = DECL_NAME (name);
       add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
       add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
+      if (TYPE_ARTIFICIAL (type))
+	add_AT_flag (mod_type_die, DW_AT_artificial, 1);
     }
   /* This probably indicates a bug.  */
   else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
@@ -18234,6 +18236,8 @@  gen_array_type_die (tree type, dw_die_re
   array_die = new_die (DW_TAG_array_type, scope_die, type);
   add_name_attribute (array_die, type_tag (type));
   add_gnat_descriptive_type_attribute (array_die, type, context_die);
+  if (TYPE_ARTIFICIAL (type))
+    add_AT_flag (array_die, DW_AT_artificial, 1);
   equate_type_number_to_die (type, array_die);
 
   if (TREE_CODE (type) == VECTOR_TYPE)
@@ -18537,6 +18541,8 @@  gen_enumeration_type_die (tree type, dw_
       equate_type_number_to_die (type, type_die);
       add_name_attribute (type_die, type_tag (type));
       add_gnat_descriptive_type_attribute (type_die, type, context_die);
+      if (TYPE_ARTIFICIAL (type))
+	add_AT_flag (type_die, DW_AT_artificial, 1);
       if (dwarf_version >= 4 || !dwarf_strict)
 	{
 	  if (ENUM_IS_SCOPED (type))
@@ -20359,6 +20365,8 @@  gen_struct_or_union_type_die (tree type,
 	{
 	  add_name_attribute (type_die, type_tag (type));
 	  add_gnat_descriptive_type_attribute (type_die, type, context_die);
+	  if (TYPE_ARTIFICIAL (type))
+	    add_AT_flag (type_die, DW_AT_artificial, 1);
 	}
     }
   else
Index: ada/gcc-interface/utils.c
===================================================================
--- ada/gcc-interface/utils.c	(revision 172224)
+++ ada/gcc-interface/utils.c	(working copy)
@@ -612,6 +612,7 @@  record_builtin_type (const char *name, t
   tree type_decl = build_decl (input_location,
 			       TYPE_DECL, get_identifier (name), type);
   DECL_ARTIFICIAL (type_decl) = artificial_p;
+  TYPE_ARTIFICIAL (type) = artificial_p;
   gnat_pushdecl (type_decl, Empty);
 
   if (debug_hooks->type_decl)
@@ -1303,6 +1304,7 @@  create_type_stub_decl (tree type_name, t
   tree type_decl = build_decl (input_location,
 			       TYPE_DECL, type_name, type);
   DECL_ARTIFICIAL (type_decl) = 1;
+  TYPE_ARTIFICIAL (type) = 1;
   return type_decl;
 }
 
@@ -1335,6 +1337,7 @@  create_type_decl (tree type_name, tree t
 			    TYPE_DECL, type_name, type);
 
   DECL_ARTIFICIAL (type_decl) = artificial_p;
+  TYPE_ARTIFICIAL (type) = artificial_p;
 
   /* Add this decl to the current binding level.  */
   gnat_pushdecl (type_decl, gnat_node);