This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

tweak to DW_TAG_namespace patch


The patch referenced in
<http://gcc.gnu.org/ml/gcc-patches/2002-11/msg00978.html> doesn't, I
think, always put DW_TAG_namespace DIE's in the right context: they
should be children of the comp unit DIE or of other namespace DIEs,
but sometimes that patch puts them in whatever the current local
context happens to be.  (I'm fairly sure; I'm using an earlier version
of the patch with GCC 3.2.3, and I know it has this bug.)

The following patch seems to fix it.  This patch actually applies to
my GCC 3.2.3 version of this patch, so it might need some tweaking to
get it to apply to the current mainline (after the aformentioned patch
has been applied), but I think/hope that doing so should be fairly
straightforward.

I don't subscribe to gcc-patches myself, so please Cc: me on any
replies.  Kealia should have a copyright assignment on file with the
FSF, if this patch is large enough to need it.  (It probably went in
the mail last Friday; there was an earlier GDB-only one for me, but
the one last Friday should cover all FSF software.)

David Carlton
carlton@kealia.com

2003-06-06  David Carlton  <carlton@kealia.com>

	* dwarf2out.c (gen_namespace_die): Call scope_die_for_namespace.
	(scope_die_for_namespace): New.

*** dwarf2out.c-first-patches	2003-06-06 11:16:49.000000000 -0700
--- dwarf2out.c	2003-06-06 13:57:24.000000000 -0700
*************** static void gen_block_die		PARAMS ((tree
*** 3662,3667 ****
--- 3662,3668 ----
  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 dw_die_ref scope_die_for_namespace PARAMS ((tree, dw_die_ref));
  static void gen_decl_die		PARAMS ((tree, dw_die_ref));
  static dw_die_ref force_out_decl	PARAMS ((tree, dw_die_ref));
  static unsigned lookup_filename		PARAMS ((const char *));
*************** gen_namespace_die (decl, context_die)
*** 11462,11468 ****
    if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
      {
        /* Output a real namespace */
!       dw_die_ref namespace_die = new_die (DW_TAG_namespace, context_die, decl);
        /* Anonymous namespaces shouldn't have a DW_AT_name.  */
        if (strncmp (dwarf2_name (decl, 0), "_GLOBAL__N", 10) == 0)
  	add_src_coords_attributes (namespace_die, decl);
--- 11463,11472 ----
    if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
      {
        /* Output a real namespace */
!       dw_die_ref namespace_die
! 	= new_die (DW_TAG_namespace,
! 		   scope_die_for_namespace (decl, context_die),
! 		   decl);
        /* Anonymous namespaces shouldn't have a DW_AT_name.  */
        if (strncmp (dwarf2_name (decl, 0), "_GLOBAL__N", 10) == 0)
  	add_src_coords_attributes (namespace_die, decl);
*************** gen_namespace_die (decl, context_die)
*** 11493,11498 ****
--- 11497,11535 ----
      }
  }
  
+ /* An analogue of scope_die_for, but T should always be a
+    namespace.  */
+ 
+ static dw_die_ref
+ scope_die_for_namespace (t, context_die)
+      tree t;
+      dw_die_ref context_die;
+ {
+   tree containing_scope = TYPE_CONTEXT (t);
+ 
+   /* Handle namespaces properly */
+   if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
+     {
+       dw_die_ref newcontext = lookup_decl_die (containing_scope);
+ 
+       if (!newcontext)
+ 	{
+ 	  gen_decl_die (containing_scope, context_die);
+ 	  newcontext = lookup_decl_die (containing_scope);
+ 	  if (!newcontext)
+ 	    abort();
+ 	}
+ 
+       return newcontext;
+     }
+   else
+     {
+       /* Namespaces should either be children of namespaces or of the
+ 	 comp_unit_die.  */
+       return comp_unit_die;
+     }
+ }
+ 
  /* Generate Dwarf debug information for a decl described by DECL.  */
  
  static void


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]