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

2020-03-17 Thread Jason Merrill via 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



[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);
+	else
+	  gen_type_die (TREE_TYPE