public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v2] debug/93751 Option to generate DIEs for external variables
       [not found] <d60f5b48-fdff-451a-0ca9-cf90e610c31a.ref@att.net>
@ 2020-02-19 23:31 ` Alexey Neyman
  2020-02-26 19:02   ` [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping Alexey Neyman
  0 siblings, 1 reply; 17+ messages in thread
From: Alexey Neyman @ 2020-02-19 23:31 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 390 bytes --]

Hi all,

Attached is a patch adjusted per discussion in 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93751

- The manual is corrected to reflect that DIEs for external variables 
are not generated when using DWARF
- A new option is introduced that implements the behavior that was 
described in the manual (and is what other debugging formats do).

Please review/apply.

Regards,
Alexey.


[-- Attachment #2: 0001-debug-93751-Option-to-create-DIEs-for-ext.-vars.patch --]
[-- Type: text/x-patch, Size: 7145 bytes --]

From 7a1b7d99a98416ed8b1c8bf2e4877655fd820fd0 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 Option to create DIEs for ext. vars

-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 fixes the manual to describe the current behavior and
introduces a new option, -gexternal-variables, that makes -g1 output the
DIEs for external variables, as it does for older debugging formats.

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

        PR debug/93751
        * gcc/common.opt: New option, -gexternal-variables.
        * gcc/doc/invoke.texi: Describe the new option.
        * dwarf2out.c (gen_decl_die): Proceed to generating the DIE if
        the debug level is terse, DIEs for external variables have been
        requested 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/common.opt                                |  4 ++++
 gcc/doc/invoke.texi                           | 13 +++++++++++--
 gcc/dwarf2out.c                               | 14 ++++++++++----
 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1.c |  7 +++++++
 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2.c |  7 +++++++
 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-3.c |  7 +++++++
 6 files changed, 46 insertions(+), 6 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
 create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-3.c

diff --git a/gcc/common.opt b/gcc/common.opt
index 5692cd04374..aec0aacb116 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3075,6 +3075,10 @@ gdwarf-
 Common Driver Joined UInteger Var(dwarf_version) Init(4) Negative(gstabs)
 Generate debug information in DWARF v2 (or later) format.
 
+gexternal-variables
+Common Driver RejectNegative Var(debug_external_variables)
+Generate debug information for external variables.
+
 ggdb
 Common Driver JoinedOrMissing
 Generate debug information in default extended format.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index bd9ecebf103..d09cf298c36 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -443,7 +443,8 @@ Objective-C and Objective-C++ Dialects}.
 @item Debugging Options
 @xref{Debugging Options,,Options for Debugging Your Program}.
 @gccoptlist{-g  -g@var{level}  -gdwarf  -gdwarf-@var{version} @gol
--ggdb  -grecord-gcc-switches  -gno-record-gcc-switches @gol
+-gexternal-variables  -ggdb  @gol
+-grecord-gcc-switches  -gno-record-gcc-switches @gol
 -gstabs  -gstabs+  -gstrict-dwarf  -gno-strict-dwarf @gol
 -gas-loc-support  -gno-as-loc-support @gol
 -gas-locview-support  -gno-as-locview-support @gol
@@ -8649,7 +8650,10 @@ Level 0 produces no debug information at all.  Thus, @option{-g0} negates
 Level 1 produces minimal information, enough for making backtraces in
 parts of the program that you don't plan to debug.  This includes
 descriptions of functions and external variables, and line number
-tables, but no information about local variables.
+tables, but no information about local variables.  For historical
+reasons, the descriptions of external variables are not generated
+when producing the debugging information in DWARF format; these
+descriptions can be requested using @option{-gexternal-variables}.
 
 Level 3 includes extra information, such as all the macro definitions
 present in the program.  Some debuggers support macro expansion when
@@ -8663,6 +8667,11 @@ confusion with @option{-gdwarf-@var{level}}.
 Instead use an additional @option{-g@var{level}} option to change the
 debug level for DWARF.
 
+@item -gexternal-variables
+@opindex gexternal-variables
+When using level 1 of the debugging information in DWARF format,
+also produce the descriptions of the external variables.
+
 @item -fno-eliminate-unused-debug-symbols
 @opindex feliminate-unused-debug-symbols
 @opindex fno-eliminate-unused-debug-symbols
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index fe46c7e1eee..13c62ad1eec 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -26354,8 +26354,11 @@ 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 an external variable
+	 and we've been explicitly told to generate them.  */
+      if (debug_info_level < DINFO_LEVEL_TERSE
+	  || (debug_info_level == DINFO_LEVEL_TERSE
+	      && !(debug_external_variables && TREE_PUBLIC(decl_or_origin))))
 	break;
 
       /* Avoid generating stray type DIEs during late dwarf dumping.
@@ -26831,8 +26834,11 @@ 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 an external variable
+	 and we've been explicitly told to generate them.  */
+      if (debug_info_level < DINFO_LEVEL_TERSE
+	  || (debug_info_level == DINFO_LEVEL_TERSE
+	      && !(debug_external_variables && 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..d9b75cb7537
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1.c
@@ -0,0 +1,7 @@
+// { dg-do compile }
+// { dg-options "-O -gdwarf-2 -g1 -dA" }
+int foo;
+static int bar;
+
+// Verify that with -g1 we do not generate the DIEs for variables at all
+// { 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..177256af5c2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2.c
@@ -0,0 +1,7 @@
+// { dg-do compile }
+// { dg-options "-O -gdwarf-2 -g1 -gexternal-variables -dA" }
+static int bar;
+
+// Verify that with -g1 -gexternal-variables 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-3.c b/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-3.c
new file mode 100644
index 00000000000..8d750498a35
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-3.c
@@ -0,0 +1,7 @@
+// { dg-do compile }
+// { dg-options "-O -gdwarf-2 -g1 -gexternal-variables -dA" }
+int foo;
+
+// Verify that with -g1 -gexternal-variables we generate
+// DIEs for external variables.
+// { dg-final { scan-assembler " DW_TAG_variable" } }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping
  2020-02-19 23:31 ` [PATCH v2] debug/93751 Option to generate DIEs for external variables Alexey Neyman
@ 2020-02-26 19:02   ` Alexey Neyman
  2020-02-26 19:14     ` Jason Merrill
  0 siblings, 1 reply; 17+ messages in thread
From: Alexey Neyman @ 2020-02-26 19:02 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 469 bytes --]

Patch ping.

On 2/19/20 3:30 PM, Alexey Neyman wrote:
> Hi all,
>
> Attached is a patch adjusted per discussion in 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93751
>
> - The manual is corrected to reflect that DIEs for external variables 
> are not generated when using DWARF
> - A new option is introduced that implements the behavior that was 
> described in the manual (and is what other debugging formats do).
>
> Please review/apply.
>
> Regards,
> Alexey.
>

[-- Attachment #2: 0001-debug-93751-Option-to-create-DIEs-for-ext.-vars.patch --]
[-- Type: text/plain, Size: 7146 bytes --]

>From 7a1b7d99a98416ed8b1c8bf2e4877655fd820fd0 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 Option to create DIEs for ext. vars

-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 fixes the manual to describe the current behavior and
introduces a new option, -gexternal-variables, that makes -g1 output the
DIEs for external variables, as it does for older debugging formats.

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

        PR debug/93751
        * gcc/common.opt: New option, -gexternal-variables.
        * gcc/doc/invoke.texi: Describe the new option.
        * dwarf2out.c (gen_decl_die): Proceed to generating the DIE if
        the debug level is terse, DIEs for external variables have been
        requested 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/common.opt                                |  4 ++++
 gcc/doc/invoke.texi                           | 13 +++++++++++--
 gcc/dwarf2out.c                               | 14 ++++++++++----
 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1.c |  7 +++++++
 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2.c |  7 +++++++
 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-3.c |  7 +++++++
 6 files changed, 46 insertions(+), 6 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
 create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-3.c

diff --git a/gcc/common.opt b/gcc/common.opt
index 5692cd04374..aec0aacb116 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3075,6 +3075,10 @@ gdwarf-
 Common Driver Joined UInteger Var(dwarf_version) Init(4) Negative(gstabs)
 Generate debug information in DWARF v2 (or later) format.
 
+gexternal-variables
+Common Driver RejectNegative Var(debug_external_variables)
+Generate debug information for external variables.
+
 ggdb
 Common Driver JoinedOrMissing
 Generate debug information in default extended format.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index bd9ecebf103..d09cf298c36 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -443,7 +443,8 @@ Objective-C and Objective-C++ Dialects}.
 @item Debugging Options
 @xref{Debugging Options,,Options for Debugging Your Program}.
 @gccoptlist{-g  -g@var{level}  -gdwarf  -gdwarf-@var{version} @gol
--ggdb  -grecord-gcc-switches  -gno-record-gcc-switches @gol
+-gexternal-variables  -ggdb  @gol
+-grecord-gcc-switches  -gno-record-gcc-switches @gol
 -gstabs  -gstabs+  -gstrict-dwarf  -gno-strict-dwarf @gol
 -gas-loc-support  -gno-as-loc-support @gol
 -gas-locview-support  -gno-as-locview-support @gol
@@ -8649,7 +8650,10 @@ Level 0 produces no debug information at all.  Thus, @option{-g0} negates
 Level 1 produces minimal information, enough for making backtraces in
 parts of the program that you don't plan to debug.  This includes
 descriptions of functions and external variables, and line number
-tables, but no information about local variables.
+tables, but no information about local variables.  For historical
+reasons, the descriptions of external variables are not generated
+when producing the debugging information in DWARF format; these
+descriptions can be requested using @option{-gexternal-variables}.
 
 Level 3 includes extra information, such as all the macro definitions
 present in the program.  Some debuggers support macro expansion when
@@ -8663,6 +8667,11 @@ confusion with @option{-gdwarf-@var{level}}.
 Instead use an additional @option{-g@var{level}} option to change the
 debug level for DWARF.
 
+@item -gexternal-variables
+@opindex gexternal-variables
+When using level 1 of the debugging information in DWARF format,
+also produce the descriptions of the external variables.
+
 @item -fno-eliminate-unused-debug-symbols
 @opindex feliminate-unused-debug-symbols
 @opindex fno-eliminate-unused-debug-symbols
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index fe46c7e1eee..13c62ad1eec 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -26354,8 +26354,11 @@ 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 an external variable
+	 and we've been explicitly told to generate them.  */
+      if (debug_info_level < DINFO_LEVEL_TERSE
+	  || (debug_info_level == DINFO_LEVEL_TERSE
+	      && !(debug_external_variables && TREE_PUBLIC(decl_or_origin))))
 	break;
 
       /* Avoid generating stray type DIEs during late dwarf dumping.
@@ -26831,8 +26834,11 @@ 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 an external variable
+	 and we've been explicitly told to generate them.  */
+      if (debug_info_level < DINFO_LEVEL_TERSE
+	  || (debug_info_level == DINFO_LEVEL_TERSE
+	      && !(debug_external_variables && 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..d9b75cb7537
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1.c
@@ -0,0 +1,7 @@
+// { dg-do compile }
+// { dg-options "-O -gdwarf-2 -g1 -dA" }
+int foo;
+static int bar;
+
+// Verify that with -g1 we do not generate the DIEs for variables at all
+// { 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..177256af5c2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2.c
@@ -0,0 +1,7 @@
+// { dg-do compile }
+// { dg-options "-O -gdwarf-2 -g1 -gexternal-variables -dA" }
+static int bar;
+
+// Verify that with -g1 -gexternal-variables 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-3.c b/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-3.c
new file mode 100644
index 00000000000..8d750498a35
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-3.c
@@ -0,0 +1,7 @@
+// { dg-do compile }
+// { dg-options "-O -gdwarf-2 -g1 -gexternal-variables -dA" }
+int foo;
+
+// Verify that with -g1 -gexternal-variables we generate
+// DIEs for external variables.
+// { dg-final { scan-assembler " DW_TAG_variable" } }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping
  2020-02-26 19:02   ` [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping Alexey Neyman
@ 2020-02-26 19:14     ` Jason Merrill
  2020-02-26 19:26       ` Alexander Monakov
  0 siblings, 1 reply; 17+ messages in thread
From: Jason Merrill @ 2020-02-26 19:14 UTC (permalink / raw)
  To: Alexey Neyman, gcc-patches

On 2/26/20 2:02 PM, Alexey Neyman wrote:
> Patch ping.
> 
> On 2/19/20 3:30 PM, Alexey Neyman wrote:
>> Hi all,
>>
>> Attached is a patch adjusted per discussion in 
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93751
>>
>> - The manual is corrected to reflect that DIEs for external variables 
>> are not generated when using DWARF
>> - A new option is introduced that implements the behavior that was 
>> described in the manual (and is what other debugging formats do).

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

Jason

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping
  2020-02-26 19:14     ` Jason Merrill
@ 2020-02-26 19:26       ` Alexander Monakov
  2020-02-26 20:14         ` Richard Biener
  2020-02-28 17:39         ` [PATCH v2] " Eric Botcazou
  0 siblings, 2 replies; 17+ messages in thread
From: Alexander Monakov @ 2020-02-26 19:26 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Alexey Neyman, gcc-patches

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).

Alexander

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping
  2020-02-26 19:26       ` Alexander Monakov
@ 2020-02-26 20:14         ` Richard Biener
  2020-02-28 17:20           ` [PATCH v3] " Alexey Neyman
  2020-02-28 17:39         ` [PATCH v2] " Eric Botcazou
  1 sibling, 1 reply; 17+ messages in thread
From: Richard Biener @ 2020-02-26 20:14 UTC (permalink / raw)
  To: gcc-patches, Alexander Monakov, Jason Merrill; +Cc: Alexey Neyman

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. 

>Alexander

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3] debug/93751 Option to generate DIEs for external variables - ping
  2020-02-26 20:14         ` Richard Biener
@ 2020-02-28 17:20           ` Alexey Neyman
  2020-02-28 17:35             ` Alexander Monakov
  0 siblings, 1 reply; 17+ messages in thread
From: Alexey Neyman @ 2020-02-28 17:20 UTC (permalink / raw)
  To: Richard Biener, gcc-patches, Alexander Monakov, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 661 bytes --]

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.


[-- Attachment #2: 0001-debug-93751-DWARF-DIEs-for-external-vars-with-g1.patch --]
[-- Type: text/x-patch, Size: 3432 bytes --]

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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3] debug/93751 Option to generate DIEs for external variables - ping
  2020-02-28 17:20           ` [PATCH v3] " Alexey Neyman
@ 2020-02-28 17:35             ` Alexander Monakov
  0 siblings, 0 replies; 17+ messages in thread
From: Alexander Monakov @ 2020-02-28 17:35 UTC (permalink / raw)
  To: Alexey Neyman; +Cc: Richard Biener, gcc-patches, Jason Merrill

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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping
  2020-02-26 19:26       ` Alexander Monakov
  2020-02-26 20:14         ` Richard Biener
@ 2020-02-28 17:39         ` Eric Botcazou
  2020-02-28 19:11           ` Alexander Monakov
  1 sibling, 1 reply; 17+ messages in thread
From: Eric Botcazou @ 2020-02-28 17:39 UTC (permalink / raw)
  To: Alexander Monakov; +Cc: gcc-patches, Jason Merrill, Alexey Neyman

> +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).

Well, this will drag the associated types too, so figures would be welcome...

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping
  2020-02-28 17:39         ` [PATCH v2] " Eric Botcazou
@ 2020-02-28 19:11           ` Alexander Monakov
  2020-02-28 20:29             ` Jason Merrill
  0 siblings, 1 reply; 17+ messages in thread
From: Alexander Monakov @ 2020-02-28 19:11 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches, Jason Merrill, Alexey Neyman



On Fri, 28 Feb 2020, Eric Botcazou wrote:

> > +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).
> 
> Well, this will drag the associated types too, so figures would be welcome...

Hm. So apparently at -g1 we don't emit type information for functions, and
gdb sees each function as 'void foo()' regardless of actual prototype.
Otherwise I would expect most of the types to be already present in debug info.

I wonder if it would make sense to emit defined variables in a similar fashion,
i.e. only address and size?

(assuming that still fits Alexey's needs)

Thanks.
Alexander

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping
  2020-02-28 19:11           ` Alexander Monakov
@ 2020-02-28 20:29             ` Jason Merrill
  2020-02-28 21:13               ` Alexey Neyman
  0 siblings, 1 reply; 17+ messages in thread
From: Jason Merrill @ 2020-02-28 20:29 UTC (permalink / raw)
  To: Alexander Monakov, Eric Botcazou; +Cc: gcc-patches, Alexey Neyman

On 2/28/20 2:11 PM, Alexander Monakov wrote:
> 
> 
> On Fri, 28 Feb 2020, Eric Botcazou wrote:
> 
>>> +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).
>>
>> Well, this will drag the associated types too, so figures would be welcome...
> 
> Hm. So apparently at -g1 we don't emit type information for functions, and
> gdb sees each function as 'void foo()' regardless of actual prototype.
> Otherwise I would expect most of the types to be already present in debug info.
> 
> I wonder if it would make sense to emit defined variables in a similar fashion,
> i.e. only address and size?

I think so.  And we probably don't want function-scope or class-scope 
variables that happen to be TREE_PUBLIC.

Jason

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping
  2020-02-28 20:29             ` Jason Merrill
@ 2020-02-28 21:13               ` Alexey Neyman
  2020-02-28 21:15                 ` Alexey Neyman
  2020-02-28 21:51                 ` Jason Merrill
  0 siblings, 2 replies; 17+ messages in thread
From: Alexey Neyman @ 2020-02-28 21:13 UTC (permalink / raw)
  To: Jason Merrill, Alexander Monakov, Eric Botcazou; +Cc: gcc-patches


On 2/28/20 12:28 PM, Jason Merrill wrote:
> On 2/28/20 2:11 PM, Alexander Monakov wrote:
>>
>>
>> On Fri, 28 Feb 2020, Eric Botcazou wrote:
>>
>>>> +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).
>>>
>>> Well, this will drag the associated types too, so figures would be 
>>> welcome...
>>
Below are the numbers from compiling GLIBC 2.31 for 
x86_64-unknown-linux-gnu. The first column is with a pristine copy of 
GCC at -g1, the 2nd/3rd columns are -g1 with this patch, 4th/5th columns 
are -g2.

.debug_ranges�� 125872� 125872� 0%����� 452864����� 260%
.debug_str����� 88689�� 102005� 15%���� 183650����� 107%
.debug_abbrev�� 112470� 255769� 127%��� 735914����� 554%
.debug_line���� 647942� 705070� 9%����� 1544877���� 138%
.debug_loc����� 64150�� 64150�� 0%����� 2976025���� 4539%
.debug_aranges� 77712�� 80784�� 4%����� 80912������ 4%
.debug_info���� 240284� 907461� 278%��� 4707104���� 1859%
TOTAL���������� 1357119 2241111 65%���� 10681346��� 687%

So indeed, an increase due to type info is substantial - but still 
nothing compared to -g2 increase.
>> Hm. So apparently at -g1 we don't emit type information for 
>> functions, and
>> gdb sees each function as 'void foo()' regardless of actual prototype.
>> Otherwise I would expect most of the types to be already present in 
>> debug info.
>>
>> I wonder if it would make sense to emit defined variables in a 
>> similar fashion,
>> i.e. only address and size?
I'll see if I can modify the patch to do so.
>
> I think so.� And we probably don't want function-scope or class-scope 
> variables that happen to be TREE_PUBLIC.

Can you give an example of such function/class scope variables being 
TREE_PUBLIC? I tried a static variable described within a function 
scope, it was not TREE_PUBLIC.

Regards,
Alexey.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping
  2020-02-28 21:13               ` Alexey Neyman
@ 2020-02-28 21:15                 ` Alexey Neyman
  2020-02-28 21:51                 ` Jason Merrill
  1 sibling, 0 replies; 17+ messages in thread
From: Alexey Neyman @ 2020-02-28 21:15 UTC (permalink / raw)
  To: Jason Merrill, Alexander Monakov, Eric Botcazou; +Cc: gcc-patches


On 2/28/20 12:28 PM, Jason Merrill wrote:
> On 2/28/20 2:11 PM, Alexander Monakov wrote:
>>
>>
>> On Fri, 28 Feb 2020, Eric Botcazou wrote:
>>
>>>> +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).
>>>
>>> Well, this will drag the associated types too, so figures would be 
>>> welcome...
>>
Below are the numbers from compiling GLIBC 2.31 for 
x86_64-unknown-linux-gnu. The first column is with a pristine copy of 
GCC at -g1, the 2nd/3rd columns are -g1 with this patch, 4th/5th columns 
are -g2.

.debug_ranges�� 125872� 125872� 0%����� 452864����� 260%
.debug_str����� 88689�� 102005� 15%���� 183650����� 107%
.debug_abbrev�� 112470� 255769� 127%��� 735914����� 554%
.debug_line���� 647942� 705070� 9%����� 1544877���� 138%
.debug_loc����� 64150�� 64150�� 0%����� 2976025���� 4539%
.debug_aranges� 77712�� 80784�� 4%����� 80912������ 4%
.debug_info���� 240284� 907461� 278%��� 4707104���� 1859%
TOTAL���������� 1357119 2241111 65%���� 10681346��� 687%

So indeed, an increase due to type info is substantial - but still 
nothing compared to -g2 increase.
>> Hm. So apparently at -g1 we don't emit type information for 
>> functions, and
>> gdb sees each function as 'void foo()' regardless of actual prototype.
>> Otherwise I would expect most of the types to be already present in 
>> debug info.
>>
>> I wonder if it would make sense to emit defined variables in a 
>> similar fashion,
>> i.e. only address and size?
I'll see if I can modify the patch to do so.
>
> I think so.� And we probably don't want function-scope or class-scope 
> variables that happen to be TREE_PUBLIC.

Can you give an example of such function/class scope variables being 
TREE_PUBLIC? I tried a static variable described within a function 
scope, it was not TREE_PUBLIC.

Regards,
Alexey.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping
  2020-02-28 21:13               ` Alexey Neyman
  2020-02-28 21:15                 ` Alexey Neyman
@ 2020-02-28 21:51                 ` Jason Merrill
  2020-03-14  8:04                   ` [PATCH v3] debug/93751 Generate DIEs for external variables with -g1 Alexey Neyman
  1 sibling, 1 reply; 17+ messages in thread
From: Jason Merrill @ 2020-02-28 21:51 UTC (permalink / raw)
  To: Alexey Neyman, Alexander Monakov, Eric Botcazou; +Cc: gcc-patches

On 2/28/20 4:12 PM, Alexey Neyman wrote:
> 
> On 2/28/20 12:28 PM, Jason Merrill wrote:
>> On 2/28/20 2:11 PM, Alexander Monakov wrote:
>>>
>>>
>>> On Fri, 28 Feb 2020, Eric Botcazou wrote:
>>>
>>>>> +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).
>>>>
>>>> Well, this will drag the associated types too, so figures would be 
>>>> welcome...
>>>
> Below are the numbers from compiling GLIBC 2.31 for 
> x86_64-unknown-linux-gnu. The first column is with a pristine copy of 
> GCC at -g1, the 2nd/3rd columns are -g1 with this patch, 4th/5th columns 
> are -g2.
> 
> .debug_ranges�� 125872� 125872� 0%����� 452864����� 260%
> .debug_str����� 88689�� 102005� 15%���� 183650����� 107%
> .debug_abbrev�� 112470� 255769� 127%��� 735914����� 554%
> .debug_line���� 647942� 705070� 9%����� 1544877���� 138%
> .debug_loc����� 64150�� 64150�� 0%����� 2976025���� 4539%
> .debug_aranges� 77712�� 80784�� 4%����� 80912������ 4%
> .debug_info���� 240284� 907461� 278%��� 4707104���� 1859%
> TOTAL���������� 1357119 2241111 65%���� 10681346��� 687%
> 
> So indeed, an increase due to type info is substantial - but still 
> nothing compared to -g2 increase.
>>> Hm. So apparently at -g1 we don't emit type information for 
>>> functions, and
>>> gdb sees each function as 'void foo()' regardless of actual prototype.
>>> Otherwise I would expect most of the types to be already present in 
>>> debug info.
>>>
>>> I wonder if it would make sense to emit defined variables in a 
>>> similar fashion,
>>> i.e. only address and size?
> I'll see if I can modify the patch to do so.
>>
>> I think so.� And we probably don't want function-scope or class-scope 
>> variables that happen to be TREE_PUBLIC.
> 
> Can you give an example of such function/class scope variables being 
> TREE_PUBLIC? I tried a static variable described within a function 
> scope, it was not TREE_PUBLIC.

A class static data member, or a static variable in an inline function 
or template instantiation.

Jason

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3] debug/93751 Generate DIEs for external variables with -g1
  2020-02-28 21:51                 ` Jason Merrill
@ 2020-03-14  8:04                   ` Alexey Neyman
  2020-03-14 11:53                     ` Alexander Monakov
  0 siblings, 1 reply; 17+ messages in thread
From: Alexey Neyman @ 2020-03-14  8:04 UTC (permalink / raw)
  To: Jason Merrill, Alexander Monakov, Eric Botcazou; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2265 bytes --]

On 2/28/20 1:50 PM, Jason Merrill wrote:
> On 2/28/20 4:12 PM, Alexey Neyman wrote:
>> On 2/28/20 12:28 PM, Jason Merrill wrote:
>>> On 2/28/20 2:11 PM, Alexander Monakov wrote:
>>>> Hm. So apparently at -g1 we don't emit type information for 
>>>> functions, and
>>>> gdb sees each function as 'void foo()' regardless of actual prototype.
>>>> Otherwise I would expect most of the types to be already present in 
>>>> debug info.
>>>>
>>>> I wonder if it would make sense to emit defined variables in a 
>>>> similar fashion,
>>>> i.e. only address and size?
>> I'll see if I can modify the patch to do so.

Attached is a patch that does it: at -g1, the type attributes are not 
generated.

With that, the size increase at -g1 is more palatable. Again, using 
GLIBC 2.31 for x86_64-unknown-linux-gnu as a reference (columns are 
without this patch, with this patch and percent increase):

.debug_aranges 77712 78960 +1.6%
.debug_info 240284 259639 +8.1%
.debug_abbrev 112470 131014 +16.5%
.debug_line 647942 671588 +3.7%
.debug_str 88689 94503 +6.6%
.debug_loc 64150 64150 +0.0%
.debug_ranges 125872 125872 +0.0%
TOTAL 1357119 1425726 +5.1%


>>> I think so. And we probably don't want function-scope or class-scope 
>>> variables that happen to be TREE_PUBLIC.
>>
>> Can you give an example of such function/class scope variables being 
>> TREE_PUBLIC? I tried a static variable described within a function 
>> scope, it was not TREE_PUBLIC.
>
> A class static data member, or a static variable in an inline function 
> or template instantiation.
>
Static variables inside an inline function or template instantiations 
were not reflected in the DIEs even with the previous iteration of this 
patch - because the DIE generation does not descend into 
function/template bodies if the debug level is terse.

DIEs for a static data member of a class, however, are currently 
generated. I couldn't find a way to distinguish it from a normal 
variable with an external linkage in a language-agnostic way. But I'd 
point out that -gstabs, for example, does generate debug info for such 
static class members even at -g1. If it is desired to avoid DIEs for 
static data members, I'd appreciate some pointers as to what tree 
predicates I should check.

Regards,
Alexey.

[-- Attachment #2: 0001-debug-93751-DWARF-DIEs-for-external-vars-with-g1.patch --]
[-- Type: text/x-patch, Size: 6656 bytes --]

From eae5ba4be1d574a515fa255d049327211afd8123 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. Do not
        generate type info.
        (dwarf2out_decl): Same.
        (add_type_attribute): Return immediately if debug level is
        terse.
        * 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                               | 73 +++++++++++--------
 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1.c |  6 ++
 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2.c |  6 ++
 3 files changed, 53 insertions(+), 32 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..271a25d01a6 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -21562,6 +21562,9 @@ add_type_attribute (dw_die_ref object_die, tree type, int cv_quals,
   enum tree_code code  = TREE_CODE (type);
   dw_die_ref type_die  = NULL;
 
+  if (debug_info_level <= DINFO_LEVEL_TERSE)
+    return;
+
   /* ??? If this type is an unnamed subrange type of an integral, floating-point
      or fixed-point type, use the inner type.  This is because we have no
      support for unnamed types in base_type_die.  This can happen if this is
@@ -26354,40 +26357,44 @@ 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.
-         All types have been dumped early.  */
-      if (early_dwarf
-	  /* ???  But in LTRANS we cannot annotate early created variably
-	     modified type DIEs without copying them and adjusting all
-	     references to them.  Dump them again as happens for inlining
-	     which copies both the decl and the types.  */
-	  /* ???  And even non-LTO needs to re-visit type DIEs to fill
-	     in VLA bound information for example.  */
-	  || (decl && variably_modified_type_p (TREE_TYPE (decl),
-						current_function_decl)))
-	{
-	  /* Output any DIEs that are needed to specify the type of this data
-	     object.  */
-	  if (decl_by_reference_p (decl_or_origin))
-	    gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
-	  else
-	    gen_type_die (TREE_TYPE (decl_or_origin), context_die);
-	}
+      if (debug_info_level > DINFO_LEVEL_TERSE) {
+	/* Avoid generating stray type DIEs during late dwarf dumping.
+	   All types have been dumped early.  */
+	if (early_dwarf
+	    /* ???  But in LTRANS we cannot annotate early created variably
+	       modified type DIEs without copying them and adjusting all
+	       references to them.  Dump them again as happens for inlining
+	       which copies both the decl and the types.  */
+	    /* ???  And even non-LTO needs to re-visit type DIEs to fill
+	       in VLA bound information for example.  */
+	    || (decl && variably_modified_type_p (TREE_TYPE (decl),
+						  current_function_decl)))
+	  {
+	    /* Output any DIEs that are needed to specify the type of this data
+	       object.  */
+	    if (decl_by_reference_p (decl_or_origin))
+	      gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
+	    else
+	      gen_type_die (TREE_TYPE (decl_or_origin), context_die);
+	  }
 
-      if (early_dwarf)
-	{
-	  /* And its containing type.  */
-	  class_origin = decl_class_context (decl_or_origin);
-	  if (class_origin != NULL_TREE)
-	    gen_type_die_for_member (class_origin, decl_or_origin, context_die);
+	if (early_dwarf)
+	  {
+	    /* And its containing type.  */
+	    class_origin = decl_class_context (decl_or_origin);
+	    if (class_origin != NULL_TREE)
+	      gen_type_die_for_member (class_origin, decl_or_origin, context_die);
 
-	  /* And its containing namespace.  */
-	  context_die = declare_in_namespace (decl_or_origin, context_die);
-	}
+	    /* And its containing namespace.  */
+	    context_die = declare_in_namespace (decl_or_origin, context_die);
+	  }
+      }
 
       /* Now output the DIE to represent the data object itself.  This gets
 	 complicated because of the possibility that the VAR_DECL really
@@ -26831,8 +26838,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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3] debug/93751 Generate DIEs for external variables with -g1
  2020-03-14  8:04                   ` [PATCH v3] debug/93751 Generate DIEs for external variables with -g1 Alexey Neyman
