X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fdwarf2read.c;h=54a6dfbdb43fd922e34d3f64865d113536d86ccc;hb=24a550149d4e29a9285b420d27bc0b2b487b802a;hp=3bb84ceaa326a7af7f8239f9fba3f8dfb28823c5;hpb=6ac97d4cc6b67e9665b86c9c511da9c867ac6382;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 3bb84ceaa3..54a6dfbdb4 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -558,6 +558,16 @@ struct dwarf2_per_cu_data attributes in the stub. */ unsigned int reading_dwo_directly : 1; + /* Non-zero if the TU has been read. + This is used to assist the "Stay in DWO Optimization" for Fission: + When reading a DWO, it's faster to read TUs from the DWO instead of + fetching them from random other DWOs (due to comdat folding). + If the TU has already been read, the optimization is unnecessary + (and unwise - we don't want to change where gdb thinks the TU lives + "midflight"). + This flag is only valid if is_debug_types is true. */ + unsigned int tu_read : 1; + /* The section this CU/TU lives in. If the DIE refers to a DWO file, this is always the original die, not the DWO file. */ @@ -1452,10 +1462,10 @@ static struct symbol *new_symbol (struct die_info *, struct type *, static struct symbol *new_symbol_full (struct die_info *, struct type *, struct dwarf2_cu *, struct symbol *); -static void dwarf2_const_value (struct attribute *, struct symbol *, +static void dwarf2_const_value (const struct attribute *, struct symbol *, struct dwarf2_cu *); -static void dwarf2_const_value_attr (struct attribute *attr, +static void dwarf2_const_value_attr (const struct attribute *attr, struct type *type, const char *name, struct obstack *obstack, @@ -1476,7 +1486,7 @@ static void set_descriptive_type (struct type *, struct die_info *, static struct type *die_containing_type (struct die_info *, struct dwarf2_cu *); -static struct type *lookup_die_type (struct die_info *, struct attribute *, +static struct type *lookup_die_type (struct die_info *, const struct attribute *, struct dwarf2_cu *); static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); @@ -1608,29 +1618,27 @@ static void dump_die_1 (struct ui_file *, int level, int max_level, static void store_in_ref_table (struct die_info *, struct dwarf2_cu *); -static int is_ref_attr (struct attribute *); - -static sect_offset dwarf2_get_ref_die_offset (struct attribute *); +static sect_offset dwarf2_get_ref_die_offset (const struct attribute *); -static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); +static LONGEST dwarf2_get_attr_constant_value (const struct attribute *, int); static struct die_info *follow_die_ref_or_sig (struct die_info *, - struct attribute *, + const struct attribute *, struct dwarf2_cu **); static struct die_info *follow_die_ref (struct die_info *, - struct attribute *, + const struct attribute *, struct dwarf2_cu **); static struct die_info *follow_die_sig (struct die_info *, - struct attribute *, + const struct attribute *, struct dwarf2_cu **); static struct type *get_signatured_type (struct die_info *, ULONGEST, struct dwarf2_cu *); static struct type *get_DW_AT_signature_type (struct die_info *, - struct attribute *, + const struct attribute *, struct dwarf2_cu *); static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu); @@ -1638,7 +1646,7 @@ static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu); static void read_signatured_type (struct signatured_type *); static struct type_unit_group *get_type_unit_group - (struct dwarf2_cu *, struct attribute *); + (struct dwarf2_cu *, const struct attribute *); static void build_type_unit_groups (die_reader_func_ftype *, void *); @@ -1651,17 +1659,19 @@ static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int, const char *, int); -static int attr_form_is_block (struct attribute *); +static int attr_form_is_block (const struct attribute *); + +static int attr_form_is_section_offset (const struct attribute *); -static int attr_form_is_section_offset (struct attribute *); +static int attr_form_is_constant (const struct attribute *); -static int attr_form_is_constant (struct attribute *); +static int attr_form_is_ref (const struct attribute *); static void fill_in_loclist_baton (struct dwarf2_cu *cu, struct dwarf2_loclist_baton *baton, - struct attribute *attr); + const struct attribute *attr); -static void dwarf2_symbol_mark_computed (struct attribute *attr, +static void dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym, struct dwarf2_cu *cu, int is_block); @@ -2099,29 +2109,33 @@ locate_dwz_sections (bfd *abfd, asection *sectp, void *arg) } } -/* Open the separate '.dwz' debug file, if needed. Error if the file - cannot be found. */ +/* Open the separate '.dwz' debug file, if needed. Return NULL if + there is no .gnu_debugaltlink section in the file. Error if there + is such a section but the file cannot be found. */ static struct dwz_file * dwarf2_get_dwz_file (void) { - bfd *abfd, *dwz_bfd; - asection *section; - gdb_byte *data; + bfd *dwz_bfd; + char *data; struct cleanup *cleanup; const char *filename; struct dwz_file *result; + unsigned long buildid; if (dwarf2_per_objfile->dwz_file != NULL) return dwarf2_per_objfile->dwz_file; - abfd = dwarf2_per_objfile->objfile->obfd; - section = bfd_get_section_by_name (abfd, ".gnu_debugaltlink"); - if (section == NULL) - error (_("could not find '.gnu_debugaltlink' section")); - if (!bfd_malloc_and_get_section (abfd, section, &data)) - error (_("could not read '.gnu_debugaltlink' section: %s"), - bfd_errmsg (bfd_get_error ())); + bfd_set_error (bfd_error_no_error); + data = bfd_get_alt_debug_link_info (dwarf2_per_objfile->objfile->obfd, + &buildid); + if (data == NULL) + { + if (bfd_get_error () == bfd_error_no_error) + return NULL; + error (_("could not read '.gnu_debugaltlink' section: %s"), + bfd_errmsg (bfd_get_error ())); + } cleanup = make_cleanup (xfree, data); filename = (const char *) data; @@ -2556,17 +2570,24 @@ create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); iter += 4; - if (cu_index < dwarf2_per_objfile->n_comp_units) + if (lo > hi) { - addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, - dw2_get_cu (cu_index)); + complaint (&symfile_complaints, + _(".gdb_index address table has invalid range (%s - %s)"), + pulongest (lo), pulongest (hi)); + continue; } - else + + if (cu_index >= dwarf2_per_objfile->n_comp_units) { complaint (&symfile_complaints, _(".gdb_index address table has invalid CU number %u"), (unsigned) cu_index); + continue; } + + addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, + dw2_get_cu (cu_index)); } objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, @@ -2799,6 +2820,7 @@ dwarf2_read_index (struct objfile *objfile) struct mapped_index local_map, *map; const gdb_byte *cu_list, *types_list, *dwz_list = NULL; offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0; + struct dwz_file *dwz; if (!read_index_from_section (objfile, objfile->name, use_deprecated_index_sections, @@ -2813,9 +2835,9 @@ dwarf2_read_index (struct objfile *objfile) /* If there is a .dwz file, read it so we can get its CU list as well. */ - if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL) + dwz = dwarf2_get_dwz_file (); + if (dwz != NULL) { - struct dwz_file *dwz = dwarf2_get_dwz_file (); struct mapped_index dwz_map; const gdb_byte *dwz_types_ignore; offset_type dwz_types_elements_ignore; @@ -3430,83 +3452,6 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile, } } -/* A helper function for dw2_find_symbol_file that finds the primary - file name for a given CU. This is a die_reader_func. */ - -static void -dw2_get_primary_filename_reader (const struct die_reader_specs *reader, - const gdb_byte *info_ptr, - struct die_info *comp_unit_die, - int has_children, - void *data) -{ - const char **result_ptr = data; - struct dwarf2_cu *cu = reader->cu; - struct attribute *attr; - - attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu); - if (attr == NULL) - *result_ptr = NULL; - else - *result_ptr = DW_STRING (attr); -} - -static const char * -dw2_find_symbol_file (struct objfile *objfile, const char *name) -{ - struct dwarf2_per_cu_data *per_cu; - offset_type *vec; - const char *filename; - - dw2_setup (objfile); - - /* index_table is NULL if OBJF_READNOW. */ - if (!dwarf2_per_objfile->index_table) - { - struct symtab *s; - - ALL_OBJFILE_PRIMARY_SYMTABS (objfile, s) - { - struct blockvector *bv = BLOCKVECTOR (s); - const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); - struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN); - - if (sym) - { - /* Only file extension of returned filename is recognized. */ - return SYMBOL_SYMTAB (sym)->filename; - } - } - return NULL; - } - - if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, - name, &vec)) - return NULL; - - /* Note that this just looks at the very first one named NAME -- but - actually we are looking for a function. find_main_filename - should be rewritten so that it doesn't require a custom hook. It - could just use the ordinary symbol tables. */ - /* vec[0] is the length, which must always be >0. */ - per_cu = dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec[1]))); - - if (per_cu->v.quick->symtab != NULL) - { - /* Only file extension of returned filename is recognized. */ - return per_cu->v.quick->symtab->filename; - } - - /* Initialize filename in case there's a problem reading the DWARF, - dw2_get_primary_filename_reader may not get called. */ - filename = NULL; - init_cutu_and_read_dies (per_cu, NULL, 0, 0, - dw2_get_primary_filename_reader, &filename); - - /* Only file extension of returned filename is recognized. */ - return filename; -} - static void dw2_map_matching_symbols (const char * name, domain_enum namespace, struct objfile *objfile, int global, @@ -3830,7 +3775,6 @@ const struct quick_symbol_functions dwarf2_gdb_index_functions = dw2_expand_symtabs_for_function, dw2_expand_all_symtabs, dw2_expand_symtabs_with_fullname, - dw2_find_symbol_file, dw2_map_matching_symbols, dw2_expand_symtabs_matching, dw2_find_pc_sect_symtab, @@ -4438,11 +4382,7 @@ fill_in_sig_entry_from_dwo_entry (struct objfile *objfile, struct signatured_type *sig_entry, struct dwo_unit *dwo_entry) { - sig_entry->per_cu.section = dwo_entry->section; - sig_entry->per_cu.offset = dwo_entry->offset; - sig_entry->per_cu.length = dwo_entry->length; - sig_entry->per_cu.reading_dwo_directly = 1; - sig_entry->per_cu.objfile = objfile; + /* Make sure we're not clobbering something we don't expect to. */ gdb_assert (! sig_entry->per_cu.queued); gdb_assert (sig_entry->per_cu.cu == NULL); gdb_assert (sig_entry->per_cu.v.quick != NULL); @@ -4450,19 +4390,26 @@ fill_in_sig_entry_from_dwo_entry (struct objfile *objfile, gdb_assert (sig_entry->signature == dwo_entry->signature); gdb_assert (sig_entry->type_offset_in_section.sect_off == 0); gdb_assert (sig_entry->type_unit_group == NULL); + gdb_assert (sig_entry->dwo_unit == NULL); + + sig_entry->per_cu.section = dwo_entry->section; + sig_entry->per_cu.offset = dwo_entry->offset; + sig_entry->per_cu.length = dwo_entry->length; + sig_entry->per_cu.reading_dwo_directly = 1; + sig_entry->per_cu.objfile = objfile; sig_entry->type_offset_in_tu = dwo_entry->type_offset_in_tu; sig_entry->dwo_unit = dwo_entry; } /* Subroutine of lookup_signatured_type. - Create the signatured_type data structure for a TU to be read in - directly from a DWO file, bypassing the stub. - We do this for the case where there is no DWP file and we're using - .gdb_index: When reading a CU we want to stay in the DWO file containing - that CU. Otherwise we could end up reading several other DWO files (due - to comdat folding) to process the transitive closure of all the mentioned - TUs, and that can be slow. The current DWO file will have every type - signature that it needs. + If we haven't read the TU yet, create the signatured_type data structure + for a TU to be read in directly from a DWO file, bypassing the stub. + This is the "Stay in DWO Optimization": When there is no DWP file and we're + using .gdb_index, then when reading a CU we want to stay in the DWO file + containing that CU. Otherwise we could end up reading several other DWO + files (due to comdat folding) to process the transitive closure of all the + mentioned TUs, and that can be slow. The current DWO file will have every + type signature that it needs. We only do this for .gdb_index because in the psymtab case we already have to read all the DWOs to build the type unit groups. */ @@ -4491,8 +4438,13 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) sig_entry = htab_find (dwarf2_per_objfile->signatured_types, &find_sig_entry); if (sig_entry == NULL) return NULL; + + /* We can get here with the TU already read, *or* in the process of being + read. Don't reassign it if that's the case. Also note that if the TU is + already being read, it may not have come from a DWO, the program may be + a mix of Fission-compiled code and non-Fission-compiled code. */ /* Have we already tried to read this TU? */ - if (sig_entry->dwo_unit != NULL) + if (sig_entry->per_cu.tu_read) return sig_entry; /* Ok, this is the first time we're reading this TU. */ @@ -5409,7 +5361,7 @@ create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct) STMT_LIST is a DW_AT_stmt_list attribute. */ static struct type_unit_group * -get_type_unit_group (struct dwarf2_cu *cu, struct attribute *stmt_list) +get_type_unit_group (struct dwarf2_cu *cu, const struct attribute *stmt_list) { struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats; struct type_unit_group *tu_group; @@ -5678,6 +5630,21 @@ create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name) return pst; } +/* The DATA object passed to process_psymtab_comp_unit_reader has this + type. */ + +struct process_psymtab_comp_unit_data +{ + /* True if we are reading a DW_TAG_partial_unit. */ + + int want_partial_unit; + + /* The "pretend" language that is used if the CU doesn't declare a + language. */ + + enum language pretend_language; +}; + /* die_reader_func for process_psymtab_comp_unit. */ static void @@ -5696,16 +5663,14 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, struct partial_symtab *pst; int has_pc_info; const char *filename; - int *want_partial_unit_ptr = data; + struct process_psymtab_comp_unit_data *info = data; - if (comp_unit_die->tag == DW_TAG_partial_unit - && (want_partial_unit_ptr == NULL - || !*want_partial_unit_ptr)) + if (comp_unit_die->tag == DW_TAG_partial_unit && !info->want_partial_unit) return; gdb_assert (! per_cu->is_debug_types); - prepare_one_comp_unit (cu, comp_unit_die, language_minimal); + prepare_one_comp_unit (cu, comp_unit_die, info->pretend_language); cu->list_in_scope = &file_symbols; @@ -5820,8 +5785,11 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, static void process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu, - int want_partial_unit) + int want_partial_unit, + enum language pretend_language) { + struct process_psymtab_comp_unit_data info; + /* If this compilation unit was already read in, free the cached copy in order to read it in again. This is necessary because we skipped some symbols when we first @@ -5831,9 +5799,11 @@ process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu, free_one_cached_comp_unit (this_cu); gdb_assert (! this_cu->is_debug_types); + info.want_partial_unit = want_partial_unit; + info.pretend_language = pretend_language; init_cutu_and_read_dies (this_cu, NULL, 0, 0, process_psymtab_comp_unit_reader, - &want_partial_unit); + &info); /* Age out any secondary CUs. */ age_cached_comp_units (); @@ -6011,7 +5981,7 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile) { struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); - process_psymtab_comp_unit (per_cu, 0); + process_psymtab_comp_unit (per_cu, 0, language_minimal); } set_partial_user (objfile); @@ -6121,6 +6091,7 @@ create_all_comp_units (struct objfile *objfile) int n_allocated; int n_comp_units; struct dwarf2_per_cu_data **all_comp_units; + struct dwz_file *dwz; n_comp_units = 0; n_allocated = 10; @@ -6130,14 +6101,11 @@ create_all_comp_units (struct objfile *objfile) read_comp_units_from_section (objfile, &dwarf2_per_objfile->info, 0, &n_allocated, &n_comp_units, &all_comp_units); - if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL) - { - struct dwz_file *dwz = dwarf2_get_dwz_file (); - - read_comp_units_from_section (objfile, &dwz->info, 1, - &n_allocated, &n_comp_units, - &all_comp_units); - } + dwz = dwarf2_get_dwz_file (); + if (dwz != NULL) + read_comp_units_from_section (objfile, &dwz->info, 1, + &n_allocated, &n_comp_units, + &all_comp_units); dwarf2_per_objfile->all_comp_units = obstack_alloc (&objfile->objfile_obstack, @@ -6235,7 +6203,7 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, /* Go read the partial unit, if needed. */ if (per_cu->v.psymtab == NULL) - process_psymtab_comp_unit (per_cu, 1); + process_psymtab_comp_unit (per_cu, 1, cu->language); VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs, per_cu); @@ -7025,14 +6993,21 @@ process_queue (void) : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) { struct dwarf2_per_cu_data *per_cu = item->per_cu; + char buf[100]; - if (dwarf2_read_debug) + if (per_cu->is_debug_types) { - fprintf_unfiltered (gdb_stdlog, - "Expanding symtab of %s at offset 0x%x\n", - per_cu->is_debug_types ? "TU" : "CU", - per_cu->offset.sect_off); + struct signatured_type *sig_type = + (struct signatured_type *) per_cu; + + sprintf (buf, "TU %s at offset 0x%x", + hex_string (sig_type->signature), per_cu->offset.sect_off); } + else + sprintf (buf, "CU at offset 0x%x", per_cu->offset.sect_off); + + if (dwarf2_read_debug) + fprintf_unfiltered (gdb_stdlog, "Expanding symtab of %s\n", buf); if (per_cu->is_debug_types) process_full_type_unit (per_cu, item->pretend_language); @@ -7040,12 +7015,7 @@ process_queue (void) process_full_comp_unit (per_cu, item->pretend_language); if (dwarf2_read_debug) - { - fprintf_unfiltered (gdb_stdlog, - "Done expanding %s at offset 0x%x\n", - per_cu->is_debug_types ? "TU" : "CU", - per_cu->offset.sect_off); - } + fprintf_unfiltered (gdb_stdlog, "Done expanding %s\n", buf); } item->per_cu->queued = 0; @@ -7349,12 +7319,14 @@ get_symtab (struct dwarf2_per_cu_data *per_cu) included by PER_CU. */ static void -recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr) **result, - htab_t all_children, - struct dwarf2_per_cu_data *per_cu) +recursively_compute_inclusions (VEC (symtab_ptr) **result, + htab_t all_children, htab_t all_type_symtabs, + struct dwarf2_per_cu_data *per_cu, + struct symtab *immediate_parent) { void **slot; int ix; + struct symtab *symtab; struct dwarf2_per_cu_data *iter; slot = htab_find_slot (all_children, per_cu, INSERT); @@ -7366,13 +7338,37 @@ recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr) **result, *slot = per_cu; /* Only add a CU if it has a symbol table. */ - if (get_symtab (per_cu) != NULL) - VEC_safe_push (dwarf2_per_cu_ptr, *result, per_cu); + symtab = get_symtab (per_cu); + if (symtab != NULL) + { + /* If this is a type unit only add its symbol table if we haven't + seen it yet (type unit per_cu's can share symtabs). */ + if (per_cu->is_debug_types) + { + slot = htab_find_slot (all_type_symtabs, symtab, INSERT); + if (*slot == NULL) + { + *slot = symtab; + VEC_safe_push (symtab_ptr, *result, symtab); + if (symtab->user == NULL) + symtab->user = immediate_parent; + } + } + else + { + VEC_safe_push (symtab_ptr, *result, symtab); + if (symtab->user == NULL) + symtab->user = immediate_parent; + } + } for (ix = 0; VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, ix, iter); ++ix) - recursively_compute_inclusions (result, all_children, iter); + { + recursively_compute_inclusions (result, all_children, + all_type_symtabs, iter, symtab); + } } /* Compute the symtab 'includes' fields for the symtab related to @@ -7386,9 +7382,10 @@ compute_symtab_includes (struct dwarf2_per_cu_data *per_cu) if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->imported_symtabs)) { int ix, len; - struct dwarf2_per_cu_data *iter; - VEC (dwarf2_per_cu_ptr) *result_children = NULL; - htab_t all_children; + struct dwarf2_per_cu_data *per_cu_iter; + struct symtab *symtab_iter; + VEC (symtab_ptr) *result_symtabs = NULL; + htab_t all_children, all_type_symtabs; struct symtab *symtab = get_symtab (per_cu); /* If we don't have a symtab, we can just skip this case. */ @@ -7397,28 +7394,33 @@ compute_symtab_includes (struct dwarf2_per_cu_data *per_cu) all_children = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, NULL, xcalloc, xfree); + all_type_symtabs = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, + NULL, xcalloc, xfree); for (ix = 0; VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, - ix, iter); + ix, per_cu_iter); ++ix) - recursively_compute_inclusions (&result_children, all_children, iter); + { + recursively_compute_inclusions (&result_symtabs, all_children, + all_type_symtabs, per_cu_iter, + symtab); + } - /* Now we have a transitive closure of all the included CUs, and - for .gdb_index version 7 the included TUs, so we can convert it - to a list of symtabs. */ - len = VEC_length (dwarf2_per_cu_ptr, result_children); + /* Now we have a transitive closure of all the included symtabs. */ + len = VEC_length (symtab_ptr, result_symtabs); symtab->includes = obstack_alloc (&dwarf2_per_objfile->objfile->objfile_obstack, (len + 1) * sizeof (struct symtab *)); for (ix = 0; - VEC_iterate (dwarf2_per_cu_ptr, result_children, ix, iter); + VEC_iterate (symtab_ptr, result_symtabs, ix, symtab_iter); ++ix) - symtab->includes[ix] = get_symtab (iter); + symtab->includes[ix] = symtab_iter; symtab->includes[len] = NULL; - VEC_free (dwarf2_per_cu_ptr, result_children); + VEC_free (symtab_ptr, result_symtabs); htab_delete (all_children); + htab_delete (all_type_symtabs); } } @@ -9780,12 +9782,13 @@ lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit, kind, dwo_name, hex_string (signature)); } - complaint (&symfile_complaints, - _("Could not find DWO %s %s(%s) referenced by %s at offset 0x%x" - " [in module %s]"), - kind, dwo_name, hex_string (signature), - this_unit->is_debug_types ? "TU" : "CU", - this_unit->offset.sect_off, objfile->name); + /* This is a warning and not a complaint because it can be caused by + pilot error (e.g., user accidentally deleting the DWO). */ + warning (_("Could not find DWO %s %s(%s) referenced by %s at offset 0x%x" + " [in module %s]"), + kind, dwo_name, hex_string (signature), + this_unit->is_debug_types ? "TU" : "CU", + this_unit->offset.sect_off, objfile->name); return NULL; } @@ -10361,7 +10364,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); } - else if (is_ref_attr (attr)) + else if (attr_form_is_ref (attr)) { struct dwarf2_cu *target_cu = cu; struct die_info *target_die; @@ -10434,7 +10437,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) loc = dwarf2_attr (child_die, DW_AT_location, cu); origin = dwarf2_attr (child_die, DW_AT_abstract_origin, cu); - if (loc == NULL && origin != NULL && is_ref_attr (origin)) + if (loc == NULL && origin != NULL && attr_form_is_ref (origin)) { sect_offset offset; @@ -13376,7 +13379,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_upper_bound, cu); if (attr) { - if (attr_form_is_block (attr) || is_ref_attr (attr)) + if (attr_form_is_block (attr) || attr_form_is_ref (attr)) { /* GCC encodes arrays with unspecified or dynamic length with a DW_FORM_block1 attribute or a reference attribute. @@ -14817,7 +14820,7 @@ read_attribute_value (const struct die_reader_specs *reader, } /* Super hack. */ - if (cu->per_cu->is_dwz && is_ref_attr (attr)) + if (cu->per_cu->is_dwz && attr_form_is_ref (attr)) attr->form = DW_FORM_GNU_ref_alt; /* We have seen instances where the compiler tried to emit a byte @@ -15701,6 +15704,7 @@ dwarf_decode_line_header (unsigned int offset, struct dwarf2_cu *cu) if (line_ptr + lh->total_length > (section->buffer + section->size)) { dwarf2_statement_list_fits_in_line_number_section_complaint (); + do_cleanups (back_to); return 0; } lh->statement_program_end = line_ptr + lh->total_length; @@ -16781,7 +16785,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) because that is the interpretation long in use by GCC. */ static gdb_byte * -dwarf2_const_value_data (struct attribute *attr, struct obstack *obstack, +dwarf2_const_value_data (const struct attribute *attr, struct obstack *obstack, struct dwarf2_cu *cu, LONGEST *value, int bits) { struct objfile *objfile = cu->objfile; @@ -16813,7 +16817,7 @@ dwarf2_const_value_data (struct attribute *attr, struct obstack *obstack, expression. */ static void -dwarf2_const_value_attr (struct attribute *attr, struct type *type, +dwarf2_const_value_attr (const struct attribute *attr, struct type *type, const char *name, struct obstack *obstack, struct dwarf2_cu *cu, LONGEST *value, const gdb_byte **bytes, @@ -16916,7 +16920,7 @@ dwarf2_const_value_attr (struct attribute *attr, struct type *type, /* Copy constant value from an attribute to a symbol. */ static void -dwarf2_const_value (struct attribute *attr, struct symbol *sym, +dwarf2_const_value (const struct attribute *attr, struct symbol *sym, struct dwarf2_cu *cu) { struct objfile *objfile = cu->objfile; @@ -17055,7 +17059,7 @@ build_error_marker_type (struct dwarf2_cu *cu, struct die_info *die) If there is no type substitute an error marker. */ static struct type * -lookup_die_type (struct die_info *die, struct attribute *attr, +lookup_die_type (struct die_info *die, const struct attribute *attr, struct dwarf2_cu *cu) { struct objfile *objfile = cu->objfile; @@ -17075,7 +17079,7 @@ lookup_die_type (struct die_info *die, struct attribute *attr, per_cu = dwarf2_find_containing_comp_unit (offset, 1, cu->objfile); this_type = get_die_type_at_offset (offset, per_cu); } - else if (is_ref_attr (attr)) + else if (attr_form_is_ref (attr)) { sect_offset offset = dwarf2_get_ref_die_offset (attr); @@ -17104,7 +17108,7 @@ lookup_die_type (struct die_info *die, struct attribute *attr, struct die_info *type_die = NULL; struct dwarf2_cu *type_cu = cu; - if (is_ref_attr (attr)) + if (attr_form_is_ref (attr)) type_die = follow_die_ref (die, attr, &type_cu); if (type_die == NULL) return build_error_marker_type (cu, die); @@ -17947,36 +17951,15 @@ store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) *slot = die; } -/* DW_ADDR is always stored already as sect_offset; despite for the forms - besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */ - -static int -is_ref_attr (struct attribute *attr) -{ - switch (attr->form) - { - case DW_FORM_ref_addr: - case DW_FORM_ref1: - case DW_FORM_ref2: - case DW_FORM_ref4: - case DW_FORM_ref8: - case DW_FORM_ref_udata: - case DW_FORM_GNU_ref_alt: - return 1; - default: - return 0; - } -} - /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the required kind. */ static sect_offset -dwarf2_get_ref_die_offset (struct attribute *attr) +dwarf2_get_ref_die_offset (const struct attribute *attr) { sect_offset retval = { DW_UNSND (attr) }; - if (is_ref_attr (attr)) + if (attr_form_is_ref (attr)) return retval; retval.sect_off = 0; @@ -17990,7 +17973,7 @@ dwarf2_get_ref_die_offset (struct attribute *attr) * the value held by the attribute is not constant. */ static LONGEST -dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) +dwarf2_get_attr_constant_value (const struct attribute *attr, int default_value) { if (attr->form == DW_FORM_sdata) return DW_SND (attr); @@ -18014,12 +17997,12 @@ dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) On exit *REF_CU is the CU of the result. */ static struct die_info * -follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, +follow_die_ref_or_sig (struct die_info *src_die, const struct attribute *attr, struct dwarf2_cu **ref_cu) { struct die_info *die; - if (is_ref_attr (attr)) + if (attr_form_is_ref (attr)) die = follow_die_ref (src_die, attr, ref_cu); else if (attr->form == DW_FORM_ref_sig8) die = follow_die_sig (src_die, attr, ref_cu); @@ -18088,7 +18071,7 @@ follow_die_offset (sect_offset offset, int offset_in_dwz, On exit *REF_CU is the CU of the result. */ static struct die_info * -follow_die_ref (struct die_info *src_die, struct attribute *attr, +follow_die_ref (struct die_info *src_die, const struct attribute *attr, struct dwarf2_cu **ref_cu) { sect_offset offset = dwarf2_get_ref_die_offset (attr); @@ -18400,7 +18383,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type, If the referenced type cannot be found an error is thrown. */ static struct die_info * -follow_die_sig (struct die_info *src_die, struct attribute *attr, +follow_die_sig (struct die_info *src_die, const struct attribute *attr, struct dwarf2_cu **ref_cu) { ULONGEST signature = DW_SIGNATURE (attr); @@ -18498,11 +18481,11 @@ get_signatured_type (struct die_info *die, ULONGEST signature, reading in and processing the type unit if necessary. */ static struct type * -get_DW_AT_signature_type (struct die_info *die, struct attribute *attr, +get_DW_AT_signature_type (struct die_info *die, const struct attribute *attr, struct dwarf2_cu *cu) /* ARI: editCase function */ { /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */ - if (is_ref_attr (attr)) + if (attr_form_is_ref (attr)) { struct dwarf2_cu *type_cu = cu; struct die_info *type_die = follow_die_ref (die, attr, &type_cu); @@ -18598,6 +18581,7 @@ read_signatured_type (struct signatured_type *sig_type) init_cutu_and_read_dies (per_cu, NULL, 0, 1, read_signatured_type_reader, NULL); + sig_type->per_cu.tu_read = 1; } /* Decode simple location descriptions. @@ -19813,7 +19797,7 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset, if so return true else false. */ static int -attr_form_is_block (struct attribute *attr) +attr_form_is_block (const struct attribute *attr) { return (attr == NULL ? 0 : attr->form == DW_FORM_block1 @@ -19833,7 +19817,7 @@ attr_form_is_block (struct attribute *attr) of them. */ static int -attr_form_is_section_offset (struct attribute *attr) +attr_form_is_section_offset (const struct attribute *attr) { return (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8 @@ -19854,7 +19838,7 @@ attr_form_is_section_offset (struct attribute *attr) taken as section offsets, not constants. */ static int -attr_form_is_constant (struct attribute *attr) +attr_form_is_constant (const struct attribute *attr) { switch (attr->form) { @@ -19870,6 +19854,28 @@ attr_form_is_constant (struct attribute *attr) } } + +/* DW_ADDR is always stored already as sect_offset; despite for the forms + besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */ + +static int +attr_form_is_ref (const struct attribute *attr) +{ + switch (attr->form) + { + case DW_FORM_ref_addr: + case DW_FORM_ref1: + case DW_FORM_ref2: + case DW_FORM_ref4: + case DW_FORM_ref8: + case DW_FORM_ref_udata: + case DW_FORM_GNU_ref_alt: + return 1; + default: + return 0; + } +} + /* Return the .debug_loc section to use for CU. For DWO files use .debug_loc.dwo. */ @@ -19886,7 +19892,7 @@ cu_debug_loc_section (struct dwarf2_cu *cu) static void fill_in_loclist_baton (struct dwarf2_cu *cu, struct dwarf2_loclist_baton *baton, - struct attribute *attr) + const struct attribute *attr) { struct dwarf2_section_info *section = cu_debug_loc_section (cu); @@ -19903,7 +19909,7 @@ fill_in_loclist_baton (struct dwarf2_cu *cu, } static void -dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, +dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym, struct dwarf2_cu *cu, int is_block) { struct objfile *objfile = dwarf2_per_objfile->objfile; @@ -20543,6 +20549,10 @@ dwarf2_per_objfile_free (struct objfile *objfile, void *d) struct dwarf2_per_objfile *data = d; int ix; + /* Make sure we don't accidentally use dwarf2_per_objfile while + cleaning up. */ + dwarf2_per_objfile = NULL; + for (ix = 0; ix < data->n_comp_units; ++ix) VEC_free (dwarf2_per_cu_ptr, data->all_comp_units[ix]->imported_symtabs);