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]

[PATCH] Add dwarf2.1 namespace support


Can someone who knows how we represent namespaces and whatnot in the
C++ front end look at this, and make sure i'm not doing something
stupid?

I've tested the patch on things like:

namespace fred
{
	int a;
	int b;
};
namespace bob
{
	int a;
	int b;
};
using namespace bob;
namespace george
{
	namespace george2
	{
		int c;
	};
};

and I get correct info, but real testcases (like pieces of
libstdc++-v3) generate too much info for me to parse. My brain can't
handle it.
Note that the toplev.c change is because if we don't do that, we get
namespace decls as the absolute last thing output.
Doing it that way, instead of generating them when we see something
use them,  would require fixing up the scope of literally
everything in a namespace, which would seem to be a very not fun thing
to implement.

2001-06-28  Daniel Berlin  <dan@cgsoftware.com>

	* toplev.c (check_global_declarations): Don't pass
	NAMESPACE_DECL's to dwarf2out_decl. It will generate the
	namespaces dies automatically as needed.

	* 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.


Index: toplev.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/toplev.c,v
retrieving revision 1.475
diff -c -3 -p -w -B -b -r1.475 toplev.c
*** toplev.c	2001/06/26 19:24:08	1.475
--- toplev.c	2001/06/28 19:21:40
*************** check_global_declarations (vec, len)
*** 2087,2095 ****
--- 2101,2110 ----
  	 and definitions which have not yet been forced out.  */
  
       if (write_symbols == DWARF2_DEBUG
+ 	  && (TREE_CODE (decl) != NAMESPACE_DECL) 
  	  && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
  	dwarf2out_decl (decl);
  #endif
        timevar_pop (TV_SYMOUT);
      }
  }
Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/dwarf2out.c,v
retrieving revision 1.277
diff -c -3 -p -w -B -b -r1.277 dwarf2out.c
*** dwarf2out.c	2001/06/10 13:47:55	1.277
--- dwarf2out.c	2001/06/28 19:21:48
*************** static void gen_tagged_type_instantiatio
*** 3585,3590 ****
--- 3586,3592 ----
  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)
*** 3872,3877 ****
--- 3877,3884 ----
        return "DW_TAG_function_template";
      case DW_TAG_class_template:
        return "DW_TAG_class_template";
+     case DW_TAG_namespace:
+       return "DW_TAG_namespace";
      case DW_TAG_GNU_BINCL:
        return "DW_TAG_GNU_BINCL";
      case DW_TAG_GNU_EINCL:
*************** scope_die_for (t, context_die)
*** 8984,8992 ****
  
    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,8999 ----
  
    containing_scope = TYPE_CONTEXT (t);
  
!   /* Handle namespaces properly */
    if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
!     context_die = lookup_decl_die (containing_scope);
  
    /* Ignore function type "scopes" from the C frontend.  They mean that
       a tagged type is local to a parmlist of a function declarator, but
*************** gen_decl_die (decl, context_die)
*** 10924,10930 ****
        break;
  
      case NAMESPACE_DECL:
!       /* Ignore for now.  */
        break;
  
      default:
--- 10931,10937 ----
        break;
  
      case NAMESPACE_DECL:
!       gen_namespace_die (decl, context_die);
        break;
  
      default:
*************** dwarf2out_add_library_unit_info (filenam
*** 10955,10960 ****
--- 10962,10976 ----
        add_pubname (context_list_decl, unit_die);
      }
  }
+ static
+ void gen_namespace_die (decl, context_die)
+     register tree decl;
+     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);
+ }
  
  /* Write the debugging output for DECL.  */
  
*************** dwarf2out_decl (decl)
*** 10967,10972 ****
--- 10983,11000 ----
    if (TREE_CODE (decl) == ERROR_MARK)
      return;
    
+   if (DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
+     {
+       context_die = lookup_decl_die (DECL_CONTEXT (decl));
+       if (context_die == NULL)
+ 	{
+ 	  dwarf2out_decl (DECL_CONTEXT (decl));
+ 	  context_die = lookup_decl_die (DECL_CONTEXT (decl));
+ 	  if (!context_die) 
+ 	    abort();
+ 	}
+     }
+ 
    /* If this ..._DECL node is marked to be ignored, then ignore it.  */
    if (DECL_IGNORED_P (decl))
      return;
*************** dwarf2out_decl (decl)
*** 11063,11069 ****
  	context_die = NULL;
  
        break;
! 
      default:
        return;
      }
--- 11090,11099 ----
  	context_die = NULL;
  
        break;
!     case NAMESPACE_DECL:
!       if (debug_info_level <= DINFO_LEVEL_TERSE)
! 	  return;
!       break;
      default:
        return;
      }





-- 
"I saw a sign:  "Rest Area 25 Miles".  That's pretty big.  Some
people must be really tired.
"-Steven Wright


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