http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48229
--- Comment #2 from Dodji Seketeli <dodji at gcc dot gnu.org> 2011-03-23 11:28:28 UTC --- This is a very lightly tested patch to add the DW_AT_producer attribute to the DW_TAG_type_unit DIE. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index f62bb48..ff1adc3 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -6498,6 +6498,7 @@ static inline int local_scope_p (dw_die_ref); static inline int class_scope_p (dw_die_ref); static inline int class_or_namespace_scope_p (dw_die_ref); static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref); +static void add_producer_attribute (dw_die_ref); static void add_calling_convention_attribute (dw_die_ref, tree); static const char *type_tag (const_tree); static tree member_declared_type (const_tree); @@ -10298,6 +10299,13 @@ break_out_comdat_types (dw_die_ref die) unit = new_die (DW_TAG_type_unit, NULL, NULL); add_AT_unsigned (unit, DW_AT_language, get_AT_unsigned (comp_unit_die (), DW_AT_language)); + + /* Add a DW_AT_producer attribute. This is not mandated by + the DWARF-4 specification. But it appears that GDB needs + it for cases where different DW_TAG_type_unit DIEs might + be emitted by different compilers. */ + add_producer_attribute (unit); + type_node = ggc_alloc_cleared_comdat_type_node (); type_node->root_die = unit; type_node->next = comdat_type_list; @@ -18014,6 +18022,28 @@ add_type_attribute (dw_die_ref object_die, tree type, int decl_const, add_AT_die_ref (object_die, DW_AT_type, type_die); } +/* Add an DW_AT_producer attribute to a given DIE. */ + +static void +add_producer_attribute (dw_die_ref die) +{ + char producer[250]; + const char *language_string = lang_hooks.name; + + 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); +} + /* Given an object die, add the calling convention attribute for the function call type. */ static void @@ -20101,7 +20131,6 @@ 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; @@ -20114,21 +20143,8 @@ gen_compile_unit_die (const char *filename) if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<') 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); + + add_producer_attribute (die); /* If our producer is LTO try to figure out a common language to use from the global list of translation units. */