From e967adf4e25eb7497495886aa4c3b9460219cd2d Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 22 Jul 2011 22:03:33 +0200 Subject: [PATCH] re PR other/32998 (-frecord-gcc-switches issues) PR other/32998 * common.opt (grecord-gcc-switches, gno-record-gcc-switches): New options. * dwarf2out.c: Include opts.h. (dchar_p): New typedef. Define heap VEC for it. (producer_string): New variable. (gen_producer_string): New function. (gen_compile_unit_die): Use it. (dwarf2out_finish): Fix up comp_unit_die () DW_AT_producer if needed. * Makefile.in (dwarf2out.o): Depend on $(OPTS_H). * doc/invoke.texi: Document -grecord-gcc-switches and -gno-record-gcc-switches, add a -grecord-gcc-switches reference to -frecord-gcc-switches description. From-SVN: r176652 --- gcc/ChangeLog | 17 ++++++ gcc/Makefile.in | 2 +- gcc/common.opt | 8 +++ gcc/doc/invoke.texi | 21 ++++++- gcc/dwarf2out.c | 139 +++++++++++++++++++++++++++++++++++++++----- 5 files changed, 169 insertions(+), 18 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 36f4ea1d968..7fd289f84a4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,20 @@ +2011-07-22 Jakub Jelinek + + PR other/32998 + * common.opt (grecord-gcc-switches, gno-record-gcc-switches): New + options. + * dwarf2out.c: Include opts.h. + (dchar_p): New typedef. Define heap VEC for it. + (producer_string): New variable. + (gen_producer_string): New function. + (gen_compile_unit_die): Use it. + (dwarf2out_finish): Fix up comp_unit_die () DW_AT_producer + if needed. + * Makefile.in (dwarf2out.o): Depend on $(OPTS_H). + * doc/invoke.texi: Document -grecord-gcc-switches and + -gno-record-gcc-switches, add a -grecord-gcc-switches reference + to -frecord-gcc-switches description. + 2011-07-22 Jason Merrill PR c++/30112 diff --git a/gcc/Makefile.in b/gcc/Makefile.in index d924fb66cd6..83cfb8ceb41 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2954,7 +2954,7 @@ dwarf2out.o : dwarf2out.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ $(GGC_H) $(EXCEPT_H) dwarf2asm.h $(TM_P_H) langhooks.h $(HASHTAB_H) \ gt-dwarf2out.h $(TARGET_H) $(CGRAPH_H) $(MD5_H) $(INPUT_H) $(FUNCTION_H) \ $(GIMPLE_H) $(TREE_PASS_H) $(TREE_FLOW_H) $(CFGLAYOUT_H) \ - tree-pretty-print.h $(COMMON_TARGET_H) + tree-pretty-print.h $(COMMON_TARGET_H) $(OPTS_H) dwarf2cfi.o : dwarf2cfi.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ version.h $(RTL_H) $(FUNCTION_H) $(DWARF2_H) dwarf2asm.h dwarf2out.h \ $(GGC_H) $(TM_P_H) $(TARGET_H) $(TREE_PASS_H) diff --git a/gcc/common.opt b/gcc/common.opt index f1279369906..63331d30ecc 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2184,6 +2184,14 @@ ggdb Common JoinedOrMissing Generate debug information in default extended format +gno-record-gcc-switches +Common RejectNegative Var(dwarf_record_gcc_switches,0) Init(0) +Don't record gcc command line switches in DWARF DW_AT_producer. + +grecord-gcc-switches +Common RejectNegative Var(dwarf_record_gcc_switches,1) +Record gcc command line switches in DWARF DW_AT_producer. + gstabs Common JoinedOrMissing Negative(gstabs+) Generate debug information in STABS format diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index ddad55b303f..e56eeaa732b 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -11,7 +11,7 @@ @c man begin COPYRIGHT Copyright @copyright{} 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, -1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 +1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document @@ -328,7 +328,8 @@ Objective-C and Objective-C++ Dialects}. -fstack-usage -ftest-coverage -ftime-report -fvar-tracking @gol -fvar-tracking-assignments -fvar-tracking-assignments-toggle @gol -g -g@var{level} -gtoggle -gcoff -gdwarf-@var{version} @gol --ggdb -gstabs -gstabs+ -gstrict-dwarf -gno-strict-dwarf @gol +-ggdb -grecord-gcc-switches -gno-record-gcc-switches @gol +-gstabs -gstabs+ -gstrict-dwarf -gno-strict-dwarf @gol -gvms -gxcoff -gxcoff+ @gol -fno-merge-debug-strings -fno-dwarf2-cfi-asm @gol -fdebug-prefix-map=@var{old}=@var{new} @gol @@ -4687,6 +4688,20 @@ use, some non-conflicting DWARF 3 extensions in the unwind tables. Version 4 may require GDB 7.0 and @option{-fvar-tracking-assignments} for maximum benefit. +@item -grecord-gcc-switches +@opindex grecord-gcc-switches +This switch causes the command line options, that were used to invoke the +compiler and may affect code generation, to be appended to the +DW_AT_producer attribute in DWARF debugging information. The options +are concatenated with spaces separating them from each other and from +the compiler version. See also @option{-frecord-gcc-switches} for another +way of storing compiler options into the object file. + +@item -gno-record-gcc-switches +@opindex gno-record-gcc-switches +Disallow appending command line options to the DW_AT_producer attribute +in DWARF debugging information. This is the default. + @item -gstrict-dwarf @opindex gstrict-dwarf Disallow using extensions of later DWARF standard version than selected @@ -18029,6 +18044,8 @@ usually takes the form of a section containing ASCII text. This switch is related to the @option{-fverbose-asm} switch, but that switch only records information in the assembler output file as comments, so it never reaches the object file. +See also @option{-grecord-gcc-switches} for another +way of storing compiler options into the object file. @item -fpic @opindex fpic diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 6046ba9c6ab..41e8040b0ef 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -94,6 +94,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-pass.h" #include "tree-flow.h" #include "cfglayout.h" +#include "opts.h" static void dwarf2out_source_line (unsigned int, const char *, int, bool); static rtx last_var_location_insn; @@ -18108,13 +18109,123 @@ gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die) add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); } +typedef const char *dchar_p; /* For DEF_VEC_P. */ +DEF_VEC_P(dchar_p); +DEF_VEC_ALLOC_P(dchar_p,heap); + +static char *producer_string; + +/* Return a heap allocated producer string including command line options + if -grecord-gcc-switches. */ + +static char * +gen_producer_string (void) +{ + size_t j; + VEC(dchar_p, heap) *switches = NULL; + const char *language_string = lang_hooks.name; + char *producer, *tail; + const char *p; + size_t len = dwarf_record_gcc_switches ? 0 : 3; + size_t plen = strlen (language_string) + 1 + strlen (version_string); + + for (j = 1; dwarf_record_gcc_switches && j < save_decoded_options_count; j++) + switch (save_decoded_options[j].opt_index) + { + case OPT_o: + case OPT_d: + case OPT_dumpbase: + case OPT_dumpdir: + case OPT_auxbase: + case OPT_auxbase_strip: + case OPT_quiet: + case OPT_version: + case OPT_v: + case OPT_w: + case OPT_L: + case OPT_D: + case OPT_I: + case OPT_U: + case OPT_SPECIAL_unknown: + case OPT_SPECIAL_ignore: + case OPT_SPECIAL_program_name: + case OPT_SPECIAL_input_file: + case OPT_grecord_gcc_switches: + case OPT_gno_record_gcc_switches: + case OPT__output_pch_: + case OPT_fdiagnostics_show_location_: + case OPT_fdiagnostics_show_option: + case OPT____: + case OPT__sysroot_: + case OPT_nostdinc: + case OPT_nostdinc__: + /* Ignore these. */ + continue; + default: + gcc_checking_assert (save_decoded_options[j].canonical_option[0][0] + == '-'); + switch (save_decoded_options[j].canonical_option[0][1]) + { + case 'M': + case 'i': + case 'W': + continue; + case 'f': + if (strncmp (save_decoded_options[j].canonical_option[0] + 2, + "dump", 4) == 0) + continue; + break; + default: + break; + } + VEC_safe_push (dchar_p, heap, switches, + save_decoded_options[j].orig_option_with_args_text); + len += strlen (save_decoded_options[j].orig_option_with_args_text) + 1; + break; + } + + producer = XNEWVEC (char, plen + 1 + len + 1); + tail = producer; + sprintf (tail, "%s %s", language_string, version_string); + tail += plen; + + if (!dwarf_record_gcc_switches) + { +#ifdef MIPS_DEBUGGING_INFO + /* The MIPS/SGI compilers place the 'cc' command line options in the + producer string. The SGI debugger looks for -g, -g1, -g2, or -g3; + if they do not appear in the producer string, the debugger reaches + the conclusion that the object file is stripped and has no debugging + information. To get the MIPS/SGI debugger to believe that there is + debugging information in the object file, we add a -g to the producer + string. */ + if (debug_info_level > DINFO_LEVEL_TERSE) + { + memcpy (tail, " -g", 3); + tail += 3; + } +#endif + } + + FOR_EACH_VEC_ELT (dchar_p, switches, j, p) + { + len = strlen (p); + *tail = ' '; + memcpy (tail + 1, p, len); + tail += len + 1; + } + + *tail = '\0'; + VEC_free (dchar_p, heap, switches); + return producer; +} + /* Generate the DIE for the compilation unit. */ static dw_die_ref gen_compile_unit_die (const char *filename) { dw_die_ref die; - char producer[250]; const char *language_string = lang_hooks.name; int language; @@ -18128,20 +18239,9 @@ gen_compile_unit_die (const char *filename) add_comp_dir_attribute (die); } - sprintf (producer, "%s %s", language_string, version_string); - -#ifdef MIPS_DEBUGGING_INFO - /* The MIPS/SGI compilers place the 'cc' command line options in the producer - string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do - not appear in the producer string, the debugger reaches the conclusion - that the object file is stripped and has no debugging information. - To get the MIPS/SGI debugger to believe that there is debugging - information in the object file, we add a -g to the producer string. */ - if (debug_info_level > DINFO_LEVEL_TERSE) - strcat (producer, " -g"); -#endif - - add_AT_string (die, DW_AT_producer, producer); + if (producer_string == NULL) + producer_string = gen_producer_string (); + add_AT_string (die, DW_AT_producer, producer_string); /* If our producer is LTO try to figure out a common language to use from the global list of translation units. */ @@ -21774,6 +21874,15 @@ dwarf2out_finish (const char *filename) htab_t comdat_type_table; unsigned int i; + /* PCH might result in DW_AT_producer string being restored from the + header compilation, fix it up if needed. */ + dw_attr_ref producer = get_AT (comp_unit_die (), DW_AT_producer); + if (strcmp (AT_string (producer), producer_string) != 0) + { + struct indirect_string_node *node = find_AT_string (producer_string); + producer->dw_attr_val.v.val_str = node; + } + gen_scheduled_generic_parms_dies (); gen_remaining_tmpl_value_param_die_attribute (); -- 2.30.2