This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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 <stilor@att.net>
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  <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.

Signed-off-by: Alexey Neyman <stilor@att.net>
---
 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]