On Wed, Dec 16, 2015 at 09:53:37AM +0100, Pierre-Marie de Rodat wrote:
> On 12/11/2015 09:25 PM, Jason Merrill wrote:
> >Hmm, can we generate the DWARF procedures during finalize_size_functions
> >to avoid the need for preserve_body?
> 
> Good idea, thank you! Here’s the updated patch (bootstrapped and regtested
> on x86_64-linux, as usual).

Unfortunately, this broke the DW_OP_GNU_implicit_pointer support, on vast
majority of binaries and libraries gcc now emits invalid DWARF (which both
gdb and dwz complain about and dwz refuses to optimize because of that).

I'm attaching two possible patches, so far untested.

The first one just fixes what I mainly care about, the committed patch
assumed that DW_TAG_dwarf_procedure is always only created for the Ada
variable sized structures or whatever it was meant for, which is not the
case, and thus if we emit DW_TAG_dwarf_procedure for some other reason,
it would be pruned as unused even when it is actually used (and result in
a DIE reference to the compilation unit header, which is always invalid).

But, looking at the points where you use DW_TAG_dwarf_procedure for the Ada
things, I can't see how it can actually work at all, though there is no
testsuite coverage, so it is hard to find out for real.
The thing is, current code sets die_perennial_p on type DIEs and their
parents, but nothing else.  In particular, type DIEs are identified by
being returned from lookup_type_die, thus earlier passed to
equate_type_number_to_die.  I don't see that this would ever be the case
of DW_TAG_dwarf_procedure though, I see the return of
function_to_dwarf_procedure being used as dw_loc_oprnd1.v.val_die_ref.die
of a DW_OP_call4 that is somewhere used in some location description that is
perhaps used somewhere in some type DIE computation.
Thus, I'm afraid for Ada variable sized structures you get the same problem,
you might IMHO DW_OP_call4 .Ldebug_info0 + 0 because the
DW_TAG_dwarf_procedure will be pruned as "unused".  So IMHO the second patch
makes more sense, and if you (for GCC 7?) want to prune really unused
DW_TAG_dwarf_procedure, you need to add code that will really walk all of
the debuginfo, rather than just type DIEs themselves, and look if location
descriptions (in .debug_info or .debug_loc) reference those
DW_TAG_dwarf_procedure and mark the DW_TAG_dwarf_procedure.

So, Pierre-Marie, can I ask you to run whatever Ada debug info testsuite
you have with the second patch?  And for GCC 7 really please consider adding
gnat.dg/guality/ and fill it with tests.

        Jakub
2016-02-25  Jakub Jelinek  <ja...@redhat.com>

        PR debug/69947
        * dwarf2out.c (string_cst_pool_decl): Set die_perennial_p on
        the DW_TAG_dwarf_procedure DIE.

        * gcc.dg/guality/pr69947.c: New test.

--- gcc/dwarf2out.c.jj  2016-02-24 23:03:32.000000000 +0100
+++ gcc/dwarf2out.c     2016-02-25 10:08:46.688716691 +0100
@@ -26288,6 +26288,7 @@ string_cst_pool_decl (tree t)
       l->dw_loc_oprnd2.v.val_vec.elt_size = 1;
       l->dw_loc_oprnd2.v.val_vec.array = array;
       add_AT_loc (ref, DW_AT_location, l);
+      ref->die_perennial_p = 1;
       equate_decl_number_to_die (decl, ref);
     }
   return rtl;
--- gcc/testsuite/gcc.dg/guality/pr69947.c.jj   2016-02-25 10:00:25.503608176 
+0100
+++ gcc/testsuite/gcc.dg/guality/pr69947.c      2016-02-25 10:05:20.446552599 
+0100
@@ -0,0 +1,22 @@
+/* PR debug/69947 */
+/* { dg-do run } */
+/* { dg-options "-g" } */
+
+#include "../nop.h"
+
+static const char *c = "foobar";
+
+__attribute__((noinline, noclone)) void
+foo (void)
+{
+  static const char a[] = "abcdefg";
+  const char *b = a;           /* { dg-final { gdb-test 14 "c\[2\]" "'o'" } } 
*/
+  asm (NOP : : : "memory");    /* { dg-final { gdb-test 14 "b\[4\]" "'e'" } } 
*/
+}
+
+int
+main ()
+{
+  foo ();
+  return 0;
+}
2016-02-25  Jakub Jelinek  <ja...@redhat.com>

        PR debug/69947
        * dwarf2out.c (prune_unused_types_walk): Don't prune
        DW_TAG_dwarf_procedure.

        * gcc.dg/guality/pr69947.c: New test.

--- gcc/dwarf2out.c.jj  2016-02-24 23:03:32.000000000 +0100
+++ gcc/dwarf2out.c     2016-02-25 10:08:46.688716691 +0100
@@ -25853,11 +25853,6 @@ prune_unused_types_walk (dw_die_ref die)
     case DW_TAG_file_type:
       /* Type nodes are useful only when other DIEs reference them --- don't
         mark them.  */
-      /* FALLTHROUGH */
-
-    case DW_TAG_dwarf_procedure:
-      /* Likewise for DWARF procedures.  */
-
       if (die->die_perennial_p)
        break;
 
--- gcc/testsuite/gcc.dg/guality/pr69947.c.jj   2016-02-25 10:00:25.503608176 
+0100
+++ gcc/testsuite/gcc.dg/guality/pr69947.c      2016-02-25 10:05:20.446552599 
+0100
@@ -0,0 +1,22 @@
+/* PR debug/69947 */
+/* { dg-do run } */
+/* { dg-options "-g" } */
+
+#include "../nop.h"
+
+static const char *c = "foobar";
+
+__attribute__((noinline, noclone)) void
+foo (void)
+{
+  static const char a[] = "abcdefg";
+  const char *b = a;           /* { dg-final { gdb-test 14 "c\[2\]" "'o'" } } 
*/
+  asm (NOP : : : "memory");    /* { dg-final { gdb-test 14 "b\[4\]" "'e'" } } 
*/
+}
+
+int
+main ()
+{
+  foo ();
+  return 0;
+}

Reply via email to