- To: gcc-patches at gcc dot gnu dot org
- Subject: [PATCH] Namespace support for DWARF2, take 2
- From: Daniel Berlin <dan at cgsoftware dot com>
- Date: Thu, 05 Jul 2001 12:12:18 -0400
This should fix all the problems Jason mentioned.
There should be no way now to cause an abort because of the debug info
level. We just don't output namespace aliases for terse output. We
will force out namespaces if they are necessary to describe where some
variable/etc is (which shouldn't ever happen either, since the things
you can have namespaces for don't get output at -g1, but ...).
I can't easily move the "force out namespaces" code above the switch
statement, since some of the decl's won't get output if we are in
terse mode, and thus, we'd end up with namespaces that refer to
nothing being output.
I could move it to a "force_out_namespaces" function or something, to
prevent the code pasting.
2001-07-05 Daniel Berlin <dan@cgsoftware.com>
* dwarf2out.c (gen_decl_die): Handle namespaces.
(scope_die_for): Handle namespaces.
(dwarf2out_decl): Handle namespaces.
Do not output namespaces if the info level is terse.
(gen_namespace_die): New function.
(gen_decl_die): Handle namespaces.
Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/dwarf2out.c,v
retrieving revision 1.280
diff -c -3 -p -w -B -b -r1.280 dwarf2out.c
*** dwarf2out.c 2001/07/05 02:08:15 1.280
--- dwarf2out.c 2001/07/05 16:07:32
*************** static void gen_tagged_type_instantiatio
*** 3535,3540 ****
--- 3535,3541 ----
static void gen_block_die PARAMS ((tree, dw_die_ref, int));
static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
static int is_redundant_typedef PARAMS ((tree));
+ static void gen_namespace_die PARAMS ((tree, dw_die_ref));
static void gen_decl_die PARAMS ((tree, dw_die_ref));
static unsigned lookup_filename PARAMS ((const char *));
static void init_file_table PARAMS ((void));
*************** dwarf_tag_name (tag)
*** 3807,3812 ****
--- 3808,3815 ----
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:
*************** scope_die_for (t, context_die)
*** 8988,8996 ****
containing_scope = TYPE_CONTEXT (t);
! /* Ignore namespaces for the moment. */
if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
! containing_scope = NULL_TREE;
/* Ignore function type "scopes" from the C frontend. They mean that
a tagged type is local to a parmlist of a function declarator, but
--- 8991,9003 ----
containing_scope = TYPE_CONTEXT (t);
! /* Handle namespaces properly */
if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
! {
! context_die = lookup_decl_die (containing_scope);
! if (!context_die)
! abort();
! }
/* Ignore function type "scopes" from the C frontend. They mean that
a tagged type is local to a parmlist of a function declarator, but
*************** is_redundant_typedef (decl)
*** 10788,10793 ****
--- 10795,10810 ----
return 0;
}
+ static void
+ gen_namespace_die (decl, context_die)
+ register tree decl;
+ register dw_die_ref context_die;
+ {
+ dw_die_ref namespace_die = new_die (DW_TAG_namespace, context_die);
+ add_name_and_src_coords_attributes (namespace_die, decl);
+ equate_decl_number_to_die (decl, namespace_die);
+ }
+
/* Generate Dwarf debug information for a decl described by DECL. */
static void
*************** gen_decl_die (decl, context_die)
*** 10836,10841 ****
--- 10853,10873 ----
/* Otherwise we're emitting the primary DIE for this decl. */
else if (debug_info_level > DINFO_LEVEL_TERSE)
{
+ /* Force out the namespace */
+ if (DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
+ {
+ dw_die_ref newcontext;
+ newcontext = lookup_decl_die (DECL_CONTEXT (decl));
+ if (!newcontext)
+ {
+ gen_decl_die (DECL_CONTEXT (decl), context_die);
+ newcontext = lookup_decl_die (DECL_CONTEXT (decl));
+ if (!newcontext)
+ abort();
+ }
+ context_die = newcontext;
+ }
+
/* Before we describe the FUNCTION_DECL itself, make sure that we
have described its return type. */
gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
*************** gen_decl_die (decl, context_die)
*** 10859,10864 ****
--- 10892,10911 ----
actual typedefs. */
if (debug_info_level <= DINFO_LEVEL_TERSE)
break;
+ /* Force out the namespace. */
+ if (DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
+ {
+ dw_die_ref newcontext;
+ newcontext = lookup_decl_die (DECL_CONTEXT (decl));
+ if (!newcontext)
+ {
+ gen_decl_die (DECL_CONTEXT (decl), context_die);
+ newcontext = lookup_decl_die (DECL_CONTEXT (decl));
+ if (!newcontext)
+ abort();
+ }
+ context_die = newcontext;
+ }
/* In the special case of a TYPE_DECL node representing the
declaration of some type tag, if the given TYPE_DECL is marked as
*************** gen_decl_die (decl, context_die)
*** 10890,10895 ****
--- 10937,10956 ----
variable declarations or definitions. */
if (debug_info_level <= DINFO_LEVEL_TERSE)
break;
+ /* Force out the namespace */
+ if (DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
+ {
+ dw_die_ref newcontext;
+ newcontext = lookup_decl_die (DECL_CONTEXT (decl));
+ if (!newcontext)
+ {
+ gen_decl_die (DECL_CONTEXT (decl), context_die);
+ newcontext = lookup_decl_die (DECL_CONTEXT (decl));
+ if (!newcontext)
+ abort();
+ }
+ context_die = newcontext;
+ }
/* Output any DIEs that are needed to specify the type of this data
object. */
*************** gen_decl_die (decl, context_die)
*** 10917,10922 ****
--- 10978,10997 ----
if (DECL_NAME (decl) != NULL_TREE
|| TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
{
+ /* Force out the namespace */
+ if (DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
+ {
+ dw_die_ref newcontext;
+ newcontext = lookup_decl_die (DECL_CONTEXT (decl));
+ if (!newcontext)
+ {
+ gen_decl_die (DECL_CONTEXT (decl), context_die);
+ newcontext = lookup_decl_die (DECL_CONTEXT (decl));
+ if (!newcontext)
+ abort();
+ }
+ context_die = newcontext;
+ }
gen_type_die (member_declared_type (decl), context_die);
gen_field_die (decl, context_die);
}
*************** gen_decl_die (decl, context_die)
*** 10928,10934 ****
break;
case NAMESPACE_DECL:
! /* Ignore for now. */
break;
default:
--- 11003,11023 ----
break;
case NAMESPACE_DECL:
! /* Force out the namespace */
! if (DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
! {
! dw_die_ref newcontext;
! newcontext = lookup_decl_die (DECL_CONTEXT (decl));
! if (!newcontext)
! {
! gen_decl_die (DECL_CONTEXT (decl), context_die);
! newcontext = lookup_decl_die (DECL_CONTEXT (decl));
! if (!newcontext)
! abort();
! }
! context_die = newcontext;
! }
! gen_namespace_die (decl, context_die);
break;
default:
*************** dwarf2out_decl (decl)
*** 11068,11073 ****
--- 11157,11169 ----
break;
+ case NAMESPACE_DECL:
+ if (debug_info_level <= DINFO_LEVEL_TERSE)
+ return;
+ if (lookup_decl_die (decl) != NULL)
+ return;
+ break;
+
default:
return;
}
--
"I used to work in a fire hydrant factory. You couldn't park
anywhere near the place.
"-Steven Wright