#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"
#include "addrmap.h"
#include "typeprint.h"
#include "psympriv.h"
-#include <sys/stat.h>
-#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 <ctype.h>
#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 <fcntl.h>
-#include <sys/types.h>
#include <algorithm>
-#include <unordered_set>
#include <unordered_map>
#include "gdbsupport/selftest.h"
-#include <cmath>
-#include <set>
-#include <forward_list>
#include "rust-lang.h"
#include "gdbsupport/pathstuff.h"
/* The TUs that share this DW_AT_stmt_list entry.
This is added to while parsing type units to build partial symtabs,
and is deleted afterwards and not used again. */
- std::vector <signatured_type *> *tus;
+ std::vector<signatured_type *> *tus;
/* The compunit symtab.
Type units in a group needn't all be defined in the same source file,
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;
/* See declaration. */
dwarf2_per_objfile::dwarf2_per_objfile (struct objfile *objfile_,
- const dwarf2_debug_sections *names)
- : objfile (objfile_)
+ const dwarf2_debug_sections *names,
+ bool can_copy_)
+ : objfile (objfile_),
+ can_copy (can_copy_)
{
if (names == NULL)
names = &dwarf2_elf_names;
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. */
}
/* Try to locate the sections we need for DWARF 2 debugging
information and return true if we have enough to do something.
NAMES points to the dwarf2 section names, or is NULL if the standard
- ELF names are used. */
+ ELF names are used. CAN_COPY is true for formats where symbol
+ interposition is possible and so symbol values must follow copy
+ relocation rules. */
int
dwarf2_has_info (struct objfile *objfile,
- const struct dwarf2_debug_sections *names)
+ const struct dwarf2_debug_sections *names,
+ bool can_copy)
{
if (objfile->flags & OBJF_READNEVER)
return 0;
if (dwarf2_per_objfile == NULL)
dwarf2_per_objfile = dwarf2_objfile_data_key.emplace (objfile, objfile,
- names);
+ names,
+ can_copy);
return (!dwarf2_per_objfile->info.is_virtual
&& dwarf2_per_objfile->info.s.section != NULL
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;
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,
tu_group = get_type_unit_group (cu, attr);
if (tu_group->tus == nullptr)
- tu_group->tus = new std::vector <signatured_type *>;
+ tu_group->tus = new std::vector<signatured_type *>;
tu_group->tus->push_back (sig_type);
prepare_one_comp_unit (cu, type_unit_die, language_minimal);
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:
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;
|| 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;
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. */
+ 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, strlen (actual_name),
built_actual_name != NULL,
VAR_DOMAIN, LOC_BLOCK,
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)
SET_FIELD_BITPOS (TYPE_FIELD (type, 0), 0);
TYPE_FIELD_NAME (type, 0) = "<<variants>>";
}
- 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;
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)
}
}
- 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
{
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<compunit_symtab *> result_symtabs;
htab_t all_children, all_type_symtabs;
struct compunit_symtab *cust = get_compunit_symtab (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. */
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);
}
}
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;
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;
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
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
|| 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))))
{
unsigned int dummy;
if (DW_BLOCK (attr)->data[0] == DW_OP_addr)
- SYMBOL_VALUE_ADDRESS (sym) =
- read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
+ SET_SYMBOL_VALUE_ADDRESS (sym,
+ read_address (objfile->obfd,
+ DW_BLOCK (attr)->data + 1,
+ cu, &dummy));
else
- SYMBOL_VALUE_ADDRESS (sym) =
- read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1, &dummy);
+ SET_SYMBOL_VALUE_ADDRESS
+ (sym, read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1,
+ &dummy));
SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
fixup_symbol_section (sym, objfile);
- SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
- SYMBOL_SECTION (sym));
+ SET_SYMBOL_VALUE_ADDRESS (sym,
+ SYMBOL_VALUE_ADDRESS (sym)
+ + ANOFFSET (objfile->section_offsets,
+ SYMBOL_SECTION (sym)));
return;
}
addr = attr_value_as_address (attr);
addr = gdbarch_adjust_dwarf2_addr (gdbarch, addr + baseaddr);
- SYMBOL_VALUE_ADDRESS (sym) = addr;
+ SET_SYMBOL_VALUE_ADDRESS (sym, addr);
}
SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
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
}
else if (attr2 && (DW_UNSND (attr2) != 0))
{
- /* Workaround gfortran PR debug/40040 - it uses
- DW_AT_location for variables in -fPIC libraries which may
- get overriden by other libraries/executable and get
- a different address. Resolve it by the minimal symbol
- which may come from inferior's executable using copy
- relocation. Make this workaround only for gfortran as for
- other compilers GDB cannot guess the minimal symbol
- Fortran mangling kind. */
- if (cu->language == language_fortran && die->parent
- && die->parent->tag == DW_TAG_module
- && cu->producer
- && startswith (cu->producer, "GNU Fortran"))
- SYMBOL_ACLASS_INDEX (sym) = LOC_UNRESOLVED;
+ if (SYMBOL_CLASS (sym) == LOC_STATIC
+ && (objfile->flags & OBJF_MAINLINE) == 0
+ && dwarf2_per_objfile->can_copy)
+ {
+ /* A global static variable might be subject to
+ copy relocation. We first check for a local
+ minsym, though, because maybe the symbol was
+ marked hidden, in which case this would not
+ apply. */
+ bound_minimal_symbol found
+ = (lookup_minimal_symbol_linkage
+ (SYMBOL_LINKAGE_NAME (sym), objfile));
+ if (found.minsym != nullptr)
+ sym->maybe_copied = 1;
+ }
/* A variable with DW_AT_external is never static,
but it may be block-scoped. */
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))
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;