@ 2020-03-14 11:53                     ` Alexander Monakov
  2020-03-15  0:05                       ` [PATCH v4] " Alexey Neyman
  0 siblings, 1 reply; 17+ messages in thread
From: Alexander Monakov @ 2020-03-14 11:53 UTC (permalink / raw)
  To: Alexey Neyman; +Cc: Jason Merrill, Eric Botcazou, gcc-patches

On Sat, 14 Mar 2020, Alexey Neyman wrote:
> Attached is a patch that does it: at -g1, the type attributes are not
> generated.

Two small issues I pointed out the last time are still present:
https://gcc.gnu.org/legacy-ml/gcc-patches/2020-02/msg01646.html

(I did not review the new patch on a more substantial level)

Alexander

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v4] debug/93751 Generate DIEs for external variables with -g1
  2020-03-14 11:53                     ` Alexander Monakov
@ 2020-03-15  0:05                       ` Alexey Neyman
  2020-03-18  1:23                         ` Jason Merrill
  0 siblings, 1 reply; 17+ messages in thread
From: Alexey Neyman @ 2020-03-15  0:05 UTC (permalink / raw)
  To: Alexander Monakov; +Cc: Jason Merrill, Eric Botcazou, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 767 bytes --]

On 3/14/20 4:53 AM, Alexander Monakov wrote:
> On Sat, 14 Mar 2020, Alexey Neyman wrote:
>> Attached is a patch that does it: at -g1, the type attributes are not
>> generated.
> Two small issues I pointed out the last time are still present:
> https://gcc.gnu.org/legacy-ml/gcc-patches/2020-02/msg01646.html
>
> (I did not review the new patch on a more substantial level)

Sorry, I seem to have missed your previous email. Fixed in the attached 
patch.

- pr93751-3.c in the commit message is a remnant from v1 of the patch 
(which implemented a separate option to enable DIEs for external 
variables). Dropped the mention of it from the commit message.

- Added spaces before parentheses in macro invocations. Finger memory is 
hard to overcome.

Regards,
Alexey.


[-- Attachment #2: 0001-debug-93751-DWARF-DIEs-for-external-vars-with-g1.patch --]
[-- Type: text/x-patch, Size: 6593 bytes --]

From 17c8b252ad3b87388f1f1809d188c159911056a0 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. Do not
        generate type info.
        (dwarf2out_decl): Same.
        (add_type_attribute): Return immediately if debug level is
        terse.
        * gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1: New test.
        * gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2: New test.

Signed-off-by: Alexey Neyman <stilor@att.net>
---
 gcc/dwarf2out.c                               | 73 +++++++++++--------
 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1.c |  6 ++
 gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2.c |  6 ++
 3 files changed, 53 insertions(+), 32 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..89e52a41508 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -21562,6 +21562,9 @@ add_type_attribute (dw_die_ref object_die, tree type, int cv_quals,
   enum tree_code code  = TREE_CODE (type);
   dw_die_ref type_die  = NULL;
 
+  if (debug_info_level <= DINFO_LEVEL_TERSE)
+    return;
+
   /* ??? If this type is an unnamed subrange type of an integral, floating-point
      or fixed-point type, use the inner type.  This is because we have no
      support for unnamed types in base_type_die.  This can happen if this is
@@ -26354,40 +26357,44 @@ 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.
-         All types have been dumped early.  */
-      if (early_dwarf
-	  /* ???  But in LTRANS we cannot annotate early created variably
-	     modified type DIEs without copying them and adjusting all
-	     references to them.  Dump them again as happens for inlining
-	     which copies both the decl and the types.  */
-	  /* ???  And even non-LTO needs to re-visit type DIEs to fill
-	     in VLA bound information for example.  */
-	  || (decl && variably_modified_type_p (TREE_TYPE (decl),
-						current_function_decl)))
-	{
-	  /* Output any DIEs that are needed to specify the type of this data
-	     object.  */
-	  if (decl_by_reference_p (decl_or_origin))
-	    gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
-	  else
-	    gen_type_die (TREE_TYPE (decl_or_origin), context_die);
-	}
+      if (debug_info_level > DINFO_LEVEL_TERSE) {
+	/* Avoid generating stray type DIEs during late dwarf dumping.
+	   All types have been dumped early.  */
+	if (early_dwarf
+	    /* ???  But in LTRANS we cannot annotate early created variably
+	       modified type DIEs without copying them and adjusting all
+	       references to them.  Dump them again as happens for inlining
+	       which copies both the decl and the types.  */
+	    /* ???  And even non-LTO needs to re-visit type DIEs to fill
+	       in VLA bound information for example.  */
+	    || (decl && variably_modified_type_p (TREE_TYPE (decl),
+						  current_function_decl)))
+	  {
+	    /* Output any DIEs that are needed to specify the type of this data
+	       object.  */
+	    if (decl_by_reference_p (decl_or_origin))
+	      gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
+	    else
+	      gen_type_die (TREE_TYPE (decl_or_origin), context_die);
+	  }
 
-      if (early_dwarf)
-	{
-	  /* And its containing type.  */
-	  class_origin = decl_class_context (decl_or_origin);
-	  if (class_origin != NULL_TREE)
-	    gen_type_die_for_member (class_origin, decl_or_origin, context_die);
+	if (early_dwarf)
+	  {
+	    /* And its containing type.  */
+	    class_origin = decl_class_context (decl_or_origin);
+	    if (class_origin != NULL_TREE)
+	      gen_type_die_for_member (class_origin, decl_or_origin, context_die);
 
-	  /* And its containing namespace.  */
-	  context_die = declare_in_namespace (decl_or_origin, context_die);
-	}
+	    /* And its containing namespace.  */
+	    context_die = declare_in_namespace (decl_or_origin, context_die);
+	  }
+      }
 
       /* Now output the DIE to represent the data object itself.  This gets
 	 complicated because of the possibility that the VAR_DECL really
@@ -26831,8 +26838,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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v4] debug/93751 Generate DIEs for external variables with -g1
  2020-03-15  0:05                       ` [PATCH v4] " Alexey Neyman
