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]

[PATCH] For static data member declarations emit DW_TAG_member instead of DW_TAG_variable (take 2)


On Mon, Apr 06,[1;5B 2009 at 09:44:32AM -0700, Mark Mitchell wrote:
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> > 
> > 2009-04-01  Jakub Jelinek  <jakub@redhat.com>
> > 
> > 	* dwarf2out.c (class_scope_p): New static inline.
> > 	(class_or_namespace_scope_p): Use it.
> > 	(gen_variable_die): Use DW_TAG_member tag for static data member
> > 	declarations instead of DW_TAG_variable.
> 
> Does GDB support this OK?  Does it require a very new GDB?

New GDB isn't needed.  See e.g.:

  else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
    {
      /* C++ static member.  */

      /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
         is a declaration, but all versions of G++ as of this writing
         (so through at least 3.2.1) incorrectly generate
         DW_TAG_variable tags.  */

comment in gdb.

> This patch should have a GCC test-case, verifying that the correct tag
> is emitted.

Here is an updated patch with a testcase:

2009-04-07  Jakub Jelinek  <jakub@redhat.com>

	* dwarf2out.c (class_scope_p): New static inline.
	(class_or_namespace_scope_p): Use it.
	(gen_variable_die): Use DW_TAG_member tag for static data member
	declarations instead of DW_TAG_variable.

	* g++.dg/debug/dwarf2/static-data-member1.C: New test.

--- gcc/dwarf2out.c.jj	2009-04-06 11:47:29.000000000 +0200
+++ gcc/dwarf2out.c	2009-04-07 08:32:56.000000000 +0200
@@ -5136,6 +5136,7 @@ static void push_decl_scope (tree);
 static void pop_decl_scope (void);
 static dw_die_ref scope_die_for (tree, dw_die_ref);
 static inline int local_scope_p (dw_die_ref);
+static inline int class_scope_p (dw_die_ref);
 static inline int class_or_namespace_scope_p (dw_die_ref);
 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
 static void add_calling_convention_attribute (dw_die_ref, tree);
@@ -12679,18 +12680,26 @@ local_scope_p (dw_die_ref context_die)
   return 0;
 }
 
-/* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
-   whether or not to treat a DIE in this context as a declaration.  */
+/* Returns nonzero if CONTEXT_DIE is a class.  */
 
 static inline int
-class_or_namespace_scope_p (dw_die_ref context_die)
+class_scope_p (dw_die_ref context_die)
 {
   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));
+	      || context_die->die_tag == DW_TAG_union_type));
+}
+
+/* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
+   whether or not to treat a DIE in this context as a declaration.  */
+
+static inline int
+class_or_namespace_scope_p (dw_die_ref context_die)
+{
+  return (class_scope_p (context_die)
+	  || (context_die && context_die->die_tag == DW_TAG_namespace));
 }
 
 /* Many forms of DIEs require a "type description" attribute.  This
@@ -13993,7 +14002,13 @@ gen_variable_die (tree decl, tree origin
       && old_die->die_parent == context_die)
     return;
 
-  var_die = new_die (DW_TAG_variable, context_die, decl);
+  /* For static data members, the declaration in the class is supposed
+     to have DW_TAG_member tag; the specification should still be
+     DW_TAG_variable referencing the DW_TAG_member DIE.  */
+  if (declaration && 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);
 
   origin_die = NULL;
   if (origin != NULL)
--- gcc/testsuite/g++.dg/debug/dwarf2/static-data-member1.C.jj	2009-04-07 08:26:20.000000000 +0200
+++ gcc/testsuite/g++.dg/debug/dwarf2/static-data-member1.C	2009-04-07 08:32:29.000000000 +0200
@@ -0,0 +1,12 @@
+// { dg-do compile }
+// { dg-options "-g -dA -fno-merge-debug-strings" }
+
+struct A
+{
+  static int staticdatamember;
+};
+
+int A::staticdatamember = 6;
+
+// { dg-final { scan-assembler "DW_TAG_member\[^\n\r\]*\[\n\r\]*\[^\n\r\]*staticdatamember\[^\n\r\]*DW_AT_name" } }
+// { dg-final { scan-assembler "DW_TAG_variable\[^\n\r\]*\[\n\r\]*\[^\n\r\]*DW_AT_specification" } }

	Jakub


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