diff mbox series

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

Message ID b5291bc5-5fef-0b34-64ed-80ab80974fb3@att.net
State New
Headers show
Series [v3] debug/93751 Generate DIEs for external variables with -g1 | expand

Commit Message

Alexey Neyman March 14, 2020, 8:04 a.m. UTC
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.

Comments

Li, Pan2 via Gcc-patches March 14, 2020, 11:53 a.m. UTC | #1
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
diff mbox series

Patch

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