This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB 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]

[RFA] DWARF-2, static data members


In article <15700.15818.829204.767503@jackfruit.Stanford.EDU>, David
Carlton <carlton@math.Stanford.EDU> writes:

> It seems to me that the safe thing to do would be to modify GDB so
> that it treats members that either are DW_TAG_variable or
> DW_TAG_member + DW_AT_declaration as static data members; that way
> it will be safe both with code compiled by current versions of GCC
> and by code compiled with hypothetical future versions of GCC that
> have this misinterpretation fixed (as well as other compilers out
> there that might do the right thing).

Here's a patch that does that.  I tried to modify GDB's behavior as
little as possible: so it uses the current code for adding non-static
and static data members, but it calls the former if the member is a
DW_TAG_member that isn't a declaration and calls the latter if the
member is either a DW_TAG_member that is a declaration or a
DW_TAG_variable.  (As opposed to the current situation that calls the
former if it's a DW_TAG_member and the latter if it's a
DW_TAG_variable.)

I'm also include a patch to GCC's dwarf2out.c that, I think, gets GCC
to tag static data members with DW_TAG_member instead of
DW_TAG_variable; I've tried compiling and debugging files with this,
and GCC seems to be generating the correct debugging information that
and GDB seems to be handling it appropriately.  I'll try to submit
that patch to the GCC folks once this patch gets accepted for GDB

David Carlton
carlton@math.stanford.edu

2002-08-20  David Carlton  <carlton@math.stanford.edu>

	* dwarf2read.c (dwarf2_add_field): Treat a field that is a
	DW_TAG_member as well as a declaration as being a C++ static data
	member.
	(read_structure_scope): Combine tests for DW_TAG_member and
	DW_TAG_variable.

Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.65
diff -u -p -r1.65 dwarf2read.c
--- dwarf2read.c	20 Aug 2002 18:45:30 -0000	1.65
+++ dwarf2read.c	20 Aug 2002 22:37:07 -0000
@@ -2049,7 +2049,9 @@ dwarf2_add_field (struct field_info *fip
     new_field->virtuality = DW_UNSND (attr);
 
   fp = &new_field->field;
-  if (die->tag == DW_TAG_member)
+
+  /* Data member other than a C++ static data member.  */
+  if (die->tag == DW_TAG_member && ! die_is_declaration (die))
     {
       /* Get type of field.  */
       fp->type = die_type (die, objfile, cu_header);
@@ -2133,12 +2135,14 @@ dwarf2_add_field (struct field_info *fip
 	  fip->non_public_fields = 1;
 	}
     }
-  else if (die->tag == DW_TAG_variable)
+  /* C++ static member.  It should be a DW_TAG_member that is a
+     declaration, but G++ currently incorrectly generates
+     DW_TAG_variable tags.  */
+  else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
     {
       char *physname;
 
-      /* C++ static member.
-	 Get name of field.  */
+      /* Get name of field.  */
       attr = dwarf_attr (die, DW_AT_name);
       if (attr && DW_STRING (attr))
 	fieldname = DW_STRING (attr);
@@ -2503,13 +2507,11 @@ read_structure_scope (struct die_info *d
 
       while (child_die && child_die->tag)
 	{
-	  if (child_die->tag == DW_TAG_member)
-	    {
-	      dwarf2_add_field (&fi, child_die, objfile, cu_header);
-	    }
-	  else if (child_die->tag == DW_TAG_variable)
+	  /* G++ can incorrectly tag static member variables with
+	     DW_TAG_variable.  */
+	  if (child_die->tag == DW_TAG_member
+	      || child_die->tag == DW_TAG_variable)
 	    {
-	      /* C++ static member.  */
 	      dwarf2_add_field (&fi, child_die, objfile, cu_header);
 	    }
 	  else if (child_die->tag == DW_TAG_subprogram)
--- dwarf2out.c.orig	Wed Aug 14 14:05:05 2002
+++ dwarf2out.c	Tue Aug 20 15:08:32 2002
@@ -10460,12 +10460,19 @@ gen_variable_die (decl, context_die)
      dw_die_ref context_die;
 {
   tree origin = decl_ultimate_origin (decl);
-  dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
-
+  dw_die_ref var_die;
   dw_die_ref old_die = lookup_decl_die (decl);
   int declaration = (DECL_EXTERNAL (decl)
 		     || class_scope_p (context_die));
 
+  /* Declarations of C++ static data members within the declaration of
+     their enclosing class should be tagged as DW_TAG_member. */
+  if (class_scope_p (context_die))
+    var_die = new_die (DW_TAG_member, context_die, decl);
+  else
+    var_die = new_die (DW_TAG_variable, context_die, decl);
+
+
   if (origin != NULL)
     add_abstract_origin_attribute (var_die, origin);
 

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