From 52b3aa8be18938486065f5f2a23553b134a10a81 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sat, 14 Mar 2020 17:05:36 -0700 Subject: [PATCH] dwarf: Generate DIEs for external variables with -g1 [93751] -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. gcc/ChangeLog 2020-03-17 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. Signed-off-by: Alexey Neyman --- gcc/ChangeLog | 10 +++ gcc/dwarf2out.c | 70 +++++++++++-------- gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-1.c | 6 ++ gcc/testsuite/gcc.dg/debug/dwarf2/pr93751-2.c | 6 ++ 4 files changed, 62 insertions(+), 30 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/ChangeLog b/gcc/ChangeLog index 642954d93f1..e1c4da2b7ef 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2020-03-17 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. + 2020-03-17 Richard Sandiford * config/aarch64/iterators.md (Vmtype): Handle V4BF and V8BF. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 0c8606ae29c..b1fa6f5ff7c 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -21563,6 +21563,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 @@ -26355,39 +26358,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))) + if (debug_info_level > DINFO_LEVEL_TERSE) { - /* 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); - } + /* 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 @@ -26832,8 +26840,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.30.2