[v3] debug/93751 Option to generate DIEs for external variables - ping

Message ID 03029d14-d76a-8bf7-0f07-56ba5dab6330@att.net
State New
Headers show
Series
  • [v3] debug/93751 Option to generate DIEs for external variables - ping
Related show

Commit Message

Alexey Neyman Feb. 28, 2020, 5:20 p.m.
On 2/26/20 11:40 AM, Richard Biener wrote:

> On February 26, 2020 8:26:06 PM GMT+01:00, Alexander Monakov <amonakov@ispras.ru> wrote:

>> On Wed, 26 Feb 2020, Jason Merrill wrote:

>>

>>> Don't we want to fix the DWARF behavior to match the documentation?

>> +1 - I think Alexey correctly pointed out in the Bugzilla that

>> debuginfo

>> growth from this change would be minimal (usually the number of global

>> variables is very small compared to number of functions (and linemap

>> info).

> +1 from me as well

>

> Richard.


Attached is a revised patch that enables DIE generation for external 
variables at -g1 without an additional option.

Regards,
Alexey.

Comments

Alexander Monakov Feb. 28, 2020, 5:35 p.m. | #1
Hi, 

On Fri, 28 Feb 2020, Alexey Neyman wrote:
> On 2/26/20 11:40 AM, Richard Biener wrote:

> 

> Attached is a revised patch that enables DIE generation for external variables

> at -g1 without an additional option.


I can't substantially review the patch, but there's a couple of nits that
will need fixing anyway:

This file seems to be missing from the patch:

	* gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-3: New test.

Also please note that GCC coding style requires a space before a paren:

    TREE_PUBLIC (decl)

Thanks.
Alexander

Patch

From eba778fd7c2489e2966c55bb8c11bdc48480fc52 Mon Sep 17 00:00:00 2001
From: Alexey Neyman <stilor@att.net>
Date: Thu, 13 Feb 2020 22:01:10 -0800
Subject: [PATCH] debug/93751 DWARF DIEs for external vars with -g1

-g1 is described in the manual to generate debug info for functions and
external variables. It does that for older debugging formats but not for
DWARF. This change brings DWARF in line with the rest of the debugging
formats and with the manual.

2020-02-14  Alexey Neyman  <stilor@att.net>

        PR debug/93751
        * dwarf2out.c (gen_decl_die): Proceed to generating the DIE if
        the debug level is terse and the declaration is public.
        (dwarf2out_decl): Same.
        * gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1: New test.
        * gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2: New test.
        * gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-3: New test.

Signed-off-by: Alexey Neyman <stilor@att.net>
---
 gcc/dwarf2out.c                               | 12 ++++++++----
 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1.c |  6 ++++++
 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2.c |  6 ++++++
 3 files changed, 20 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2.c

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index fe46c7e1eee..4d9bfe3a68b 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -26354,8 +26354,10 @@  gen_decl_die (tree decl, tree origin, struct vlr_context *ctx,
     case VAR_DECL:
     case RESULT_DECL:
       /* If we are in terse mode, don't generate any DIEs to represent any
-	 variable declarations or definitions.  */
-      if (debug_info_level <= DINFO_LEVEL_TERSE)
+	 variable declarations or definitions unless it is external.  */
+      if (debug_info_level < DINFO_LEVEL_TERSE
+	  || (debug_info_level == DINFO_LEVEL_TERSE
+	      && !TREE_PUBLIC(decl_or_origin)))
 	break;
 
       /* Avoid generating stray type DIEs during late dwarf dumping.
@@ -26831,8 +26833,10 @@  dwarf2out_decl (tree decl)
 	context_die = lookup_decl_die (DECL_CONTEXT (decl));
 
       /* If we are in terse mode, don't generate any DIEs to represent any
-	 variable declarations or definitions.  */
-      if (debug_info_level <= DINFO_LEVEL_TERSE)
+	 variable declarations or definitions unless it is external.  */
+      if (debug_info_level < DINFO_LEVEL_TERSE
+	  || (debug_info_level == DINFO_LEVEL_TERSE
+	      && !TREE_PUBLIC(decl)))
 	return;
       break;
 
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1.c b/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1.c
new file mode 100644
index 00000000000..4be170c57d6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1.c
@@ -0,0 +1,6 @@ 
+// { dg-do compile }
+// { dg-options "-O -gdwarf-2 -g1 -dA" }
+static int bar;
+
+// Verify that with -g1 we still do not generate DIEs for static variables.
+// { dg-final { scan-assembler-not " DW_TAG_variable" } }
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2.c b/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2.c
new file mode 100644
index 00000000000..3ee369bd99e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2.c
@@ -0,0 +1,6 @@ 
+// { dg-do compile }
+// { dg-options "-O -gdwarf-2 -g1 -dA" }
+int foo;
+
+// Verify that with -g1 we generate DIEs for external variables.
+// { dg-final { scan-assembler " DW_TAG_variable" } }
-- 
2.20.1