diff mbox

PR debug/45024

Message ID m34ofrvojt.fsf@redhat.com
State New
Headers show

Commit Message

Dodji Seketeli July 22, 2010, 9:44 a.m. UTC
Hello,

Consider this testcase:
struct S {
  template<typename Z> struct T { };
};

S::T<int> tval;

In this PR, the DIE of S::T<int> is not a child of the DIE of S. Rather
it's a child of the compilation unit DIE.

That patch below addresses that issue.

Fully bootstrapped and tested against trunk on x86_64-unknown-linux-gnu.

OK to commit to trunk?

    gcc/ChangeLog:
    	PR debug/45024
    	* dwarf2out.c (scope_die_for): Don't fall back to the compilation
    	unit DIE if we can find the scope DIE.
    
    gcc/testsuite/ChangeLog:
    	PR debug/45024
    	* g++.dg/debug/dwarf2/nested-2.C: New test case.

Comments

Jason Merrill July 22, 2010, 1:16 p.m. UTC | #1
OK.

Jason
H.J. Lu July 25, 2010, 2:38 p.m. UTC | #2
On Thu, Jul 22, 2010 at 2:44 AM, Dodji Seketeli <dodji@redhat.com> wrote:
> Hello,
>
> Consider this testcase:
> struct S {
>  template<typename Z> struct T { };
> };
>
> S::T<int> tval;
>
> In this PR, the DIE of S::T<int> is not a child of the DIE of S. Rather
> it's a child of the compilation unit DIE.
>
> That patch below addresses that issue.
>
> Fully bootstrapped and tested against trunk on x86_64-unknown-linux-gnu.
>
> OK to commit to trunk?
>
>    gcc/ChangeLog:
>        PR debug/45024
>        * dwarf2out.c (scope_die_for): Don't fall back to the compilation
>        unit DIE if we can find the scope DIE.
>
>    gcc/testsuite/ChangeLog:
>        PR debug/45024
>        * g++.dg/debug/dwarf2/nested-2.C: New test case.
>

This caused:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45068
diff mbox

Patch

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index ce35c91..183bbd3 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17585,9 +17585,13 @@  scope_die_for (tree t, dw_die_ref context_die)
 	{
 	  gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
 		      || TREE_ASM_WRITTEN (containing_scope));
+	  /*We are not in the middle of emitting the type
+	    CONTAINING_SCOPE. Let's see if it's emitted already.  */
+	  scope_die = lookup_type_die (containing_scope);
 
 	  /* If none of the current dies are suitable, we get file scope.  */
-	  scope_die = comp_unit_die;
+	  if (scope_die == NULL)
+	    scope_die = comp_unit_die;
 	}
       else
 	scope_die = lookup_type_die (containing_scope);

diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/nested-2.C b/gcc/testsuite/g++.dg/debug/dwarf2/nested-2.C
new file mode 100644
index 0000000..2386baa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/nested-2.C
@@ -0,0 +1,37 @@ 
+/*
+  Origin: PR debug/45024
+  { dg-options "-g -dA -fno-merge-debug-strings" }
+  { dg-do compile }
+*/
+
+struct S {
+  template<typename Z> struct T { };
+};
+
+S::T<int> tval;
+
+/*
+We want to express that the DIE of S::T<int> must be a child of the DIE of S, like in assembly this output:
+
+	.uleb128 0x2	# (DIE (0x9e) DW_TAG_structure_type)
+	.ascii "S\0"	# DW_AT_name
+	.byte	0x1	# DW_AT_byte_size
+	.byte	0x1	# DW_AT_decl_file (../../prtests/test-PR45024.cc)
+	.byte	0x1	# DW_AT_decl_line
+	.long	0xbc	# DW_AT_sibling
+	.uleb128 0x3	# (DIE (0xa8) DW_TAG_structure_type)
+	.ascii "T<int>\0"	# DW_AT_name
+	.byte	0x1	# DW_AT_byte_size
+	.byte	0x1	# DW_AT_decl_file (../../prtests/test-PR45024.cc)
+	.byte	0x2	# DW_AT_decl_line
+	.uleb128 0x4	# (DIE (0xb3) DW_TAG_template_type_param)
+	.ascii "Z\0"	# DW_AT_name
+	.long	0xbc	# DW_AT_type
+	.byte	0	# end of children of DIE 0xa8
+	.byte	0	# end of children of DIE 0x9e
+
+Hence the slightly odd regexp:
+
+  { dg-final { scan-assembler "\[^\n\r\]*\\(DIE\[^\n\r\]*DW_TAG_structure_type\\)\[\n\r\]+\[^\n\r\]*\"S\\\\0\"\[ \t\]+#\[ \t\]+DW_AT_name\[\n\r\]+\(.*\)?\\(DIE\[^\n\r\]*DW_TAG_structure_type\\)\[\n\r\]+\[^\n\r\]*\"T<int>\\\\0\"\[ \t\]+\(.*\)?\\(DIE\[^\n\r\]*DW_TAG_template_type_param\\)\[\n\r\]+\[^\n\r\]*\[\n\r\]+\[^\n\r\]*\[\n\r\]+\[^\n\r\]*#\[ \t\]+end of children of DIE\[^\n\r\]*\[\n\r\]+\[^\n\r\]*end of children of DIE\[^\n\r\]*" } }
+
+ */