@ 2020-03-18  1:23                         ` Jason Merrill
  0 siblings, 0 replies; 17+ messages in thread
From: Jason Merrill @ 2020-03-18  1:23 UTC (permalink / raw)
  To: Alexey Neyman, Alexander Monakov; +Cc: Eric Botcazou, gcc-patches

On 3/14/20 8:05 PM, Alexey Neyman wrote:
> +      if (debug_info_level > DINFO_LEVEL_TERSE) {

{ goes on the next line.

It looks like you don't have commit access, so I committed the patch 
with that change.

Thanks,
Jason


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-03-18  1:23 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <d60f5b48-fdff-451a-0ca9-cf90e610c31a.ref@att.net>
2020-02-19 23:31 ` [PATCH v2] debug/93751 Option to generate DIEs for external variables Alexey Neyman
2020-02-26 19:02   ` [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping Alexey Neyman
2020-02-26 19:14     ` Jason Merrill
2020-02-26 19:26       ` Alexander Monakov
2020-02-26 20:14         ` Richard Biener
2020-02-28 17:20           ` [PATCH v3] " Alexey Neyman
2020-02-28 17:35             ` Alexander Monakov
2020-02-28 17:39         ` [PATCH v2] " Eric Botcazou
2020-02-28 19:11           ` Alexander Monakov
2020-02-28 20:29             ` Jason Merrill
2020-02-28 21:13               ` Alexey Neyman
2020-02-28 21:15                 ` Alexey Neyman
2020-02-28 21:51                 ` Jason Merrill
2020-03-14  8:04                   ` [PATCH v3] debug/93751 Generate DIEs for external variables with -g1 Alexey Neyman
2020-03-14 11:53                     ` Alexander Monakov
2020-03-15  0:05                       ` [PATCH v4] " Alexey Neyman
2020-03-18  1:23                         ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).