/* DWARF 2 debugging format support for GDB.
- Copyright (C) 1994-2013 Free Software Foundation, Inc.
+ Copyright (C) 1994-2014 Free Software Foundation, Inc.
Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
Inc. with support from Florida State University (under contract
#include "jv-lang.h"
#include "psympriv.h"
#include "exceptions.h"
-#include "gdb_stat.h"
+#include <sys/stat.h>
#include "completer.h"
#include "vec.h"
#include "c-lang.h"
#include "build-id.h"
#include <fcntl.h>
-#include "gdb_string.h"
+#include <string.h>
#include "gdb_assert.h"
#include <sys/types.h>
static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
+static int read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu);
+
static struct type *read_module_type (struct die_info *die,
struct dwarf2_cu *cu);
do_cleanups (cleanup);
+ gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, dwz_bfd);
dwarf2_per_objfile->dwz_file = result;
return result;
}
return 0;
}
/* Version 7 indices generated by gold refer to the CU for a symbol instead
- of the TU (for symbols coming from TUs). It's just a performance bug, and
- we can't distinguish gdb-generated indices from gold-generated ones, so
- nothing to do here. */
+ of the TU (for symbols coming from TUs),
+ http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
+ Plus gold-generated indices can have duplicate entries for global symbols,
+ http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
+ These are just performance bugs, and we can't distinguish gdb-generated
+ indices from gold-generated ones, so issue no warning here. */
/* Indexes with higher version than the one supported by GDB may be no
longer backward compatible. */
int next;
/* The number of elements in VEC, or zero if there is no match. */
int length;
+ /* Have we seen a global version of the symbol?
+ If so we can ignore all further global instances.
+ This is to work around gold/15646, inefficient gold-generated
+ indices. */
+ int global_seen;
};
/* Initialize the index symtab iterator ITER.
iter->block_index = block_index;
iter->domain = domain;
iter->next = 0;
+ iter->global_seen = 0;
if (find_slot_in_mapped_hash (index, name, &iter->vec))
iter->length = MAYBE_SWAP (*iter->vec);
if (per_cu->v.quick->symtab)
continue;
- if (attrs_valid
- && iter->want_specific_block
- && want_static != is_static)
- continue;
+ /* Check static vs global. */
+ if (attrs_valid)
+ {
+ if (iter->want_specific_block
+ && want_static != is_static)
+ continue;
+ /* Work around gold/15646. */
+ if (!is_static && iter->global_seen)
+ continue;
+ if (!is_static)
+ iter->global_seen = 1;
+ }
/* Only check the symbol's kind if it has one. */
if (attrs_valid)
static void
dw2_expand_symtabs_matching
(struct objfile *objfile,
- int (*file_matcher) (const char *, void *, int basenames),
- int (*name_matcher) (const char *, void *),
+ expand_symtabs_file_matcher_ftype *file_matcher,
+ expand_symtabs_symbol_matcher_ftype *symbol_matcher,
enum search_domain kind,
void *data)
{
offset_type idx = 2 * iter;
const char *name;
offset_type *vec, vec_len, vec_idx;
+ int global_seen = 0;
if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
continue;
name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
- if (! (*name_matcher) (name, data))
+ if (! (*symbol_matcher) (name, data))
continue;
/* The name was matched, now expand corresponding CUs that were
{
struct dwarf2_per_cu_data *per_cu;
offset_type cu_index_and_attrs = MAYBE_SWAP (vec[vec_idx + 1]);
+ /* This value is only valid for index versions >= 7. */
+ int is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs);
gdb_index_symbol_kind symbol_kind =
GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs);
int cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs);
(index->version >= 7
&& symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE);
+ /* Work around gold/15646. */
+ if (attrs_valid)
+ {
+ if (!is_static && global_seen)
+ continue;
+ if (!is_static)
+ global_seen = 1;
+ }
+
/* Only check the symbol's kind if it has one. */
if (attrs_valid)
{
cu->per_cu->imported_symtabs, per_cu);
}
break;
+ case DW_TAG_imported_declaration:
+ add_partial_symbol (pdi, cu);
+ break;
default:
break;
}
&objfile->static_psymbols,
0, (CORE_ADDR) 0, cu->language, objfile);
break;
+ case DW_TAG_imported_declaration:
case DW_TAG_namespace:
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
&objfile->global_psymbols,
0, (CORE_ADDR) 0, cu->language, objfile);
break;
+ case DW_TAG_module:
+ add_psymbol_to_list (actual_name, strlen (actual_name),
+ built_actual_name != NULL,
+ MODULE_DOMAIN, LOC_TYPEDEF,
+ &objfile->global_psymbols,
+ 0, (CORE_ADDR) 0, cu->language, objfile);
+ break;
case DW_TAG_class_type:
case DW_TAG_interface_type:
case DW_TAG_structure_type:
add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
{
+ /* Add a symbol for the namespace. */
+
+ add_partial_symbol (pdi, cu);
+
/* Now scan partial symbols in that module. */
if (pdi->has_children)
read_module (die, cu);
break;
case DW_TAG_imported_declaration:
+ cu->processing_has_namespace_info = 1;
+ if (read_namespace_alias (die, cu))
+ break;
+ /* The declaration is not a global namespace alias: fall through. */
case DW_TAG_imported_module:
cu->processing_has_namespace_info = 1;
if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
case DW_TAG_enumerator:
case DW_TAG_subprogram:
case DW_TAG_member:
+ case DW_TAG_imported_declaration:
return 1;
case DW_TAG_variable:
return retval;
}
+/* Inspect DIE in CU for a namespace alias. If one exists, record
+ a new symbol for it.
+
+ Returns 1 if a namespace alias was recorded, 0 otherwise. */
+
+static int
+read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu)
+{
+ struct attribute *attr;
+
+ /* If the die does not have a name, this is not a namespace
+ alias. */
+ attr = dwarf2_attr (die, DW_AT_name, cu);
+ if (attr != NULL)
+ {
+ int num;
+ struct die_info *d = die;
+ struct dwarf2_cu *imported_cu = cu;
+
+ /* If the compiler has nested DW_AT_imported_declaration DIEs,
+ keep inspecting DIEs until we hit the underlying import. */
+#define MAX_NESTED_IMPORTED_DECLARATIONS 100
+ for (num = 0; num < MAX_NESTED_IMPORTED_DECLARATIONS; ++num)
+ {
+ attr = dwarf2_attr (d, DW_AT_import, cu);
+ if (attr == NULL)
+ break;
+
+ d = follow_die_ref (d, attr, &imported_cu);
+ if (d->tag != DW_TAG_imported_declaration)
+ break;
+ }
+
+ if (num == MAX_NESTED_IMPORTED_DECLARATIONS)
+ {
+ complaint (&symfile_complaints,
+ _("DIE at 0x%x has too many recursively imported "
+ "declarations"), d->offset.sect_off);
+ return 0;
+ }
+
+ if (attr != NULL)
+ {
+ struct type *type;
+ sect_offset offset = dwarf2_get_ref_die_offset (attr);
+
+ type = get_die_type_at_offset (offset, cu->per_cu);
+ if (type != NULL && TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
+ {
+ /* This declaration is a global namespace alias. Add
+ a symbol for it whose type is the aliased namespace. */
+ new_symbol (die, type, cu);
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
/* Read the import statement specified by the given die and record it. */
static void
If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
SEARCH_CWD is true if the current directory is to be searched.
It will be searched before debug-file-directory.
+ If successful, the file is added to the bfd include table of the
+ objfile's bfd (see gdb_bfd_record_inclusion).
If unable to find/open the file, return NULL.
NOTE: This function is derived from symfile_bfd_open. */
return NULL;
}
+ /* Success. Record the bfd as having been included by the objfile's bfd.
+ This is important because things like demangled_names_hash lives in the
+ objfile's per_bfd space and may have references to things like symbol
+ names that live in the DWO/DWP file's per_bfd space. PR 16426. */
+ gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, sym_bfd);
+
return sym_bfd;
}
if (dwp_file->cus->version != dwp_file->tus->version)
{
/* Technically speaking, we should try to limp along, but this is
- pretty bizarre. */
- error (_("Dwarf Error: DWP file CU version %d doesn't match"
- " TU version %d [in DWP file %s]"),
- dwp_file->cus->version, dwp_file->tus->version, dwp_name);
+ pretty bizarre. We use pulongest here because that's the established
+ portability solution (e.g, we cannot use %u for uint32_t). */
+ error (_("Dwarf Error: DWP file CU version %s doesn't match"
+ " TU version %s [in DWP file %s]"),
+ pulongest (dwp_file->cus->version),
+ pulongest (dwp_file->tus->version), dwp_name);
}
dwp_file->version = dwp_file->cus->version;
/* 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 (objfile));
+ {
+ /* Print the name of the DWP file if we looked there, helps the user
+ better diagnose the problem. */
+ char *dwp_text = NULL;
+ struct cleanup *cleanups;
+
+ if (dwp_file != NULL)
+ dwp_text = xstrprintf (" [in DWP file %s]", lbasename (dwp_file->name));
+ cleanups = make_cleanup (xfree, dwp_text);
+
+ warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
+ " [in module %s]"),
+ kind, dwo_name, hex_string (signature),
+ dwp_text != NULL ? dwp_text : "",
+ this_unit->is_debug_types ? "TU" : "CU",
+ this_unit->offset.sect_off, objfile_name (objfile));
+
+ do_cleanups (cleanups);
+ }
return NULL;
}
read_module (struct die_info *die, struct dwarf2_cu *cu)
{
struct die_info *child_die = die->child;
+ struct type *type;
+
+ type = read_type_die (die, cu);
+ new_symbol (die, type, cu);
while (child_die && child_die->tag)
{
struct attr_abbrev *cur_attrs;
unsigned int allocated_attrs;
- abbrev_table = XMALLOC (struct abbrev_table);
+ abbrev_table = XNEW (struct abbrev_table);
abbrev_table->offset = offset;
obstack_init (&abbrev_table->abbrev_obstack);
abbrev_table->abbrevs = obstack_alloc (&abbrev_table->abbrev_obstack,
&& abbrev->tag != DW_TAG_namespace
&& abbrev->tag != DW_TAG_module
&& abbrev->tag != DW_TAG_member
- && abbrev->tag != DW_TAG_imported_unit)
+ && abbrev->tag != DW_TAG_imported_unit
+ && abbrev->tag != DW_TAG_imported_declaration)
{
/* Otherwise we skip to the next sibling, if any. */
info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
practice. */
if (DW_UNSND (&attr) == DW_CC_program
&& cu->language == language_fortran)
- {
- set_main_name (part_die->name);
-
- /* As this DIE has a static linkage the name would be difficult
- to look up later. */
- language_of_main = language_fortran;
- }
+ set_objfile_main_name (objfile, part_die->name, language_fortran);
break;
case DW_AT_inline:
if (DW_UNSND (&attr) == DW_INL_inlined
? &global_symbols : cu->list_in_scope);
}
break;
+ case DW_TAG_imported_declaration:
case DW_TAG_namespace:
SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
list_to_add = &global_symbols;
break;
+ case DW_TAG_module:
+ SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
+ SYMBOL_DOMAIN (sym) = MODULE_DOMAIN;
+ list_to_add = &global_symbols;
+ break;
case DW_TAG_common_block:
SYMBOL_ACLASS_INDEX (sym) = LOC_COMMON_BLOCK;
SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;