X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;ds=sidebyside;f=gcc%2Fdwarf2out.c;h=b99e45bc36798a50452722f311112e5ce150e38c;hb=7756de4a8afcb59df241b42f32e94193ff9d444b;hp=835e4ecd88405133af7370959c17604d791a9791;hpb=559e966b0d135d4c8ae5904d5cd206a2487f0fdd;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 835e4ecd884..b99e45bc367 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -1,6 +1,6 @@ /* Output Dwarf2 format symbol table information from GCC. Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, - 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 + 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. Contributed by Gary Funck (gary@intrepid.com). Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com). @@ -94,9 +94,11 @@ 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; +static rtx cached_next_real_insn; #ifdef VMS_DEBUGGING_INFO int vms_file_stats_name (const char *, long long *, long *, char *, int *); @@ -518,11 +520,9 @@ output_fde (dw_fde_ref fde, bool for_eh, bool second, char *section_start_label, int fde_encoding, char *augmentation, bool any_lsda_needed, int lsda_encoding) { - int ix; const char *begin, *end; static unsigned int j; char l1[20], l2[20]; - dw_cfi_ref cfi; targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0); @@ -602,36 +602,24 @@ output_fde (dw_fde_ref fde, bool for_eh, bool second, dw2_asm_output_data_uleb128 (0, "Augmentation size"); } - /* Loop through the Call Frame Instructions associated with - this FDE. */ + /* Loop through the Call Frame Instructions associated with this FDE. */ fde->dw_fde_current_label = begin; - if (fde->dw_fde_second_begin == NULL) - FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi) - output_cfi (cfi, fde, for_eh); - else if (!second) - { - if (fde->dw_fde_switch_cfi_index > 0) - FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi) - { - if (ix == fde->dw_fde_switch_cfi_index) - break; - output_cfi (cfi, fde, for_eh); - } - } - else - { - int i, from = 0; - int until = VEC_length (dw_cfi_ref, fde->dw_fde_cfi); + { + size_t from, until, i; - if (fde->dw_fde_switch_cfi_index > 0) - { - from = fde->dw_fde_switch_cfi_index; - output_cfis (fde->dw_fde_cfi, from, false, fde, for_eh); - } - for (i = from; i < until; i++) - output_cfi (VEC_index (dw_cfi_ref, fde->dw_fde_cfi, i), - fde, for_eh); - } + from = 0; + until = VEC_length (dw_cfi_ref, fde->dw_fde_cfi); + + if (fde->dw_fde_second_begin == NULL) + ; + else if (!second) + until = fde->dw_fde_switch_cfi_index; + else + from = fde->dw_fde_switch_cfi_index; + + for (i = from; i < until; i++) + output_cfi (VEC_index (dw_cfi_ref, fde->dw_fde_cfi, i), fde, for_eh); + } /* If we are to emit a ref/link from function bodies to their frame tables, do it now. This is typically performed to make sure that tables @@ -1103,6 +1091,7 @@ dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED, char label[MAX_ARTIFICIAL_LABEL_BYTES]; last_var_location_insn = NULL_RTX; + cached_next_real_insn = NULL_RTX; if (dwarf2out_do_cfi_asm ()) fprintf (asm_out_file, "\t.cfi_endproc\n"); @@ -1183,20 +1172,13 @@ dwarf2out_switch_text_section (void) = (sect == text_section || (cold_text_section && sect == cold_text_section)); - fde->dw_fde_switch_cfi_index = VEC_length (dw_cfi_ref, fde->dw_fde_cfi); - if (dwarf2out_do_cfi_asm ()) - { - dwarf2out_do_cfi_startproc (true); - /* As this is a different FDE, insert all current CFI instructions - again. */ - output_cfis (fde->dw_fde_cfi, fde->dw_fde_switch_cfi_index, - true, fde, true); - } + dwarf2out_do_cfi_startproc (true); var_location_switch_text_section (); - set_cur_line_info_table (sect); + if (cold_text_section != NULL) + set_cur_line_info_table (sect); } /* And now, the subset of the debugging information support code necessary @@ -1638,6 +1620,109 @@ add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr) *d = descr; } +/* Compare two location operands for exact equality. */ + +static bool +dw_val_equal_p (dw_val_node *a, dw_val_node *b) +{ + if (a->val_class != b->val_class) + return false; + switch (a->val_class) + { + case dw_val_class_none: + return true; + case dw_val_class_addr: + return rtx_equal_p (a->v.val_addr, b->v.val_addr); + + case dw_val_class_offset: + case dw_val_class_unsigned_const: + case dw_val_class_const: + case dw_val_class_range_list: + case dw_val_class_lineptr: + case dw_val_class_macptr: + /* These are all HOST_WIDE_INT, signed or unsigned. */ + return a->v.val_unsigned == b->v.val_unsigned; + + case dw_val_class_loc: + return a->v.val_loc == b->v.val_loc; + case dw_val_class_loc_list: + return a->v.val_loc_list == b->v.val_loc_list; + case dw_val_class_die_ref: + return a->v.val_die_ref.die == b->v.val_die_ref.die; + case dw_val_class_fde_ref: + return a->v.val_fde_index == b->v.val_fde_index; + case dw_val_class_lbl_id: + return strcmp (a->v.val_lbl_id, b->v.val_lbl_id) == 0; + case dw_val_class_str: + return a->v.val_str == b->v.val_str; + case dw_val_class_flag: + return a->v.val_flag == b->v.val_flag; + case dw_val_class_file: + return a->v.val_file == b->v.val_file; + case dw_val_class_decl_ref: + return a->v.val_decl_ref == b->v.val_decl_ref; + + case dw_val_class_const_double: + return (a->v.val_double.high == b->v.val_double.high + && a->v.val_double.low == b->v.val_double.low); + + case dw_val_class_vec: + { + size_t a_len = a->v.val_vec.elt_size * a->v.val_vec.length; + size_t b_len = b->v.val_vec.elt_size * b->v.val_vec.length; + + return (a_len == b_len + && !memcmp (a->v.val_vec.array, b->v.val_vec.array, a_len)); + } + + case dw_val_class_data8: + return memcmp (a->v.val_data8, b->v.val_data8, 8) == 0; + + case dw_val_class_vms_delta: + return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1) + && !strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1)); + } + gcc_unreachable (); +} + +/* Compare two location atoms for exact equality. */ + +static bool +loc_descr_equal_p_1 (dw_loc_descr_ref a, dw_loc_descr_ref b) +{ + if (a->dw_loc_opc != b->dw_loc_opc) + return false; + + /* ??? This is only ever set for DW_OP_constNu, for N equal to the + address size, but since we always allocate cleared storage it + should be zero for other types of locations. */ + if (a->dtprel != b->dtprel) + return false; + + return (dw_val_equal_p (&a->dw_loc_oprnd1, &b->dw_loc_oprnd1) + && dw_val_equal_p (&a->dw_loc_oprnd2, &b->dw_loc_oprnd2)); +} + +/* Compare two complete location expressions for exact equality. */ + +bool +loc_descr_equal_p (dw_loc_descr_ref a, dw_loc_descr_ref b) +{ + while (1) + { + if (a == b) + return true; + if (a == NULL || b == NULL) + return false; + if (!loc_descr_equal_p_1 (a, b)) + return false; + + a = a->dw_loc_next; + b = b->dw_loc_next; + } +} + + /* Add a constant OFFSET to a location expression. */ static void @@ -2770,7 +2855,7 @@ struct GTY(()) dw_ranges_struct { /* A structure to hold a macinfo entry. */ typedef struct GTY(()) macinfo_struct { - unsigned HOST_WIDE_INT code; + unsigned char code; unsigned HOST_WIDE_INT lineno; const char *info; } @@ -3049,6 +3134,12 @@ static GTY (()) VEC (pubname_entry, gc) * pubtype_table; defines/undefines (and file start/end markers). */ static GTY (()) VEC (macinfo_entry, gc) * macinfo_table; +/* True if .debug_macinfo or .debug_macros section is going to be + emitted. */ +#define have_macinfo \ + (debug_info_level >= DINFO_LEVEL_VERBOSE \ + && !VEC_empty (macinfo_entry, macinfo_table)) + /* Array of dies for which we should generate .debug_ranges info. */ static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table; @@ -3218,11 +3309,12 @@ static int should_move_die_to_comdat (dw_die_ref); static dw_die_ref clone_as_declaration (dw_die_ref); static dw_die_ref clone_die (dw_die_ref); static dw_die_ref clone_tree (dw_die_ref); -static void copy_declaration_context (dw_die_ref, dw_die_ref); +static dw_die_ref copy_declaration_context (dw_die_ref, dw_die_ref); static void generate_skeleton_ancestor_tree (skeleton_chain_node *); static void generate_skeleton_bottom_up (skeleton_chain_node *); static dw_die_ref generate_skeleton (dw_die_ref); static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref, + dw_die_ref, dw_die_ref); static void break_out_comdat_types (dw_die_ref); static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t); @@ -3417,6 +3509,9 @@ static void gen_scheduled_generic_parms_dies (void); #ifndef DEBUG_MACINFO_SECTION #define DEBUG_MACINFO_SECTION ".debug_macinfo" #endif +#ifndef DEBUG_MACRO_SECTION +#define DEBUG_MACRO_SECTION ".debug_macro" +#endif #ifndef DEBUG_LINE_SECTION #define DEBUG_LINE_SECTION ".debug_line" #endif @@ -3474,6 +3569,9 @@ static void gen_scheduled_generic_parms_dies (void); #ifndef DEBUG_MACINFO_SECTION_LABEL #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo" #endif +#ifndef DEBUG_MACRO_SECTION_LABEL +#define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro" +#endif /* Definitions of defaults for formats and names of various special @@ -4015,6 +4113,8 @@ dwarf_attr_name (unsigned int attr) return "DW_AT_GNU_all_call_sites"; case DW_AT_GNU_all_source_call_sites: return "DW_AT_GNU_all_source_call_sites"; + case DW_AT_GNU_macros: + return "DW_AT_GNU_macros"; case DW_AT_GNAT_descriptive_type: return "DW_AT_GNAT_descriptive_type"; @@ -6978,16 +7078,18 @@ clone_as_declaration (dw_die_ref die) return clone; } -/* Copy the declaration context to the new compile unit DIE. This includes +/* Copy the declaration context to the new type unit DIE. This includes any surrounding namespace or type declarations. If the DIE has an AT_specification attribute, it also includes attributes and children - attached to the specification. */ + attached to the specification, and returns a pointer to the original + parent of the declaration DIE. Returns NULL otherwise. */ -static void +static dw_die_ref copy_declaration_context (dw_die_ref unit, dw_die_ref die) { dw_die_ref decl; dw_die_ref new_decl; + dw_die_ref orig_parent = NULL; decl = get_AT_ref (die, DW_AT_specification); if (decl == NULL) @@ -6998,6 +7100,10 @@ copy_declaration_context (dw_die_ref unit, dw_die_ref die) dw_die_ref c; dw_attr_ref a; + /* The original DIE will be changed to a declaration, and must + be moved to be a child of the original declaration DIE. */ + orig_parent = decl->die_parent; + /* Copy the type node pointer from the new DIE to the original declaration DIE so we can forward references later. */ decl->die_id.die_type_node = die->die_id.die_type_node; @@ -7026,6 +7132,8 @@ copy_declaration_context (dw_die_ref unit, dw_die_ref die) add_AT_specification (die, new_decl); } } + + return orig_parent; } /* Generate the skeleton ancestor tree for the given NODE, then clone @@ -7109,17 +7217,23 @@ generate_skeleton (dw_die_ref die) return node.new_die; } -/* Remove the DIE from its parent, possibly replacing it with a cloned - declaration. The original DIE will be moved to a new compile unit - so that existing references to it follow it to the new location. If - any of the original DIE's descendants is a declaration, we need to - replace the original DIE with a skeleton tree and move the - declarations back into the skeleton tree. */ +/* Remove the CHILD DIE from its parent, possibly replacing it with a cloned + declaration. The original DIE is moved to a new compile unit so that + existing references to it follow it to the new location. If any of the + original DIE's descendants is a declaration, we need to replace the + original DIE with a skeleton tree and move the declarations back into the + skeleton tree. */ static dw_die_ref -remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev) +remove_child_or_replace_with_skeleton (dw_die_ref unit, dw_die_ref child, + dw_die_ref prev) { - dw_die_ref skeleton; + dw_die_ref skeleton, orig_parent; + + /* Copy the declaration context to the type unit DIE. If the returned + ORIG_PARENT is not NULL, the skeleton needs to be added as a child of + that DIE. */ + orig_parent = copy_declaration_context (unit, child); skeleton = generate_skeleton (child); if (skeleton == NULL) @@ -7127,7 +7241,19 @@ remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev) else { skeleton->die_id.die_type_node = child->die_id.die_type_node; - replace_child (child, skeleton, prev); + + /* If the original DIE was a specification, we need to put + the skeleton under the parent DIE of the declaration. + This leaves the original declaration in the tree, but + it will be pruned later since there are no longer any + references to it. */ + if (orig_parent != NULL) + { + remove_child_with_prev (child, prev); + add_child_die (orig_parent, skeleton); + } + else + replace_child (child, skeleton, prev); } return skeleton; @@ -7172,11 +7298,9 @@ break_out_comdat_types (dw_die_ref die) generate_type_signature (c, type_node); /* Copy the declaration context, attributes, and children of the - declaration into the new compile unit DIE. */ - copy_declaration_context (unit, c); - - /* Remove this DIE from the main CU. */ - replacement = remove_child_or_replace_with_skeleton (c, prev); + declaration into the new type unit DIE, then remove this DIE + from the main CU (or replace it with a skeleton if necessary). */ + replacement = remove_child_or_replace_with_skeleton (unit, c, prev); /* Break out nested types into their own type units. */ break_out_comdat_types (c); @@ -7289,6 +7413,32 @@ copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table) return copy; } +/* Like clone_tree, but additionally enter all the children into + the hash table decl_table. */ + +static dw_die_ref +clone_tree_hash (dw_die_ref die, htab_t decl_table) +{ + dw_die_ref c; + dw_die_ref clone = clone_die (die); + struct decl_table_entry *entry; + void **slot = htab_find_slot_with_hash (decl_table, die, + htab_hash_pointer (die), INSERT); + /* Assert that DIE isn't in the hash table yet. If it would be there + before, the ancestors would be necessarily there as well, therefore + clone_tree_hash wouldn't be called. */ + gcc_assert (*slot == HTAB_EMPTY_ENTRY); + entry = XCNEW (struct decl_table_entry); + entry->orig = die; + entry->copy = clone; + *slot = entry; + + FOR_EACH_CHILD (die, c, + add_child_die (clone, clone_tree_hash (c, decl_table))); + + return clone; +} + /* Walk the DIE and its children, looking for references to incomplete or trivial types that are unmarked (i.e., that are not in the current type_unit). */ @@ -7325,11 +7475,7 @@ copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table) else { dw_die_ref parent = unit; - dw_die_ref copy = clone_tree (targ); - - /* Make sure the cloned tree is marked as part of the - type unit. */ - mark_dies (copy); + dw_die_ref copy = clone_die (targ); /* Record in DECL_TABLE that TARG has been copied. Need to do this now, before the recursive call, @@ -7340,6 +7486,14 @@ copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table) entry->copy = copy; *slot = entry; + FOR_EACH_CHILD (targ, c, + add_child_die (copy, + clone_tree_hash (c, decl_table))); + + /* Make sure the cloned tree is marked as part of the + type unit. */ + mark_dies (copy); + /* If TARG has surrounding context, copy its ancestor tree into the new type unit. */ if (targ->die_parent != NULL @@ -7562,7 +7716,15 @@ size_of_die (dw_die_ref die) size += size_of_sleb128 (AT_int (a)); break; case dw_val_class_unsigned_const: - size += constant_size (AT_unsigned (a)); + { + int csize = constant_size (AT_unsigned (a)); + if (dwarf_version == 3 + && a->dw_attr == DW_AT_data_member_location + && csize >= 4) + size += size_of_uleb128 (AT_unsigned (a)); + else + size += csize; + } break; case dw_val_class_const_double: size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; @@ -7850,6 +8012,8 @@ value_format (dw_attr_ref a) return DW_FORM_block1; case 2: return DW_FORM_block2; + case 4: + return DW_FORM_block4; default: gcc_unreachable (); } @@ -7863,8 +8027,16 @@ value_format (dw_attr_ref a) case 2: return DW_FORM_data2; case 4: + /* In DWARF3 DW_AT_data_member_location with + DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not + constant, so we need to use DW_FORM_udata if we need + a large constant. */ + if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location) + return DW_FORM_udata; return DW_FORM_data4; case 8: + if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location) + return DW_FORM_udata; return DW_FORM_data8; default: gcc_unreachable (); @@ -8058,6 +8230,13 @@ output_loc_list (dw_loc_list_ref list_head) /* Don't output an entry that starts and ends at the same address. */ if (strcmp (curr->begin, curr->end) == 0 && !curr->force) continue; + size = size_of_locs (curr->expr); + /* If the expression is too large, drop it on the floor. We could + perhaps put it into DW_TAG_dwarf_procedure and refer to that + in the expression, but >= 64KB expressions for a single value + in a single range are unlikely very useful. */ + if (size > 0xffff) + continue; if (!have_multiple_function_sections) { dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, @@ -8076,7 +8255,6 @@ output_loc_list (dw_loc_list_ref list_head) "Location list end address (%s)", list_head->ll_symbol); } - size = size_of_locs (curr->expr); /* Output the block length for this list of location operations. */ gcc_assert (size <= 0xffff); @@ -8171,8 +8349,15 @@ output_die (dw_die_ref die) break; case dw_val_class_unsigned_const: - dw2_asm_output_data (constant_size (AT_unsigned (a)), - AT_unsigned (a), "%s", name); + { + int csize = constant_size (AT_unsigned (a)); + if (dwarf_version == 3 + && a->dw_attr == DW_AT_data_member_location + && csize >= 4) + dw2_asm_output_data_uleb128 (AT_unsigned (a), "%s", name); + else + dw2_asm_output_data (csize, AT_unsigned (a), "%s", name); + } break; case dw_val_class_const_double: @@ -9607,6 +9792,7 @@ modified_type_die (tree type, int is_const_type, int is_volatile_type, tree item_type = NULL; tree qualified_type; tree name, low, high; + dw_die_ref mod_scope; if (code == ERROR_MARK) return NULL; @@ -9667,6 +9853,8 @@ modified_type_die (tree type, int is_const_type, int is_volatile_type, /* Else cv-qualified version of named type; fall through. */ } + mod_scope = scope_die_for (type, context_die); + if (is_const_type /* If both is_const_type and is_volatile_type, prefer the path which leads to a qualified type. */ @@ -9674,17 +9862,17 @@ modified_type_die (tree type, int is_const_type, int is_volatile_type, || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE)) { - mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type); + mod_type_die = new_die (DW_TAG_const_type, mod_scope, type); sub_die = modified_type_die (type, 0, is_volatile_type, context_die); } else if (is_volatile_type) { - mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type); + mod_type_die = new_die (DW_TAG_volatile_type, mod_scope, type); sub_die = modified_type_die (type, is_const_type, 0, context_die); } else if (code == POINTER_TYPE) { - mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type); + mod_type_die = new_die (DW_TAG_pointer_type, mod_scope, type); add_AT_unsigned (mod_type_die, DW_AT_byte_size, simple_type_size_in_bits (type) / BITS_PER_UNIT); item_type = TREE_TYPE (type); @@ -9695,10 +9883,10 @@ modified_type_die (tree type, int is_const_type, int is_volatile_type, else if (code == REFERENCE_TYPE) { if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4) - mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (), + mod_type_die = new_die (DW_TAG_rvalue_reference_type, mod_scope, type); else - mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type); + mod_type_die = new_die (DW_TAG_reference_type, mod_scope, type); add_AT_unsigned (mod_type_die, DW_AT_byte_size, simple_type_size_in_bits (type) / BITS_PER_UNIT); item_type = TREE_TYPE (type); @@ -9752,13 +9940,17 @@ modified_type_die (tree type, int is_const_type, int is_volatile_type, useful source coordinates anyway. */ name = DECL_NAME (name); add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name)); - add_gnat_descriptive_type_attribute (mod_type_die, type, context_die); - if (TYPE_ARTIFICIAL (type)) - add_AT_flag (mod_type_die, DW_AT_artificial, 1); } /* This probably indicates a bug. */ else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type) - add_name_attribute (mod_type_die, "__unknown__"); + { + name = TYPE_NAME (type); + if (name + && TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + add_name_attribute (mod_type_die, + name ? IDENTIFIER_POINTER (name) : "__unknown__"); + } if (qualified_type) equate_type_number_to_die (qualified_type, mod_type_die); @@ -9776,6 +9968,10 @@ modified_type_die (tree type, int is_const_type, int is_volatile_type, if (sub_die != NULL) add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); + add_gnat_descriptive_type_attribute (mod_type_die, type, context_die); + if (TYPE_ARTIFICIAL (type)) + add_AT_flag (mod_type_die, DW_AT_artificial, 1); + return mod_type_die; } @@ -10406,10 +10602,20 @@ based_loc_descr (rtx reg, HOST_WIDE_INT offset, return new_loc_descr (DW_OP_fbreg, offset, 0); } } - else if (!optimize - && fde - && (fde->drap_reg == dwarf_frame_regnum (REGNO (reg)) - || fde->vdrap_reg == dwarf_frame_regnum (REGNO (reg)))) + + regno = REGNO (reg); +#ifdef LEAF_REG_REMAP + if (current_function_uses_only_leaf_regs) + { + int leaf_reg = LEAF_REG_REMAP (regno); + if (leaf_reg != -1) + regno = (unsigned) leaf_reg; + } +#endif + regno = DWARF_FRAME_REGNUM (regno); + + if (!optimize && fde + && (fde->drap_reg == regno || fde->vdrap_reg == regno)) { /* Use cfa+offset to represent the location of arguments passed on the stack when drap is used to align stack. @@ -10420,7 +10626,6 @@ based_loc_descr (rtx reg, HOST_WIDE_INT offset, return new_loc_descr (DW_OP_fbreg, offset, 0); } - regno = dbx_reg_number (reg); if (regno <= 31) result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno), offset, 0); @@ -10453,7 +10658,7 @@ tls_mem_loc_descriptor (rtx mem) tree base; dw_loc_descr_ref loc_result; - if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX) + if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem)) return NULL; base = get_base_address (MEM_EXPR (mem)); @@ -10466,8 +10671,8 @@ tls_mem_loc_descriptor (rtx mem) if (loc_result == NULL) return NULL; - if (INTVAL (MEM_OFFSET (mem))) - loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem))); + if (MEM_OFFSET (mem)) + loc_descr_plus_const (&loc_result, MEM_OFFSET (mem)); return loc_result; } @@ -10530,6 +10735,13 @@ const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED) return 1; } + if (targetm.const_not_ok_for_debug_p (rtl)) + { + expansion_failed (NULL_TREE, rtl, + "Expression rejected for debug by the backend.\n"); + return 1; + } + if (GET_CODE (rtl) != SYMBOL_REF) return 0; @@ -11582,12 +11794,22 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode, break; case MEM: + { + rtx new_rtl = avoid_constant_pool_reference (rtl); + if (new_rtl != rtl) + { + mem_loc_result = mem_loc_descriptor (new_rtl, mode, mem_mode, + initialized); + if (mem_loc_result != NULL) + return mem_loc_result; + } + } mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl), mode, VAR_INIT_STATUS_INITIALIZED); if (mem_loc_result == NULL) mem_loc_result = tls_mem_loc_descriptor (rtl); - if (mem_loc_result != 0) + if (mem_loc_result != NULL) { if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE || GET_MODE_CLASS (mode) != MODE_INT) @@ -11615,12 +11837,6 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode, new_loc_descr (DW_OP_deref_size, GET_MODE_SIZE (mode), 0)); } - else - { - rtx new_rtl = avoid_constant_pool_reference (rtl); - if (new_rtl != rtl) - return mem_loc_descriptor (new_rtl, mode, mem_mode, initialized); - } break; case LO_SUM: @@ -12385,7 +12601,8 @@ loc_descriptor (rtx rtl, enum machine_mode mode, legitimate to make the Dwarf info refer to the whole register which contains the given subreg. */ if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl)) - loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized); + loc_result = loc_descriptor (SUBREG_REG (rtl), + GET_MODE (SUBREG_REG (rtl)), initialized); else goto do_default; break; @@ -12876,7 +13093,7 @@ dw_sra_loc_expr (tree decl, rtx loc) if (MEM_P (varloc)) { unsigned HOST_WIDE_INT memsize - = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT; + = MEM_SIZE (varloc) * BITS_PER_UNIT; if (memsize != bitsize) { if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN @@ -15876,10 +16093,36 @@ pop_decl_scope (void) VEC_pop (tree, decl_scope_table); } +/* walk_tree helper function for uses_local_type, below. */ + +static tree +uses_local_type_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED) +{ + if (!TYPE_P (*tp)) + *walk_subtrees = 0; + else + { + tree name = TYPE_NAME (*tp); + if (name && DECL_P (name) && decl_function_context (name)) + return *tp; + } + return NULL_TREE; +} + +/* If TYPE involves a function-local type (including a local typedef to a + non-local type), returns that type; otherwise returns NULL_TREE. */ + +static tree +uses_local_type (tree type) +{ + tree used = walk_tree_without_duplicates (&type, uses_local_type_r, NULL); + return used; +} + /* Return the DIE for the scope that immediately contains this type. - Non-named types get global scope. Named types nested in other - types get their containing scope if it's open, or global scope - otherwise. All other types (i.e. function-local named types) get + Non-named types that do not involve a function-local type get global + scope. Named types nested in namespaces or other types get their + containing scope. All other types (i.e. function-local named types) get the current active scope. */ static dw_die_ref @@ -15887,18 +16130,24 @@ scope_die_for (tree t, dw_die_ref context_die) { dw_die_ref scope_die = NULL; tree containing_scope; - int i; /* Non-types always go in the current scope. */ gcc_assert (TYPE_P (t)); - containing_scope = TYPE_CONTEXT (t); + /* Use the scope of the typedef, rather than the scope of the type + it refers to. */ + if (TYPE_NAME (t) && DECL_P (TYPE_NAME (t))) + containing_scope = DECL_CONTEXT (TYPE_NAME (t)); + else + containing_scope = TYPE_CONTEXT (t); - /* Use the containing namespace if it was passed in (for a declaration). */ + /* Use the containing namespace if there is one. */ if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) { if (context_die == lookup_decl_die (containing_scope)) /* OK */; + else if (debug_info_level > DINFO_LEVEL_TERSE) + context_die = get_context_die (containing_scope); else containing_scope = NULL_TREE; } @@ -15910,30 +16159,25 @@ scope_die_for (tree t, dw_die_ref context_die) containing_scope = NULL_TREE; if (SCOPE_FILE_SCOPE_P (containing_scope)) - scope_die = comp_unit_die (); + { + /* If T uses a local type keep it local as well, to avoid references + to function-local DIEs from outside the function. */ + if (current_function_decl && uses_local_type (t)) + scope_die = context_die; + else + scope_die = comp_unit_die (); + } else if (TYPE_P (containing_scope)) { - /* For types, we can just look up the appropriate DIE. But - first we check to see if we're in the middle of emitting it - so we know where the new DIE should go. */ - for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i) - if (VEC_index (tree, decl_scope_table, i) == containing_scope) - break; - - if (i < 0) + /* For types, we can just look up the appropriate DIE. */ + if (debug_info_level > DINFO_LEVEL_TERSE) + scope_die = get_context_die (containing_scope); + else { - gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE - || TREE_ASM_WRITTEN (containing_scope)); - /*We are not in the middle of emitting the type - CONTAINING_SCOPE. Let's see if it's emitted already. */ - scope_die = lookup_type_die (containing_scope); - - /* If none of the current dies are suitable, we get file scope. */ + scope_die = lookup_type_die_strip_naming_typedef (containing_scope); if (scope_die == NULL) scope_die = comp_unit_die (); } - else - scope_die = lookup_type_die_strip_naming_typedef (containing_scope); } else scope_die = context_die; @@ -16184,9 +16428,6 @@ gen_array_type_die (tree type, dw_die_ref context_die) array_die = new_die (DW_TAG_array_type, scope_die, type); add_name_attribute (array_die, type_tag (type)); - add_gnat_descriptive_type_attribute (array_die, type, context_die); - if (TYPE_ARTIFICIAL (type)) - add_AT_flag (array_die, DW_AT_artificial, 1); equate_type_number_to_die (type, array_die); if (TREE_CODE (type) == VECTOR_TYPE) @@ -16246,6 +16487,10 @@ gen_array_type_die (tree type, dw_die_ref context_die) add_type_attribute (array_die, element_type, 0, 0, context_die); + add_gnat_descriptive_type_attribute (array_die, type, context_die); + if (TYPE_ARTIFICIAL (type)) + add_AT_flag (array_die, DW_AT_artificial, 1); + if (get_AT (array_die, DW_AT_name)) add_pubtype (type, array_die); } @@ -16489,9 +16734,6 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die) scope_die_for (type, context_die), type); equate_type_number_to_die (type, type_die); add_name_attribute (type_die, type_tag (type)); - add_gnat_descriptive_type_attribute (type_die, type, context_die); - if (TYPE_ARTIFICIAL (type)) - add_AT_flag (type_die, DW_AT_artificial, 1); if (dwarf_version >= 4 || !dwarf_strict) { if (ENUM_IS_SCOPED (type)) @@ -16547,6 +16789,10 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die) add_AT_int (enum_die, DW_AT_const_value, tree_low_cst (value, tree_int_cst_sgn (value) > 0)); } + + add_gnat_descriptive_type_attribute (type_die, type, context_die); + if (TYPE_ARTIFICIAL (type)) + add_AT_flag (type_die, DW_AT_artificial, 1); } else add_AT_flag (type_die, DW_AT_declaration, 1); @@ -17896,6 +18142,14 @@ gen_label_die (tree decl, dw_die_ref context_die) ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); } + else if (insn + && NOTE_P (insn) + && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL + && CODE_LABEL_NUMBER (insn) != -1) + { + ASM_GENERATE_INTERNAL_LABEL (label, "LDL", CODE_LABEL_NUMBER (insn)); + add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); + } } } @@ -18108,13 +18362,124 @@ 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_fverbose_asm: + 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 +18493,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. */ @@ -18194,6 +18548,11 @@ gen_compile_unit_die (const char *filename) language = DW_LANG_ObjC; else if (strcmp (language_string, "GNU Objective-C++") == 0) language = DW_LANG_ObjC_plus_plus; + else if (dwarf_version >= 5 || !dwarf_strict) + { + if (strcmp (language_string, "GNU Go") == 0) + language = DW_LANG_Go; + } } add_AT_unsigned (die, DW_AT_language, language); @@ -18346,12 +18705,7 @@ gen_struct_or_union_type_die (tree type, dw_die_ref context_die, if (old_die) add_AT_specification (type_die, old_die); else - { - add_name_attribute (type_die, type_tag (type)); - add_gnat_descriptive_type_attribute (type_die, type, context_die); - if (TYPE_ARTIFICIAL (type)) - add_AT_flag (type_die, DW_AT_artificial, 1); - } + add_name_attribute (type_die, type_tag (type)); } else remove_AT (type_die, DW_AT_declaration); @@ -18384,6 +18738,10 @@ gen_struct_or_union_type_die (tree type, dw_die_ref context_die, gen_member_die (type, type_die); pop_decl_scope (); + add_gnat_descriptive_type_attribute (type_die, type, context_die); + if (TYPE_ARTIFICIAL (type)) + add_AT_flag (type_die, DW_AT_artificial, 1); + /* GNU extension: Record what type our vtable lives in. */ if (TYPE_VFIELD (type)) { @@ -18608,11 +18966,8 @@ gen_type_die_with_usage (tree type, dw_die_ref context_die, /* Prevent broken recursion; we can't hand off to the same type. */ gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type); - /* Use the DIE of the containing namespace as the parent DIE of - the type description DIE we want to generate. */ - if (DECL_CONTEXT (TYPE_NAME (type)) - && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL) - context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type))); + /* Give typedefs the right scope. */ + context_die = scope_die_for (type, context_die); TREE_ASM_WRITTEN (type) = 1; @@ -19577,7 +19932,9 @@ dwarf2out_decl (tree decl) return; /* For local statics lookup proper context die. */ - if (TREE_STATIC (decl) && decl_function_context (decl)) + if (TREE_STATIC (decl) + && DECL_CONTEXT (decl) + && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL) context_die = lookup_decl_die (DECL_CONTEXT (decl)); /* If we are in terse mode, don't generate any DIEs to represent any @@ -19905,10 +20262,11 @@ dwarf2out_var_location (rtx loc_note) { char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2]; struct var_loc_node *newloc; - rtx next_real; + rtx next_real, next_note; static const char *last_label; static const char *last_postcall_label; static bool last_in_cold_section_p; + static rtx expected_next_loc_note; tree decl; bool var_loc_p; @@ -19927,7 +20285,35 @@ dwarf2out_var_location (rtx loc_note) if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note))) return; - next_real = next_real_insn (loc_note); + /* Optimize processing a large consecutive sequence of location + notes so we don't spend too much time in next_real_insn. If the + next insn is another location note, remember the next_real_insn + calculation for next time. */ + next_real = cached_next_real_insn; + if (next_real) + { + if (expected_next_loc_note != loc_note) + next_real = NULL_RTX; + } + + next_note = NEXT_INSN (loc_note); + if (! next_note + || INSN_DELETED_P (next_note) + || GET_CODE (next_note) != NOTE + || (NOTE_KIND (next_note) != NOTE_INSN_VAR_LOCATION + && NOTE_KIND (next_note) != NOTE_INSN_CALL_ARG_LOCATION)) + next_note = NULL_RTX; + + if (! next_real) + next_real = next_real_insn (loc_note); + + if (next_note) + { + expected_next_loc_note = next_note; + cached_next_real_insn = next_real; + } + else + cached_next_real_insn = NULL_RTX; /* If there are no instructions which would be affected by this note, don't do anything. */ @@ -20110,6 +20496,10 @@ set_cur_line_info_table (section *sec) VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table); } + if (DWARF2_ASM_LINE_DEBUG_INFO) + table->is_stmt = (cur_line_info_table + ? cur_line_info_table->is_stmt + : DWARF_LINE_DEFAULT_IS_STMT_START); cur_line_info_table = table; } @@ -20207,12 +20597,27 @@ dwarf2out_source_line (unsigned int line, const char *filename, if (DWARF2_ASM_LINE_DEBUG_INFO) { /* Emit the .loc directive understood by GNU as. */ - fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line); + /* "\t.loc %u %u 0 is_stmt %u discriminator %u", + file_num, line, is_stmt, discriminator */ + fputs ("\t.loc ", asm_out_file); + fprint_ul (asm_out_file, file_num); + putc (' ', asm_out_file); + fprint_ul (asm_out_file, line); + putc (' ', asm_out_file); + putc ('0', asm_out_file); + if (is_stmt != table->is_stmt) - fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0); + { + fputs (" is_stmt ", asm_out_file); + putc (is_stmt ? '1' : '0', asm_out_file); + } if (SUPPORTS_DISCRIMINATOR && discriminator != 0) - fprintf (asm_out_file, " discriminator %d", discriminator); - fputc ('\n', asm_out_file); + { + gcc_assert (discriminator > 0); + fputs (" discriminator ", asm_out_file); + fprint_ul (asm_out_file, (unsigned long) discriminator); + } + putc ('\n', asm_out_file); } else { @@ -20256,7 +20661,7 @@ dwarf2out_start_source_file (unsigned int lineno, const char *filename) macinfo_entry e; e.code = DW_MACINFO_start_file; e.lineno = lineno; - e.info = xstrdup (filename); + e.info = ggc_strdup (filename); VEC_safe_push (macinfo_entry, gc, macinfo_table, &e); } } @@ -20291,9 +20696,18 @@ dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED, if (debug_info_level >= DINFO_LEVEL_VERBOSE) { macinfo_entry e; + /* Insert a dummy first entry to be able to optimize the whole + predefined macro block using DW_MACRO_GNU_transparent_include. */ + if (VEC_empty (macinfo_entry, macinfo_table) && lineno <= 1) + { + e.code = 0; + e.lineno = 0; + e.info = NULL; + VEC_safe_push (macinfo_entry, gc, macinfo_table, &e); + } e.code = DW_MACINFO_define; e.lineno = lineno; - e.info = xstrdup (buffer);; + e.info = ggc_strdup (buffer); VEC_safe_push (macinfo_entry, gc, macinfo_table, &e); } } @@ -20309,58 +20723,376 @@ dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED, if (debug_info_level >= DINFO_LEVEL_VERBOSE) { macinfo_entry e; + /* Insert a dummy first entry to be able to optimize the whole + predefined macro block using DW_MACRO_GNU_transparent_include. */ + if (VEC_empty (macinfo_entry, macinfo_table) && lineno <= 1) + { + e.code = 0; + e.lineno = 0; + e.info = NULL; + VEC_safe_push (macinfo_entry, gc, macinfo_table, &e); + } e.code = DW_MACINFO_undef; e.lineno = lineno; - e.info = xstrdup (buffer);; + e.info = ggc_strdup (buffer); VEC_safe_push (macinfo_entry, gc, macinfo_table, &e); } } +/* Routines to manipulate hash table of CUs. */ + +static hashval_t +htab_macinfo_hash (const void *of) +{ + const macinfo_entry *const entry = + (const macinfo_entry *) of; + + return htab_hash_string (entry->info); +} + +static int +htab_macinfo_eq (const void *of1, const void *of2) +{ + const macinfo_entry *const entry1 = (const macinfo_entry *) of1; + const macinfo_entry *const entry2 = (const macinfo_entry *) of2; + + return !strcmp (entry1->info, entry2->info); +} + +/* Output a single .debug_macinfo entry. */ + +static void +output_macinfo_op (macinfo_entry *ref) +{ + int file_num; + size_t len; + struct indirect_string_node *node; + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + struct dwarf_file_data *fd; + + switch (ref->code) + { + case DW_MACINFO_start_file: + fd = lookup_filename (ref->info); + file_num = maybe_emit_file (fd); + dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); + dw2_asm_output_data_uleb128 (ref->lineno, + "Included from line number %lu", + (unsigned long) ref->lineno); + dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info); + break; + case DW_MACINFO_end_file: + dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); + break; + case DW_MACINFO_define: + case DW_MACINFO_undef: + len = strlen (ref->info) + 1; + if (!dwarf_strict + && len > DWARF_OFFSET_SIZE + && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET + && (debug_str_section->common.flags & SECTION_MERGE) != 0) + { + ref->code = ref->code == DW_MACINFO_define + ? DW_MACRO_GNU_define_indirect + : DW_MACRO_GNU_undef_indirect; + output_macinfo_op (ref); + return; + } + dw2_asm_output_data (1, ref->code, + ref->code == DW_MACINFO_define + ? "Define macro" : "Undefine macro"); + dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu", + (unsigned long) ref->lineno); + dw2_asm_output_nstring (ref->info, -1, "The macro"); + break; + case DW_MACRO_GNU_define_indirect: + case DW_MACRO_GNU_undef_indirect: + node = find_AT_string (ref->info); + if (node->form != DW_FORM_strp) + { + char label[32]; + ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter); + ++dw2_string_counter; + node->label = xstrdup (label); + node->form = DW_FORM_strp; + } + dw2_asm_output_data (1, ref->code, + ref->code == DW_MACRO_GNU_define_indirect + ? "Define macro indirect" + : "Undefine macro indirect"); + dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu", + (unsigned long) ref->lineno); + dw2_asm_output_offset (DWARF_OFFSET_SIZE, node->label, + debug_str_section, "The macro: \"%s\"", + ref->info); + break; + case DW_MACRO_GNU_transparent_include: + dw2_asm_output_data (1, ref->code, "Transparent include"); + ASM_GENERATE_INTERNAL_LABEL (label, + DEBUG_MACRO_SECTION_LABEL, ref->lineno); + dw2_asm_output_offset (DWARF_OFFSET_SIZE, label, NULL, NULL); + break; + default: + fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n", + ASM_COMMENT_START, (unsigned long) ref->code); + break; + } +} + +/* Attempt to make a sequence of define/undef macinfo ops shareable with + other compilation unit .debug_macinfo sections. IDX is the first + index of a define/undef, return the number of ops that should be + emitted in a comdat .debug_macinfo section and emit + a DW_MACRO_GNU_transparent_include entry referencing it. + If the define/undef entry should be emitted normally, return 0. */ + +static unsigned +optimize_macinfo_range (unsigned int idx, VEC (macinfo_entry, gc) *files, + htab_t *macinfo_htab) +{ + macinfo_entry *first, *second, *cur, *inc; + char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1]; + unsigned char checksum[16]; + struct md5_ctx ctx; + char *grp_name, *tail; + const char *base; + unsigned int i, count, encoded_filename_len, linebuf_len; + void **slot; + + first = VEC_index (macinfo_entry, macinfo_table, idx); + second = VEC_index (macinfo_entry, macinfo_table, idx + 1); + + /* Optimize only if there are at least two consecutive define/undef ops, + and either all of them are before first DW_MACINFO_start_file + with lineno {0,1} (i.e. predefined macro block), or all of them are + in some included header file. */ + if (second->code != DW_MACINFO_define && second->code != DW_MACINFO_undef) + return 0; + if (VEC_empty (macinfo_entry, files)) + { + if (first->lineno > 1 || second->lineno > 1) + return 0; + } + else if (first->lineno == 0) + return 0; + + /* Find the last define/undef entry that can be grouped together + with first and at the same time compute md5 checksum of their + codes, linenumbers and strings. */ + md5_init_ctx (&ctx); + for (i = idx; VEC_iterate (macinfo_entry, macinfo_table, i, cur); i++) + if (cur->code != DW_MACINFO_define && cur->code != DW_MACINFO_undef) + break; + else if (VEC_empty (macinfo_entry, files) && cur->lineno > 1) + break; + else + { + unsigned char code = cur->code; + md5_process_bytes (&code, 1, &ctx); + checksum_uleb128 (cur->lineno, &ctx); + md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx); + } + md5_finish_ctx (&ctx, checksum); + count = i - idx; + + /* From the containing include filename (if any) pick up just + usable characters from its basename. */ + if (VEC_empty (macinfo_entry, files)) + base = ""; + else + base = lbasename (VEC_last (macinfo_entry, files)->info); + for (encoded_filename_len = 0, i = 0; base[i]; i++) + if (ISIDNUM (base[i]) || base[i] == '.') + encoded_filename_len++; + /* Count . at the end. */ + if (encoded_filename_len) + encoded_filename_len++; + + sprintf (linebuf, HOST_WIDE_INT_PRINT_UNSIGNED, first->lineno); + linebuf_len = strlen (linebuf); + + /* The group name format is: wmN.[.]. */ + grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1 + + 16 * 2 + 1); + memcpy (grp_name, DWARF_OFFSET_SIZE == 4 ? "wm4." : "wm8.", 4); + tail = grp_name + 4; + if (encoded_filename_len) + { + for (i = 0; base[i]; i++) + if (ISIDNUM (base[i]) || base[i] == '.') + *tail++ = base[i]; + *tail++ = '.'; + } + memcpy (tail, linebuf, linebuf_len); + tail += linebuf_len; + *tail++ = '.'; + for (i = 0; i < 16; i++) + sprintf (tail + i * 2, "%02x", checksum[i] & 0xff); + + /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include + in the empty vector entry before the first define/undef. */ + inc = VEC_index (macinfo_entry, macinfo_table, idx - 1); + inc->code = DW_MACRO_GNU_transparent_include; + inc->lineno = 0; + inc->info = ggc_strdup (grp_name); + if (*macinfo_htab == NULL) + *macinfo_htab = htab_create (10, htab_macinfo_hash, htab_macinfo_eq, NULL); + /* Avoid emitting duplicates. */ + slot = htab_find_slot (*macinfo_htab, inc, INSERT); + if (*slot != NULL) + { + inc->code = 0; + inc->info = NULL; + /* If such an entry has been used before, just emit + a DW_MACRO_GNU_transparent_include op. */ + inc = (macinfo_entry *) *slot; + output_macinfo_op (inc); + /* And clear all macinfo_entry in the range to avoid emitting them + in the second pass. */ + for (i = idx; + VEC_iterate (macinfo_entry, macinfo_table, i, cur) + && i < idx + count; + i++) + { + cur->code = 0; + cur->info = NULL; + } + } + else + { + *slot = inc; + inc->lineno = htab_elements (*macinfo_htab); + output_macinfo_op (inc); + } + return count; +} + +/* Output macinfo section(s). */ + static void output_macinfo (void) { unsigned i; unsigned long length = VEC_length (macinfo_entry, macinfo_table); macinfo_entry *ref; + VEC (macinfo_entry, gc) *files = NULL; + htab_t macinfo_htab = NULL; if (! length) return; + /* output_macinfo* uses these interchangeably. */ + gcc_assert ((int) DW_MACINFO_define == (int) DW_MACRO_GNU_define + && (int) DW_MACINFO_undef == (int) DW_MACRO_GNU_undef + && (int) DW_MACINFO_start_file == (int) DW_MACRO_GNU_start_file + && (int) DW_MACINFO_end_file == (int) DW_MACRO_GNU_end_file); + + /* For .debug_macro emit the section header. */ + if (!dwarf_strict) + { + dw2_asm_output_data (2, 4, "DWARF macro version number"); + if (DWARF_OFFSET_SIZE == 8) + dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present"); + else + dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present"); + dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_line_section_label, + debug_line_section, NULL); + } + + /* In the first loop, it emits the primary .debug_macinfo section + and after each emitted op the macinfo_entry is cleared. + If a longer range of define/undef ops can be optimized using + DW_MACRO_GNU_transparent_include, the + DW_MACRO_GNU_transparent_include op is emitted and kept in + the vector before the first define/undef in the range and the + whole range of define/undef ops is not emitted and kept. */ for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++) { switch (ref->code) { - case DW_MACINFO_start_file: + case DW_MACINFO_start_file: + VEC_safe_push (macinfo_entry, gc, files, ref); + break; + case DW_MACINFO_end_file: + if (!VEC_empty (macinfo_entry, files)) + VEC_pop (macinfo_entry, files); + break; + case DW_MACINFO_define: + case DW_MACINFO_undef: + if (!dwarf_strict + && HAVE_COMDAT_GROUP + && VEC_length (macinfo_entry, files) != 1 + && i > 0 + && i + 1 < length + && VEC_index (macinfo_entry, macinfo_table, i - 1)->code == 0) { - int file_num = maybe_emit_file (lookup_filename (ref->info)); - dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); - dw2_asm_output_data_uleb128 - (ref->lineno, "Included from line number %lu", - (unsigned long)ref->lineno); - dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info); + unsigned count = optimize_macinfo_range (i, files, &macinfo_htab); + if (count) + { + i += count - 1; + continue; + } } - break; - case DW_MACINFO_end_file: - dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); - break; - case DW_MACINFO_define: - dw2_asm_output_data (1, DW_MACINFO_define, "Define macro"); - dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu", - (unsigned long)ref->lineno); - dw2_asm_output_nstring (ref->info, -1, "The macro"); - break; - case DW_MACINFO_undef: - dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro"); - dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu", - (unsigned long)ref->lineno); - dw2_asm_output_nstring (ref->info, -1, "The macro"); - break; - default: - fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n", - ASM_COMMENT_START, (unsigned long)ref->code); + break; + case 0: + /* A dummy entry may be inserted at the beginning to be able + to optimize the whole block of predefined macros. */ + if (i == 0) + continue; + default: break; } + output_macinfo_op (ref); + ref->info = NULL; + ref->code = 0; } + + if (macinfo_htab == NULL) + return; + + htab_delete (macinfo_htab); + + /* If any DW_MACRO_GNU_transparent_include were used, on those + DW_MACRO_GNU_transparent_include entries terminate the + current chain and switch to a new comdat .debug_macinfo + section and emit the define/undef entries within it. */ + for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++) + switch (ref->code) + { + case 0: + continue; + case DW_MACRO_GNU_transparent_include: + { + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + tree comdat_key = get_identifier (ref->info); + /* Terminate the previous .debug_macinfo section. */ + dw2_asm_output_data (1, 0, "End compilation unit"); + targetm.asm_out.named_section (DEBUG_MACRO_SECTION, + SECTION_DEBUG + | SECTION_LINKONCE, + comdat_key); + ASM_GENERATE_INTERNAL_LABEL (label, + DEBUG_MACRO_SECTION_LABEL, + ref->lineno); + ASM_OUTPUT_LABEL (asm_out_file, label); + ref->code = 0; + ref->info = NULL; + dw2_asm_output_data (2, 4, "DWARF macro version number"); + if (DWARF_OFFSET_SIZE == 8) + dw2_asm_output_data (1, 1, "Flags: 64-bit"); + else + dw2_asm_output_data (1, 0, "Flags: 32-bit"); + } + break; + case DW_MACINFO_define: + case DW_MACINFO_undef: + output_macinfo_op (ref); + ref->code = 0; + ref->info = NULL; + break; + default: + gcc_unreachable (); + } } /* Set up for Dwarf output at the start of compilation. */ @@ -20409,7 +21141,9 @@ dwarf2out_init (const char *filename ATTRIBUTE_UNUSED) SECTION_DEBUG, NULL); debug_aranges_section = get_section (DEBUG_ARANGES_SECTION, SECTION_DEBUG, NULL); - debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION, + debug_macinfo_section = get_section (dwarf_strict + ? DEBUG_MACINFO_SECTION + : DEBUG_MACRO_SECTION, SECTION_DEBUG, NULL); debug_line_section = get_section (DEBUG_LINE_SECTION, SECTION_DEBUG, NULL); @@ -20441,7 +21175,9 @@ dwarf2out_init (const char *filename ATTRIBUTE_UNUSED) ASM_GENERATE_INTERNAL_LABEL (ranges_section_label, DEBUG_RANGES_SECTION_LABEL, 0); ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, - DEBUG_MACINFO_SECTION_LABEL, 0); + dwarf_strict + ? DEBUG_MACINFO_SECTION_LABEL + : DEBUG_MACRO_SECTION_LABEL, 0); if (debug_info_level >= DINFO_LEVEL_VERBOSE) macinfo_table = VEC_alloc (macinfo_entry, gc, 64); @@ -21251,13 +21987,26 @@ resolve_addr (dw_die_ref die) } break; case dw_val_class_loc: - if (!resolve_addr_in_expr (AT_loc (a))) - { - remove_AT (die, a->dw_attr); - ix--; - } - else - mark_base_types (AT_loc (a)); + { + dw_loc_descr_ref l = AT_loc (a); + /* For -gdwarf-2 don't attempt to optimize + DW_AT_data_member_location containing + DW_OP_plus_uconst - older consumers might + rely on it being that op instead of a more complex, + but shorter, location description. */ + if ((dwarf_version > 2 + || a->dw_attr != DW_AT_data_member_location + || l == NULL + || l->dw_loc_opc != DW_OP_plus_uconst + || l->dw_loc_next != NULL) + && !resolve_addr_in_expr (l)) + { + remove_AT (die, a->dw_attr); + ix--; + } + else + mark_base_types (l); + } break; case dw_val_class_addr: if (a->dw_attr == DW_AT_const_value @@ -21774,13 +22523,22 @@ 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 (); /* Add the name for the main input file now. We delayed this from dwarf2out_init to avoid complications with PCH. */ add_name_attribute (comp_unit_die (), remap_debug_filename (filename)); - if (!IS_ABSOLUTE_PATH (filename)) + if (!IS_ABSOLUTE_PATH (filename) || targetm.force_at_comp_dir) add_comp_dir_attribute (comp_unit_die ()); else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL) { @@ -21832,24 +22590,16 @@ dwarf2out_finish (const char *filename) inlined and optimized out. In that case we are lost and assign the empty child. This should not be big issue as the function is likely unreachable too. */ - tree context = NULL_TREE; - gcc_assert (node->created_for); if (DECL_P (node->created_for)) - context = DECL_CONTEXT (node->created_for); + origin = get_context_die (DECL_CONTEXT (node->created_for)); else if (TYPE_P (node->created_for)) - context = TYPE_CONTEXT (node->created_for); - - gcc_assert (context - && (TREE_CODE (context) == FUNCTION_DECL - || TREE_CODE (context) == NAMESPACE_DECL)); - - origin = lookup_decl_die (context); - if (origin) - add_child_die (origin, die); + origin = scope_die_for (node->created_for, comp_unit_die ()); else - add_child_die (comp_unit_die (), die); + origin = comp_unit_die (); + + add_child_die (origin, die); } } } @@ -21868,7 +22618,11 @@ dwarf2out_finish (const char *filename) for (node = deferred_asm_name; node; node = node->next) { tree decl = node->created_for; - if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)) + /* When generating LTO bytecode we can not generate new assembler + names at this point and all important decls got theirs via + free-lang-data. */ + if ((!flag_generate_lto || DECL_ASSEMBLER_NAME_SET_P (decl)) + && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)) { add_linkage_attr (node->die, decl); move_linkage_attr (node->die); @@ -21983,8 +22737,10 @@ dwarf2out_finish (const char *filename) add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list, debug_line_section_label); - if (debug_info_level >= DINFO_LEVEL_VERBOSE) - add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label); + if (have_macinfo) + add_AT_macptr (comp_unit_die (), + dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros, + macinfo_section_label); if (have_location_lists) optimize_location_lists (comp_unit_die ()); @@ -22016,8 +22772,8 @@ dwarf2out_finish (const char *filename) htab_delete (comdat_type_table); /* Output the main compilation unit if non-empty or if .debug_macinfo - will be emitted. */ - output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE); + or .debug_macro will be emitted. */ + output_comp_unit (comp_unit_die (), have_macinfo); /* Output the abbreviation table. */ if (abbrev_die_table_in_use != 1) @@ -22096,6 +22852,15 @@ dwarf2out_finish (const char *filename) output_ranges (); } + /* Have to end the macro section. */ + if (have_macinfo) + { + switch_to_section (debug_macinfo_section); + ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); + output_macinfo (); + dw2_asm_output_data (1, 0, "End compilation unit"); + } + /* Output the source line correspondence table. We must do this even if there is no line information. Otherwise, on an empty translation unit, we will generate a present, but empty, @@ -22107,16 +22872,6 @@ dwarf2out_finish (const char *filename) if (! DWARF2_ASM_LINE_DEBUG_INFO) output_line_info (); - /* Have to end the macro section. */ - if (debug_info_level >= DINFO_LEVEL_VERBOSE) - { - switch_to_section (debug_macinfo_section); - ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); - if (!VEC_empty (macinfo_entry, macinfo_table)) - output_macinfo (); - dw2_asm_output_data (1, 0, "End compilation unit"); - } - /* If we emitted any DW_FORM_strp form attribute, output the string table too. */ if (debug_str_hash)