This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PR debug/7081: emit DW_TAG_class_type and DW_TAG_interface_type
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 29 Nov 2007 16:29:09 -0200
- Subject: PR debug/7081: emit DW_TAG_class_type and DW_TAG_interface_type
We've long output C++ classes and Java classes and interfaces as
DW_TAG_structure_type. This patch fixes it, with a different approach
from the one proposed at
http://gcc.gnu.org/ml/gcc-patches/2003-06/msg01748.html
Instead of moving the declared-as-class bit from C++ into common
trees, it introduces a langhook to let the language decide what is a
class, what is an interface and what is a structure.
I went ahead and implemented the langhooks for C++ and Java, and
verified that the generated debug information is correct.
I'm a bit concerned about debug information consumers that don't
support the new tags, particularly DW_TAG_interface_type, introduced
in Dwarf 3, but I don't have a solution for this. It doesn't seem
like Dwarf 3 has made any backward-compatibility provisions for this
case.
Should we perhaps introduce a command-line flag to disable Dwarf
3-only debug information?
I'm also a bit confused as to how to handle Java arrays. They're
still output as DW_TAG_structure_types, but I wonder if using some
other representation would be more appropriate.
Bootstrapped on x86_64-linux-gnu. Is this ok for 4.4, when 4.3
branches off? How about for 4.3?
for gcc/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR debug/7081
* dwarf2out.c (dwarf_tag_name): Synchronize with dwarf2.h.
(is_type_die): Cover interface types.
(class_or_namespace_scope_p): Cover interface and class types.
(record_type_tag): New.
(gen_inlined_structure_type_die): Use it.
(gen_struct_or_union_type_die): Likewise.
(prune_unused_types_walk): Cover interface types.
* langhooks.h (classify_record): New enum.
(classify_record): New member in struct langhooks_for_types.
* langhooks-def.h (LANG_HOOKS_CLASSIFY_RECORD): New.
(LANGHOOKS_FOR_TYPES_INITIALIZER): Adjust.
for gcc/cp/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR debug/7081
* cp-lang.c (cp_classify_record): New.
(LANG_HOOKS_CLASSIFY_RECORD): Override.
for gcc/java/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR debug/7081
* lang.c (java_classify_record): New.
(LANG_HOOKS_CLASSIFY_RECORD): Override.
Index: gcc/java/lang.c
===================================================================
--- gcc/java/lang.c.orig 2007-11-29 04:13:56.000000000 -0200
+++ gcc/java/lang.c 2007-11-29 16:18:23.000000000 -0200
@@ -64,6 +64,8 @@ static bool java_decl_ok_for_sibcall (co
static tree java_get_callee_fndecl (const_tree);
static void java_clear_binding_stack (void);
+static enum classify_record java_classify_record (tree type);
+
#ifndef TARGET_OBJECT_SUFFIX
# define TARGET_OBJECT_SUFFIX ".o"
#endif
@@ -180,6 +182,8 @@ struct language_function GTY(())
#define LANG_HOOKS_TYPE_FOR_MODE java_type_for_mode
#undef LANG_HOOKS_TYPE_FOR_SIZE
#define LANG_HOOKS_TYPE_FOR_SIZE java_type_for_size
+#undef LANG_HOOKS_CLASSIFY_RECORD
+#define LANG_HOOKS_CLASSIFY_RECORD java_classify_record
#undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN
#define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN java_dump_tree
@@ -955,4 +959,16 @@ java_clear_binding_stack (void)
poplevel (0, 0, 0);
}
+static enum classify_record
+java_classify_record (tree type)
+{
+ if (! CLASS_P (type))
+ return RECORD_IS_STRUCT;
+
+ if (CLASS_INTERFACE (TYPE_NAME (type)))
+ return RECORD_IS_INTERFACE;
+
+ return RECORD_IS_CLASS;
+}
+
#include "gt-java-lang.h"
Index: gcc/cp/cp-lang.c
===================================================================
--- gcc/cp/cp-lang.c.orig 2007-11-29 04:13:56.000000000 -0200
+++ gcc/cp/cp-lang.c 2007-11-29 16:18:23.000000000 -0200
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3.
enum c_language_kind c_language = clk_cxx;
static void cp_init_ts (void);
static const char * cxx_dwarf_name (tree t, int verbosity);
+static enum classify_record cp_classify_record (tree type);
/* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h;
consequently, there should be very few hooks below. */
@@ -44,6 +45,8 @@ static const char * cxx_dwarf_name (tree
#define LANG_HOOKS_NAME "GNU C++"
#undef LANG_HOOKS_INIT
#define LANG_HOOKS_INIT cxx_init
+#undef LANG_HOOKS_CLASSIFY_RECORD
+#define LANG_HOOKS_CLASSIFY_RECORD cp_classify_record
#undef LANG_HOOKS_GENERIC_TYPE_P
#define LANG_HOOKS_GENERIC_TYPE_P class_tmpl_impl_spec_p
#undef LANG_HOOKS_DECL_PRINTABLE_NAME
@@ -153,6 +156,15 @@ cxx_dwarf_name (tree t, int verbosity)
return cxx_printable_name (t, verbosity);
}
+static enum classify_record
+cp_classify_record (tree type)
+{
+ if (CLASSTYPE_DECLARED_CLASS (type))
+ return RECORD_IS_CLASS;
+
+ return RECORD_IS_STRUCT;
+}
+
void
finish_file (void)
{
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c.orig 2007-11-29 16:18:22.000000000 -0200
+++ gcc/dwarf2out.c 2007-11-29 16:18:23.000000000 -0200
@@ -4561,8 +4561,6 @@ dwarf_tag_name (unsigned int tag)
return "DW_TAG_namelist";
case DW_TAG_namelist_item:
return "DW_TAG_namelist_item";
- case DW_TAG_namespace:
- return "DW_TAG_namespace";
case DW_TAG_packed_type:
return "DW_TAG_packed_type";
case DW_TAG_subprogram:
@@ -4581,8 +4579,26 @@ dwarf_tag_name (unsigned int tag)
return "DW_TAG_variable";
case DW_TAG_volatile_type:
return "DW_TAG_volatile_type";
+ case DW_TAG_dwarf_procedure:
+ return "DW_TAG_dwarf_procedure";
+ case DW_TAG_restrict_type:
+ return "DW_TAG_restrict_type";
+ case DW_TAG_interface_type:
+ return "DW_TAG_interface_type";
+ case DW_TAG_namespace:
+ return "DW_TAG_namespace";
case DW_TAG_imported_module:
return "DW_TAG_imported_module";
+ case DW_TAG_unspecified_type:
+ return "DW_TAG_unspecified_type";
+ case DW_TAG_partial_unit:
+ return "DW_TAG_partial_unit";
+ case DW_TAG_imported_unit:
+ return "DW_TAG_imported_unit";
+ case DW_TAG_condition:
+ return "DW_TAG_condition";
+ case DW_TAG_shared_type:
+ return "DW_TAG_shared_type";
case DW_TAG_MIPS_loop:
return "DW_TAG_MIPS_loop";
case DW_TAG_format_label:
@@ -6300,6 +6316,7 @@ is_type_die (dw_die_ref die)
{
case DW_TAG_array_type:
case DW_TAG_class_type:
+ case DW_TAG_interface_type:
case DW_TAG_enumeration_type:
case DW_TAG_pointer_type:
case DW_TAG_reference_type:
@@ -11474,6 +11491,8 @@ class_or_namespace_scope_p (dw_die_ref c
{
return (context_die
&& (context_die->die_tag == DW_TAG_structure_type
+ || context_die->die_tag == DW_TAG_class_type
+ || context_die->die_tag == DW_TAG_interface_type
|| context_die->die_tag == DW_TAG_union_type
|| context_die->die_tag == DW_TAG_namespace));
}
@@ -11724,12 +11743,36 @@ gen_inlined_enumeration_type_die (tree t
add_abstract_origin_attribute (type_die, type);
}
+/* Determine what tag to use for a record type. */
+
+static enum dwarf_tag
+record_type_tag (tree type)
+{
+ if (! lang_hooks.types.classify_record)
+ return DW_TAG_structure_type;
+
+ switch (lang_hooks.types.classify_record (type))
+ {
+ case RECORD_IS_STRUCT:
+ return DW_TAG_structure_type;
+
+ case RECORD_IS_CLASS:
+ return DW_TAG_class_type;
+
+ case RECORD_IS_INTERFACE:
+ return DW_TAG_interface_type;
+
+ default:
+ gcc_unreachable ();
+ }
+}
+
/* Generate a DIE to represent an inlined instance of a structure type. */
static void
gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
{
- dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
+ dw_die_ref type_die = new_die (record_type_tag (type), context_die, type);
/* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
be incomplete and such types are not marked. */
@@ -12930,7 +12973,7 @@ gen_struct_or_union_type_die (tree type,
dw_die_ref old_die = type_die;
type_die = new_die (TREE_CODE (type) == RECORD_TYPE
- ? DW_TAG_structure_type : DW_TAG_union_type,
+ ? record_type_tag (type) : DW_TAG_union_type,
scope_die, type);
equate_type_number_to_die (type, type_die);
if (old_die)
@@ -14593,6 +14636,7 @@ prune_unused_types_walk (dw_die_ref die)
case DW_TAG_structure_type:
case DW_TAG_union_type:
case DW_TAG_class_type:
+ case DW_TAG_interface_type:
case DW_TAG_friend:
case DW_TAG_variant_part:
case DW_TAG_enumeration_type:
Index: gcc/langhooks.h
===================================================================
--- gcc/langhooks.h.orig 2007-11-29 04:13:56.000000000 -0200
+++ gcc/langhooks.h 2007-11-29 16:18:23.000000000 -0200
@@ -31,6 +31,9 @@ struct gimplify_omp_ctx;
/* A print hook for print_tree (). */
typedef void (*lang_print_tree_hook) (FILE *, tree, int indent);
+enum classify_record
+ { RECORD_IS_STRUCT, RECORD_IS_CLASS, RECORD_IS_INTERFACE };
+
/* The following hooks are documented in langhooks.c. Must not be
NULL. */
@@ -89,6 +92,11 @@ struct lang_hooks_for_types
language-specific processing is required. */
tree (*make_type) (enum tree_code);
+ /* Return what kind of RECORD_TYPE this is, mainly for purposes of
+ debug information. If not defined, record types are assumed to
+ be structures. */
+ enum classify_record (*classify_record) (tree);
+
/* Given MODE and UNSIGNEDP, return a suitable type-tree with that
mode. */
tree (*type_for_mode) (enum machine_mode, int);
Index: gcc/langhooks-def.h
===================================================================
--- gcc/langhooks-def.h.orig 2007-11-29 04:13:56.000000000 -0200
+++ gcc/langhooks-def.h 2007-11-29 16:18:23.000000000 -0200
@@ -172,6 +172,7 @@ extern tree lhd_make_node (enum tree_cod
/* Types hooks. There are no reasonable defaults for most of them,
so we create a compile-time error instead. */
#define LANG_HOOKS_MAKE_TYPE lhd_make_node
+#define LANG_HOOKS_CLASSIFY_RECORD NULL
#define LANG_HOOKS_INCOMPLETE_TYPE_ERROR lhd_incomplete_type_error
#define LANG_HOOKS_GENERIC_TYPE_P hook_bool_const_tree_false
#define LANG_HOOKS_TYPE_PROMOTES_TO lhd_type_promotes_to
@@ -184,6 +185,7 @@ extern tree lhd_make_node (enum tree_cod
#define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
LANG_HOOKS_MAKE_TYPE, \
+ LANG_HOOKS_CLASSIFY_RECORD, \
LANG_HOOKS_TYPE_FOR_MODE, \
LANG_HOOKS_TYPE_FOR_SIZE, \
LANG_HOOKS_GENERIC_TYPE_P, \
--
Alexandre Oliva http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member http://www.fsfla.org/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}