[PATCH] debug/93751 Generate DIEs for external variables with -g1

2020-02-14 Thread Alexey Neyman

Hi all,

As reported here, https://gcc.gnu.org/ml/gcc-help/2020-02/msg00062.html, 
GCC does not behave according to manual when `-gdwarf -g1` options are 
used; it does not generate the debugging information for external 
variables even though it is supposed to (and it does so for other 
debugging formats):


aneyman@supox:/tmp$ cat foo.c
int foo __attribute__((externally_visible));
aneyman@supox:/tmp$ gcc -c -O2 -gdwarf -g1 foo.c
aneyman@supox:/tmp$ readelf -wi foo.o
aneyman@supox:/tmp$ gcc -c -O2 -gdwarf -g2 foo.c
aneyman@supox:/tmp$ readelf -wi foo.o
...
<1><1d>: Abbrev Number: 2 (DW_TAG_variable)
    <1e>   DW_AT_name    : foo


The attached patch fixes this issue.

Regards,
Alexey.

>From a4cdccf633c83746481daac5da088b07843c6c38 Mon Sep 17 00:00:00 2001
From: Alexey Neyman 
Date: Thu, 13 Feb 2020 22:01:10 -0800
Subject: [PATCH] debug/93751 Create 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 aligns the behavior of `-gdwarf -g1` with the
description in the manual.

2020-02-14  Alexey Neyman  

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.

Signed-off-by: Alexey Neyman 
---
 gcc/dwarf2out.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index fe46c7e1eee..5f9e82a8da2 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 except for public ones.  */
+  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 except public ones.  */
+  if (debug_info_level < DINFO_LEVEL_TERSE
+	  || (debug_info_level == DINFO_LEVEL_TERSE
+	  && !TREE_PUBLIC(decl)))
 	return;
   break;
 
-- 
2.20.1



Re: [PATCH] debug/93751 Generate DIEs for external variables with -g1

2020-02-14 Thread Alexey Neyman

On 2/14/20 4:36 PM, Alexey Neyman wrote:

Hi all,

As reported here, 
https://gcc.gnu.org/ml/gcc-help/2020-02/msg00062.html, GCC does not 
behave according to manual when `-gdwarf -g1` options are used; it 
does not generate the debugging information for external variables 
even though it is supposed to (and it does so for other debugging 
formats):


aneyman@supox:/tmp$ cat foo.c
int foo __attribute__((externally_visible));


Just as a clarification, the __attribute__((externally_visible)) is not 
needed; this is copied from the original bug report to gcc-help mailing 
list where it indicated that neither external linkage nor this attribute 
made GCC behave as described in the manual.



Regards,
Alexey.



aneyman@supox:/tmp$ gcc -c -O2 -gdwarf -g1 foo.c
aneyman@supox:/tmp$ readelf -wi foo.o
aneyman@supox:/tmp$ gcc -c -O2 -gdwarf -g2 foo.c
aneyman@supox:/tmp$ readelf -wi foo.o
...
<1><1d>: Abbrev Number: 2 (DW_TAG_variable)
    <1e>   DW_AT_name    : foo


The attached patch fixes this issue.

Regards,
Alexey.



[PATCH v2] debug/93751 Option to generate DIEs for external variables

2020-02-19 Thread Alexey Neyman

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.

>From 7a1b7d99a98416ed8b1c8bf2e4877655fd820fd0 Mon Sep 17 00:00:00 2001
From: Alexey Neyman 
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  

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 
---
 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 o

Re: [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping

2020-02-26 Thread Alexey Neyman

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.

>From 7a1b7d99a98416ed8b1c8bf2e4877655fd820fd0 Mon Sep 17 00:00:00 2001
From: Alexey Neyman 
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  

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 
---
 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 gene

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

2020-02-28 Thread Alexey Neyman

On 2/26/20 11:40 AM, Richard Biener wrote:


On February 26, 2020 8:26:06 PM GMT+01:00, Alexander Monakov 
 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.

>From eba778fd7c2489e2966c55bb8c11bdc48480fc52 Mon Sep 17 00:00:00 2001
From: Alexey Neyman 
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  

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



Re: [PATCH v2] debug/93751 Option to generate DIEs for external variables - ping

2020-02-28 Thread Alexey Neyman



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



[PATCH v3] debug/93751 Generate DIEs for external variables with -g1

2020-03-14 Thread Alexey Neyman

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.
>From eae5ba4be1d574a515fa255d049327211afd8123 Mon Sep 17 00:00:00 2001
From: Alexey Neyman 
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  

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 
---
 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 withou

[PATCH v4] debug/93751 Generate DIEs for external variables with -g1

2020-03-14 Thread Alexey Neyman

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.

>From 17c8b252ad3b87388f1f1809d188c159911056a0 Mon Sep 17 00:00:00 2001
From: Alexey Neyman 
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  

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

[PATCH] Fix build with ISL 0.20

2018-09-25 Thread Alexey Neyman

Hi,

A trivial patch that fixes the build against the latest ISL release, 
0.20. In that release,  and  were split in two 
headers each. The  (included from  which is 
included by "graphite.h") now includes  and 
;  and  must be included explicitly.


These headers ( and ) are present in all 
supported versions of ISL (0.15 and later).


Bootstrapped on x86_64-pc-linux-gnu.

Regards,
Alexey.

>From d4f0e6b43aecb4542b1fd6483874ff4cec684f6a Mon Sep 17 00:00:00 2001
From: Alexey Neyman 
Date: Mon, 24 Sep 2018 22:50:11 -0700
Subject: Fix build with ISL 0.20

	* gcc/graphite.h: Include  and ; these
	headers are no longer pulled in by .

Signed-off-by: Alexey Neyman 
---
 gcc/ChangeLog  | 5 +
 gcc/graphite.h | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6be143e9f18..320e3731932 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2018-09-25  Alexey Neyman  
+
+	* gcc/graphite.h: Include  and ; these
+	headers are no longer pulled in by .
+
 2018-09-25  Richard Biener  
 
 	PR debug/83941
diff --git a/gcc/graphite.h b/gcc/graphite.h
index be0a22b3894..8db5700e03f 100644
--- a/gcc/graphite.h
+++ b/gcc/graphite.h
@@ -26,6 +26,8 @@ along with GCC; see the file COPYING3.  If not see
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.14.1



Re: [PATCH] Fix build with ISL 0.20

2018-09-26 Thread Alexey Neyman

On 09/26/2018 07:46 AM, Jeff Law wrote:

On 9/26/18 8:43 AM, Richard Biener wrote:

On Wed, Sep 26, 2018 at 4:10 PM Jeff Law  wrote:

On 9/25/18 1:07 PM, Alexey Neyman wrote:

Hi,

A trivial patch that fixes the build against the latest ISL release,
0.20. In that release,  and  were split in two
headers each. The  (included from  which is
included by "graphite.h") now includes  and
;  and  must be included explicitly.

These headers ( and ) are present in all
supported versions of ISL (0.15 and later).

Bootstrapped on x86_64-pc-linux-gnu.

Thanks for verifying these are in ISL 0.15 and later -- we recommend
0.18 these days, so I think this is fine.

Installed on the trunk

I think this was fixed already in August:

2018-08-01  Richard Biener  

 PR bootstrap/86724
 * graphite.h: Include isl/id.h and isl/space.h to allow build
 with ISL 0.20.

and also backported to branches.

You're right!  I'll revert.


Indeed, sorry for the noise. I noticed that the currently released 
versions failed to build, grepped for  in trunk - which 
yielded nothing due to a typo. So I just applied the same patch and 
verified it built.


Sorry again,
Alexey.