X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fdwarf2read.c;h=0a7a0334202429c70328763b83ef9323f4c45ea9;hb=59c35742fb785b1e454f45c2ace663000bf34f4c;hp=9d9dd6db709d78013db992f366e73adfecac8470;hpb=a8b3b8e93e36d2c9efe346f04f3bbd767e3cc0f0;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 9d9dd6db70..0a7a033420 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -41,7 +41,6 @@ #include "buildsym.h" #include "demangle.h" #include "gdb-demangle.h" -#include "expression.h" #include "filenames.h" /* for DOSish file names */ #include "macrotab.h" #include "language.h" @@ -56,38 +55,26 @@ #include "addrmap.h" #include "typeprint.h" #include "psympriv.h" -#include -#include "completer.h" -#include "gdbsupport/vec.h" #include "c-lang.h" #include "go-lang.h" #include "valprint.h" #include "gdbcore.h" /* for gnutarget */ #include "gdb/gdb-index.h" -#include #include "gdb_bfd.h" #include "f-lang.h" #include "source.h" -#include "gdbsupport/filestuff.h" #include "build-id.h" #include "namespace.h" -#include "gdbsupport/gdb_unlinker.h" #include "gdbsupport/function-view.h" #include "gdbsupport/gdb_optional.h" #include "gdbsupport/underlying.h" -#include "gdbsupport/byte-vector.h" #include "gdbsupport/hash_enum.h" #include "filename-seen-cache.h" #include "producer.h" #include -#include #include -#include #include #include "gdbsupport/selftest.h" -#include -#include -#include #include "rust-lang.h" #include "gdbsupport/pathstuff.h" @@ -922,13 +909,13 @@ typedef void (die_reader_func_ftype) (const struct die_reader_specs *reader, int has_children, void *data); -/* A 1-based directory index. This is a strong typedef to prevent - accidentally using a directory index as a 0-based index into an - array/vector. */ -enum class dir_index : unsigned int {}; +/* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and + later. */ +typedef int dir_index; -/* Likewise, a 1-based file name index. */ -enum class file_name_index : unsigned int {}; +/* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 + and later. */ +typedef int file_name_index; struct file_entry { @@ -980,32 +967,47 @@ struct line_header void add_file_name (const char *name, dir_index d_index, unsigned int mod_time, unsigned int length); - /* Return the include dir at INDEX (1-based). Returns NULL if INDEX - is out of bounds. */ + /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before). + Returns NULL if INDEX is out of bounds. */ const char *include_dir_at (dir_index index) const { - /* Convert directory index number (1-based) to vector index - (0-based). */ - size_t vec_index = to_underlying (index) - 1; - - if (vec_index >= include_dirs.size ()) + int vec_index; + if (version >= 5) + vec_index = index; + else + vec_index = index - 1; + if (vec_index < 0 || vec_index >= m_include_dirs.size ()) return NULL; - return include_dirs[vec_index]; + return m_include_dirs[vec_index]; } - /* Return the file name at INDEX (1-based). Returns NULL if INDEX - is out of bounds. */ - file_entry *file_name_at (file_name_index index) + bool is_valid_file_index (int file_index) { - /* Convert file name index number (1-based) to vector index - (0-based). */ - size_t vec_index = to_underlying (index) - 1; + if (version >= 5) + return 0 <= file_index && file_index < file_names_size (); + return 1 <= file_index && file_index <= file_names_size (); + } - if (vec_index >= file_names.size ()) + /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before). + Returns NULL if INDEX is out of bounds. */ + file_entry *file_name_at (file_name_index index) + { + int vec_index; + if (version >= 5) + vec_index = index; + else + vec_index = index - 1; + if (vec_index < 0 || vec_index >= m_file_names.size ()) return NULL; - return &file_names[vec_index]; + return &m_file_names[vec_index]; } + /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore, + this method should only be used to iterate through all file entries in an + index-agnostic manner. */ + std::vector &file_names () + { return m_file_names; } + /* Offset of line number information in .debug_line section. */ sect_offset sect_off {}; @@ -1028,16 +1030,23 @@ struct line_header element is standard_opcode_lengths[opcode_base - 1]. */ std::unique_ptr standard_opcode_lengths; - /* The include_directories table. Note these are observing - pointers. The memory is owned by debug_line_buffer. */ - std::vector include_dirs; - - /* The file_names table. */ - std::vector file_names; + int file_names_size () + { return m_file_names.size(); } /* The start and end of the statement program following this header. These point into dwarf2_per_objfile->line_buffer. */ const gdb_byte *statement_program_start {}, *statement_program_end {}; + + private: + /* The include_directories table. Note these are observing + pointers. The memory is owned by debug_line_buffer. */ + std::vector m_include_dirs; + + /* The file_names table. This is private because the meaning of indexes + differs among DWARF versions (The first valid index is 1 in DWARF 4 and + before, and is 0 in DWARF 5 and later). So the client should use + file_name_at method for access. */ + std::vector m_file_names; }; typedef std::unique_ptr line_header_up; @@ -1388,7 +1397,7 @@ struct field_info /* Number of fields (including baseclasses). */ int nfields = 0; - /* Set if the accesibility of one of the fields is not public. */ + /* Set if the accessibility of one of the fields is not public. */ int non_public_fields = 0; /* Member function fieldlist array, contains name of possibly overloaded @@ -1499,7 +1508,7 @@ struct cu_partial_die_info cu_partial_die_info (struct dwarf2_cu *cu, struct partial_die_info *pdi) : cu (cu), pdi (pdi) - { /* Nothhing. */ } + { /* Nothing. */ } private: cu_partial_die_info () = delete; @@ -2164,10 +2173,10 @@ dwarf2_per_objfile::~dwarf2_per_objfile () htab_delete (line_header_hash); for (dwarf2_per_cu_data *per_cu : all_comp_units) - VEC_free (dwarf2_per_cu_ptr, per_cu->imported_symtabs); + per_cu->imported_symtabs_free (); for (signatured_type *sig_type : all_type_units) - VEC_free (dwarf2_per_cu_ptr, sig_type->per_cu.imported_symtabs); + sig_type->per_cu.imported_symtabs_free (); /* Everything else should be on the objfile obstack. */ } @@ -2351,6 +2360,15 @@ dwarf2_per_objfile::locate_sections (bfd *abfd, asection *sectp, if ((aflag & SEC_HAS_CONTENTS) == 0) { } + else if (elf_section_data (sectp)->this_hdr.sh_size + > bfd_get_file_size (abfd)) + { + bfd_size_type size = elf_section_data (sectp)->this_hdr.sh_size; + warning (_("Discarding section %s which has a section size (%s" + ") larger than the file size [in module %s]"), + bfd_section_name (sectp), phex_nz (size, sizeof (size)), + bfd_get_filename (abfd)); + } else if (section_is_p (sectp->name, &names.info)) { this->info.s.section = sectp; @@ -3644,7 +3662,6 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader, struct objfile *objfile = dwarf2_per_objfile->objfile; struct dwarf2_per_cu_data *lh_cu; struct attribute *attr; - int i; void **slot; struct quick_file_names *qfn; @@ -3703,12 +3720,12 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader, if (strcmp (fnd.name, "") != 0) ++offset; - qfn->num_file_names = offset + lh->file_names.size (); + qfn->num_file_names = offset + lh->file_names_size (); qfn->file_names = XOBNEWVEC (&objfile->objfile_obstack, const char *, qfn->num_file_names); if (offset != 0) qfn->file_names[0] = xstrdup (fnd.name); - for (i = 0; i < lh->file_names.size (); ++i) + for (int i = 0; i < lh->file_names_size (); ++i) qfn->file_names[i + offset] = file_full_name (i + 1, lh.get (), fnd.comp_dir); qfn->real_names = NULL; @@ -4025,6 +4042,10 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter) if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER) continue; break; + case MODULE_DOMAIN: + if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER) + continue; + break; default: break; } @@ -5047,6 +5068,10 @@ dw2_expand_marked_cus if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) continue; break; + case MODULES_DOMAIN: + if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER) + continue; + break; default: break; } @@ -5953,6 +5978,15 @@ dw2_debug_names_iterator::next () goto again; } break; + case MODULE_DOMAIN: + switch (indexval.dwarf_tag) + { + case DW_TAG_module: + break; + default: + goto again; + } + break; default: break; } @@ -5989,6 +6023,14 @@ dw2_debug_names_iterator::next () goto again; } break; + case MODULES_DOMAIN: + switch (indexval.dwarf_tag) + { + case DW_TAG_module: + break; + default: + goto again; + } default: break; } @@ -8092,24 +8134,23 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, end_psymtab_common (objfile, pst); - if (!VEC_empty (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs)) + if (!cu->per_cu->imported_symtabs_empty ()) { int i; - int len = VEC_length (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs); - struct dwarf2_per_cu_data *iter; + int len = cu->per_cu->imported_symtabs_size (); /* Fill in 'dependencies' here; we fill in 'users' in a post-pass. */ pst->number_of_dependencies = len; pst->dependencies = objfile->partial_symtabs->allocate_dependencies (len); - for (i = 0; - VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs, - i, iter); - ++i) - pst->dependencies[i] = iter->v.psymtab; + for (i = 0; i < len; ++i) + { + pst->dependencies[i] + = cu->per_cu->imported_symtabs->at (i)->v.psymtab; + } - VEC_free (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs); + cu->per_cu->imported_symtabs_free (); } /* Get the list of files included in the current compilation unit, @@ -8717,7 +8758,8 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, add_partial_namespace (pdi, lowpc, highpc, set_addrmap, cu); break; case DW_TAG_module: - add_partial_module (pdi, lowpc, highpc, set_addrmap, cu); + if (!pdi->is_declaration) + add_partial_module (pdi, lowpc, highpc, set_addrmap, cu); break; case DW_TAG_imported_unit: { @@ -8739,8 +8781,7 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, if (per_cu->v.psymtab == NULL) process_psymtab_comp_unit (per_cu, 1, cu->language); - VEC_safe_push (dwarf2_per_cu_ptr, - cu->per_cu->imported_symtabs, per_cu); + cu->per_cu->imported_symtabs_push (per_cu); } break; case DW_TAG_imported_declaration: @@ -8823,6 +8864,7 @@ partial_die_parent_scope (struct partial_die_info *pdi, return NULL; } + /* Nested subroutines in Fortran get a prefix. */ if (pdi->tag == DW_TAG_enumerator) /* Enumerators should not get the name of the enumeration as a prefix. */ parent->scope = grandparent_scope; @@ -8832,7 +8874,10 @@ partial_die_parent_scope (struct partial_die_info *pdi, || parent->tag == DW_TAG_class_type || parent->tag == DW_TAG_interface_type || parent->tag == DW_TAG_union_type - || parent->tag == DW_TAG_enumeration_type) + || parent->tag == DW_TAG_enumeration_type + || (cu->language == language_fortran + && parent->tag == DW_TAG_subprogram + && pdi->tag == DW_TAG_subprogram)) { if (grandparent_scope == NULL) parent->scope = parent->name; @@ -8923,13 +8968,17 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) case DW_TAG_subprogram: addr = (gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr) - baseaddr); - if (pdi->is_external || cu->language == language_ada) - { - /* brobecker/2007-12-26: Normally, only "external" DIEs are part - of the global scope. But in Ada, we want to be able to access - nested procedures globally. So all Ada subprograms are stored - in the global scope. */ - add_psymbol_to_list (actual_name, strlen (actual_name), + if (pdi->is_external + || cu->language == language_ada + || (cu->language == language_fortran + && pdi->die_parent != NULL + && pdi->die_parent->tag == DW_TAG_subprogram)) + { + /* Normally, only "external" DIEs are part of the global scope. + But in Ada and Fortran, we want to be able to access nested + procedures globally. So all Ada and Fortran subprograms are + stored in the global scope. */ + add_psymbol_to_list (actual_name, built_actual_name != NULL, VAR_DOMAIN, LOC_BLOCK, SECT_OFF_TEXT (objfile), @@ -8939,7 +8988,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) } else { - add_psymbol_to_list (actual_name, strlen (actual_name), + add_psymbol_to_list (actual_name, built_actual_name != NULL, VAR_DOMAIN, LOC_BLOCK, SECT_OFF_TEXT (objfile), @@ -8951,7 +9000,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) set_objfile_main_name (objfile, actual_name, cu->language); break; case DW_TAG_constant: - add_psymbol_to_list (actual_name, strlen (actual_name), + add_psymbol_to_list (actual_name, built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC, -1, (pdi->is_external ? psymbol_placement::GLOBAL @@ -8987,7 +9036,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) table building. */ if (pdi->d.locdesc || pdi->has_type) - add_psymbol_to_list (actual_name, strlen (actual_name), + add_psymbol_to_list (actual_name, built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC, SECT_OFF_TEXT (objfile), @@ -9006,7 +9055,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) return; } - add_psymbol_to_list (actual_name, strlen (actual_name), + add_psymbol_to_list (actual_name, built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC, SECT_OFF_TEXT (objfile), @@ -9018,7 +9067,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) case DW_TAG_typedef: case DW_TAG_base_type: case DW_TAG_subrange_type: - add_psymbol_to_list (actual_name, strlen (actual_name), + add_psymbol_to_list (actual_name, built_actual_name != NULL, VAR_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::STATIC, @@ -9026,7 +9075,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) break; case DW_TAG_imported_declaration: case DW_TAG_namespace: - add_psymbol_to_list (actual_name, strlen (actual_name), + add_psymbol_to_list (actual_name, built_actual_name != NULL, VAR_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::GLOBAL, @@ -9037,7 +9086,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) available without any name. If so, we skip the module as it doesn't bring any value. */ if (actual_name != nullptr) - add_psymbol_to_list (actual_name, strlen (actual_name), + add_psymbol_to_list (actual_name, built_actual_name != NULL, MODULE_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::GLOBAL, @@ -9061,7 +9110,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) /* NOTE: carlton/2003-10-07: See comment in new_symbol about static vs. global. */ - add_psymbol_to_list (actual_name, strlen (actual_name), + add_psymbol_to_list (actual_name, built_actual_name != NULL, STRUCT_DOMAIN, LOC_TYPEDEF, -1, cu->language == language_cplus @@ -9071,7 +9120,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) break; case DW_TAG_enumerator: - add_psymbol_to_list (actual_name, strlen (actual_name), + add_psymbol_to_list (actual_name, built_actual_name != NULL, VAR_DOMAIN, LOC_CONST, -1, cu->language == language_cplus @@ -9184,7 +9233,7 @@ add_partial_subprogram (struct partial_die_info *pdi, if (! pdi->has_children) return; - if (cu->language == language_ada) + if (cu->language == language_ada || cu->language == language_fortran) { pdi = pdi->die_child; while (pdi != NULL) @@ -9901,8 +9950,7 @@ fixup_go_packaging (struct dwarf2_cu *cu) sym = allocate_symbol (objfile); SYMBOL_SET_LANGUAGE (sym, language_go, &objfile->objfile_obstack); - SYMBOL_SET_NAMES (sym, saved_package_name, - strlen (saved_package_name), 0, objfile); + SYMBOL_SET_NAMES (sym, saved_package_name, false, objfile); /* This is not VAR_DOMAIN because we want a way to ensure a lookup of, e.g., "main" finds the "main" module and not C's main(). */ SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; @@ -10068,10 +10116,10 @@ quirk_rust_enum (struct type *type, struct objfile *objfile) SET_FIELD_BITPOS (TYPE_FIELD (type, 0), 0); TYPE_FIELD_NAME (type, 0) = "<>"; } - else if (TYPE_NFIELDS (type) == 1) + /* A union with a single anonymous field is probably an old-style + univariant enum. */ + else if (TYPE_NFIELDS (type) == 1 && streq (TYPE_FIELD_NAME (type, 0), "")) { - /* We assume that a union with a single field is a univariant - enum. */ /* Smash this type to be a structure type. We have to do this because the type has already been recorded. */ TYPE_CODE (type) = TYPE_CODE_STRUCT; @@ -10248,9 +10296,7 @@ recursively_compute_inclusions (std::vector *result, struct compunit_symtab *immediate_parent) { void **slot; - int ix; struct compunit_symtab *cust; - struct dwarf2_per_cu_data *iter; slot = htab_find_slot (all_children, per_cu, INSERT); if (*slot != NULL) @@ -10285,13 +10331,12 @@ recursively_compute_inclusions (std::vector *result, } } - for (ix = 0; - VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, ix, iter); - ++ix) - { - recursively_compute_inclusions (result, all_children, - all_type_symtabs, iter, cust); - } + if (!per_cu->imported_symtabs_empty ()) + for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs) + { + recursively_compute_inclusions (result, all_children, + all_type_symtabs, ptr, cust); + } } /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of @@ -10302,10 +10347,9 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu) { gdb_assert (! per_cu->is_debug_types); - if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->imported_symtabs)) + if (!per_cu->imported_symtabs_empty ()) { - int ix, len; - struct dwarf2_per_cu_data *per_cu_iter; + int len; std::vector result_symtabs; htab_t all_children, all_type_symtabs; struct compunit_symtab *cust = get_compunit_symtab (per_cu); @@ -10319,14 +10363,10 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu) 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, per_cu_iter); - ++ix) + for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs) { recursively_compute_inclusions (&result_symtabs, all_children, - all_type_symtabs, per_cu_iter, - cust); + all_type_symtabs, ptr, cust); } /* Now we have a transitive closure of all the included symtabs. */ @@ -10570,8 +10610,7 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu) if (maybe_queue_comp_unit (cu, per_cu, cu->language)) load_full_comp_unit (per_cu, false, cu->language); - VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs, - per_cu); + cu->per_cu->imported_symtabs_push (per_cu); } } @@ -10626,6 +10665,12 @@ process_die (struct die_info *die, struct dwarf2_cu *cu) read_type_unit_scope (die, cu); break; case DW_TAG_subprogram: + /* Nested subprograms in Fortran get a prefix. */ + if (cu->language == language_fortran + && die->parent != NULL + && die->parent->tag == DW_TAG_subprogram) + cu->processing_has_namespace_info = true; + /* Fall through. */ case DW_TAG_inlined_subroutine: read_func_scope (die, cu); break; @@ -11703,14 +11748,14 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die) process_full_type_unit still needs to know if this is the first time. */ - tu_group->num_symtabs = line_header->file_names.size (); + tu_group->num_symtabs = line_header->file_names_size (); tu_group->symtabs = XNEWVEC (struct symtab *, - line_header->file_names.size ()); + line_header->file_names_size ()); - for (i = 0; i < line_header->file_names.size (); ++i) + auto &file_names = line_header->file_names (); + for (i = 0; i < file_names.size (); ++i) { - file_entry &fe = line_header->file_names[i]; - + file_entry &fe = file_names[i]; dwarf2_start_subfile (this, fe.name, fe.include_dir (line_header)); buildsym_compunit *b = get_builder (); @@ -11739,10 +11784,10 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die) compunit_language (cust), 0, cust)); - for (i = 0; i < line_header->file_names.size (); ++i) + auto &file_names = line_header->file_names (); + for (i = 0; i < file_names.size (); ++i) { - file_entry &fe = line_header->file_names[i]; - + file_entry &fe = file_names[i]; fe.symtab = tu_group->symtabs[i]; } } @@ -13497,7 +13542,7 @@ queue_and_load_dwo_tu (void **slot, void *info) while processing PER_CU. */ if (maybe_queue_comp_unit (NULL, sig_cu, per_cu->cu->language)) load_full_type_unit (sig_cu); - VEC_safe_push (dwarf2_per_cu_ptr, per_cu->imported_symtabs, sig_cu); + per_cu->imported_symtabs_push (sig_cu); } return 1; @@ -14943,7 +14988,7 @@ producer_is_codewarrior (struct dwarf2_cu *cu) return cu->producer_is_codewarrior; } -/* Return the default accessibility type if it is not overriden by +/* Return the default accessibility type if it is not overridden by DW_AT_accessibility. */ static enum dwarf_access_attribute @@ -16216,7 +16261,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) { /* Any related symtab will do. */ symtab - = cu->line_header->file_name_at (file_name_index (1))->symtab; + = cu->line_header->file_names ()[0].symtab; } else { @@ -16752,7 +16797,7 @@ mark_common_block_symbol_computed (struct symbol *sym, /* Create appropriate locally-scoped variables for all the DW_TAG_common_block entries. Also create a struct common_block listing all such variables for `info common'. COMMON_BLOCK_DOMAIN - is used to sepate the common blocks name namespace from regular + is used to separate the common blocks name namespace from regular variable names. */ static void @@ -17310,7 +17355,7 @@ prototyped_function_p (struct die_info *die, struct dwarf2_cu *cu) return 1; /* The DWARF standard implies that the DW_AT_prototyped attribute - is only meaninful for C, but the concept also extends to other + is only meaningful for C, but the concept also extends to other languages that allow unprototyped functions (Eg: Objective C). For all other languages, assume that functions are always prototyped. */ @@ -18040,7 +18085,7 @@ read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) TYPE_NAME (type) = dwarf2_name (die, cu); /* In Ada, an unspecified type is typically used when the description - of the type is defered to a different unit. When encountering + of the type is deferred to a different unit. When encountering such a type, we treat it as a stub, and try to resolve it later on, when needed. */ if (cu->language == language_ada) @@ -18546,7 +18591,7 @@ load_partial_dies (const struct die_reader_specs *reader, || pdi.tag == DW_TAG_subrange_type)) { if (building_psymtab && pdi.name != NULL) - add_psymbol_to_list (pdi.name, strlen (pdi.name), false, + add_psymbol_to_list (pdi.name, false, VAR_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::STATIC, 0, cu->language, objfile); @@ -18580,7 +18625,7 @@ load_partial_dies (const struct die_reader_specs *reader, if (pdi.name == NULL) complaint (_("malformed enumerator DIE ignored")); else if (building_psymtab) - add_psymbol_to_list (pdi.name, strlen (pdi.name), false, + add_psymbol_to_list (pdi.name, false, VAR_DOMAIN, LOC_CONST, -1, cu->language == language_cplus ? psymbol_placement::GLOBAL @@ -18653,10 +18698,10 @@ load_partial_dies (const struct die_reader_specs *reader, inside functions to find template arguments (if the name of the function does not already contain the template arguments). - For Ada, we need to scan the children of subprograms and lexical - blocks as well because Ada allows the definition of nested - entities that could be interesting for the debugger, such as - nested subprograms for instance. */ + For Ada and Fortran, we need to scan the children of subprograms + and lexical blocks as well because these languages allow the + definition of nested entities that could be interesting for the + debugger, such as nested subprograms for instance. */ if (last_die->has_children && (load_all || last_die->tag == DW_TAG_namespace @@ -18671,7 +18716,8 @@ load_partial_dies (const struct die_reader_specs *reader, || last_die->tag == DW_TAG_interface_type || last_die->tag == DW_TAG_structure_type || last_die->tag == DW_TAG_union_type)) - || (cu->language == language_ada + || ((cu->language == language_ada + || cu->language == language_fortran) && (last_die->tag == DW_TAG_subprogram || last_die->tag == DW_TAG_lexical_block)))) { @@ -20199,7 +20245,7 @@ dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *c } /* Return the dwo name or NULL if not present. If present, it is in either - DW_AT_GNU_dwo_name or DW_AT_dwo_name atrribute. */ + DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */ static const char * dwarf2_dwo_name (struct die_info *die, struct dwarf2_cu *cu) { @@ -20270,10 +20316,16 @@ void line_header::add_include_dir (const char *include_dir) { if (dwarf_line_debug >= 2) - fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n", - include_dirs.size () + 1, include_dir); - - include_dirs.push_back (include_dir); + { + size_t new_size; + if (version >= 5) + new_size = m_include_dirs.size (); + else + new_size = m_include_dirs.size () + 1; + fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n", + new_size, include_dir); + } + m_include_dirs.push_back (include_dir); } void @@ -20283,10 +20335,16 @@ line_header::add_file_name (const char *name, unsigned int length) { if (dwarf_line_debug >= 2) - fprintf_unfiltered (gdb_stdlog, "Adding file %u: %s\n", - (unsigned) file_names.size () + 1, name); - - file_names.emplace_back (name, d_index, mod_time, length); + { + size_t new_size; + if (version >= 5) + new_size = file_names_size (); + else + new_size = file_names_size () + 1; + fprintf_unfiltered (gdb_stdlog, "Adding file %zu: %s\n", + new_size, name); + } + m_file_names.emplace_back (name, d_index, mod_time, length); } /* A convenience function to find the proper .debug_line section for a CU. */ @@ -20400,6 +20458,11 @@ read_formatted_entries (struct dwarf2_per_objfile *dwarf2_per_objfile, buf += 8; break; + case DW_FORM_data16: + /* This is used for MD5, but file_entry does not record MD5s. */ + buf += 16; + break; + case DW_FORM_udata: uint.emplace (read_unsigned_leb128 (abfd, buf, &bytes_read)); buf += bytes_read; @@ -20500,12 +20563,15 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu) read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, &bytes_read, &offset_size); line_ptr += bytes_read; + + const gdb_byte *start_here = line_ptr; + if (line_ptr + lh->total_length > (section->buffer + section->size)) { dwarf2_statement_list_fits_in_line_number_section_complaint (); return 0; } - lh->statement_program_end = line_ptr + lh->total_length; + lh->statement_program_end = start_here + lh->total_length; lh->version = read_2_bytes (abfd, line_ptr); line_ptr += 2; if (lh->version > 5) @@ -20535,6 +20601,7 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu) } lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); line_ptr += offset_size; + lh->statement_program_start = line_ptr + lh->header_length; lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); line_ptr += 1; if (lh->version >= 4) @@ -20619,7 +20686,6 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu) } line_ptr += bytes_read; } - lh->statement_program_start = line_ptr; if (line_ptr > (section->buffer + section->size)) complaint (_("line number info header doesn't " @@ -20629,19 +20695,17 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu) } /* Subroutine of dwarf_decode_lines to simplify it. - Return the file name of the psymtab for included file FILE_INDEX - in line header LH of PST. + Return the file name of the psymtab for the given file_entry. COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. If space for the result is malloc'd, *NAME_HOLDER will be set. Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ static const char * -psymtab_include_file_name (const struct line_header *lh, int file_index, +psymtab_include_file_name (const struct line_header *lh, const file_entry &fe, const struct partial_symtab *pst, const char *comp_dir, gdb::unique_xmalloc_ptr *name_holder) { - const file_entry &fe = lh->file_names[file_index]; const char *include_name = fe.name; const char *include_name_to_compare = include_name; const char *pst_filename; @@ -20816,8 +20880,8 @@ private: and initialized according to the DWARF spec. */ unsigned char m_op_index = 0; - /* The line table index (1-based) of the current file. */ - file_name_index m_file = (file_name_index) 1; + /* The line table index of the current file. */ + file_name_index m_file = 1; unsigned int m_line = 1; /* These are initialized in the constructor. */ @@ -21009,7 +21073,7 @@ lnp_state_machine::record_line (bool end_sequence) fprintf_unfiltered (gdb_stdlog, "Processing actual line %u: file %u," " address %s, is_stmt %u, discrim %u\n", - m_line, to_underlying (m_file), + m_line, m_file, paddress (m_gdbarch, m_address), m_is_stmt, m_discriminator); } @@ -21348,17 +21412,15 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, if (decode_for_pst_p) { - int file_index; - /* Now that we're done scanning the Line Header Program, we can create the psymtab of each included file. */ - for (file_index = 0; file_index < lh->file_names.size (); file_index++) - if (lh->file_names[file_index].included_p == 1) + for (auto &file_entry : lh->file_names ()) + if (file_entry.included_p == 1) { gdb::unique_xmalloc_ptr name_holder; const char *include_name = - psymtab_include_file_name (lh, file_index, pst, comp_dir, - &name_holder); + psymtab_include_file_name (lh, file_entry, pst, + comp_dir, &name_holder); if (include_name != NULL) dwarf2_create_include_psymtab (include_name, pst, objfile); } @@ -21370,14 +21432,10 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, line numbers). */ buildsym_compunit *builder = cu->get_builder (); struct compunit_symtab *cust = builder->get_compunit_symtab (); - int i; - for (i = 0; i < lh->file_names.size (); i++) + for (auto &fe : lh->file_names ()) { - file_entry &fe = lh->file_names[i]; - dwarf2_start_subfile (cu, fe.name, fe.include_dir (lh)); - if (builder->get_current_subfile ()->symtab == NULL) { builder->get_current_subfile ()->symtab @@ -21573,7 +21631,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, /* Cache this symbol's name and the name's demangled form (if any). */ SYMBOL_SET_LANGUAGE (sym, cu->language, &objfile->objfile_obstack); linkagename = dwarf2_physname (name, die, cu); - SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); + SYMBOL_SET_NAMES (sym, linkagename, false, objfile); /* Fortran does not have mangling standard and the mangling does differ between gfortran, iFort etc. */ @@ -21641,14 +21699,15 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK; attr2 = dwarf2_attr (die, DW_AT_external, cu); if ((attr2 && (DW_UNSND (attr2) != 0)) - || cu->language == language_ada) + || cu->language == language_ada + || cu->language == language_fortran) { /* Subprograms marked external are stored as a global symbol. - Ada subprograms, whether marked external or not, are always - stored as a global symbol, because we want to be able to - access them globally. For instance, we want to be able - to break on a nested subprogram without having to - specify the context. */ + Ada and Fortran subprograms, whether marked external or + not, are always stored as a global symbol, because we want + to be able to access them globally. For instance, we want + to be able to break on a nested subprogram without having + to specify the context. */ list_to_add = cu->get_builder ()->get_global_symbols (); } else @@ -22645,6 +22704,16 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu) return name; } return ""; + case DW_TAG_subprogram: + /* Nested subroutines in Fortran get a prefix with the name + of the parent's subroutine. */ + if (cu->language == language_fortran) + { + if ((die->tag == DW_TAG_subprogram) + && (dwarf2_name (parent, cu) != NULL)) + return dwarf2_name (parent, cu); + } + return determine_prefix (parent, cu); case DW_TAG_enumeration_type: parent_type = read_type_die (parent, cu); if (TYPE_DECLARED_CLASS (parent_type)) @@ -23652,9 +23721,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type, if (dwarf2_per_objfile->index_table != NULL && dwarf2_per_objfile->index_table->version <= 7) { - VEC_safe_push (dwarf2_per_cu_ptr, - (*ref_cu)->per_cu->imported_symtabs, - sig_cu->per_cu); + (*ref_cu)->per_cu->imported_symtabs_push (sig_cu->per_cu); } *ref_cu = sig_cu; @@ -24173,17 +24240,17 @@ file_file_name (int file, struct line_header *lh) { /* Is the file number a valid index into the line header's file name table? Remember that file numbers start with one, not zero. */ - if (1 <= file && file <= lh->file_names.size ()) + if (lh->is_valid_file_index (file)) { - const file_entry &fe = lh->file_names[file - 1]; + const file_entry *fe = lh->file_name_at (file); - if (!IS_ABSOLUTE_PATH (fe.name)) + if (!IS_ABSOLUTE_PATH (fe->name)) { - const char *dir = fe.include_dir (lh); + const char *dir = fe->include_dir (lh); if (dir != NULL) - return concat (dir, SLASH_STRING, fe.name, (char *) NULL); + return concat (dir, SLASH_STRING, fe->name, (char *) NULL); } - return xstrdup (fe.name); + return xstrdup (fe->name); } else { @@ -24211,7 +24278,7 @@ file_full_name (int file, struct line_header *lh, const char *comp_dir) { /* Is the file number a valid index into the line header's file name table? Remember that file numbers start with one, not zero. */ - if (1 <= file && file <= lh->file_names.size ()) + if (lh->is_valid_file_index (file)) { char *relative = file_file_name (file, lh); @@ -25613,7 +25680,7 @@ per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs) table if necessary. For convenience, return TYPE. The DIEs reading must have careful ordering to: - * Not cause infite loops trying to read in DIEs as a prerequisite for + * Not cause infinite loops trying to read in DIEs as a prerequisite for reading current DIE. * Not trying to dereference contents of still incompletely read in types while reading in other DIEs.