Add target_ops argument to to_pid_to_exec_file
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
index 7e87ed9adde38402d707ac2bd7c3757ba87847a6..54c538af5fb8df8e569ebc3d9194997607b8898c 100644 (file)
@@ -1,6 +1,6 @@
 /* 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
@@ -56,7 +56,7 @@
 #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"
@@ -72,7 +72,7 @@
 #include "build-id.h"
 
 #include <fcntl.h>
-#include "gdb_string.h"
+#include <string.h>
 #include "gdb_assert.h"
 #include <sys/types.h>
 
@@ -1612,6 +1612,8 @@ static void read_module (struct die_info *die, struct dwarf2_cu *cu);
 
 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);
 
@@ -2430,6 +2432,7 @@ dwarf2_get_dwz_file (void)
 
   do_cleanups (cleanup);
 
+  gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, dwz_bfd);
   dwarf2_per_objfile->dwz_file = result;
   return result;
 }
@@ -3034,9 +3037,12 @@ to use the section anyway."),
       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.  */
@@ -3448,6 +3454,11 @@ struct dw2_symtab_iterator
   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.
@@ -3467,6 +3478,7 @@ dw2_symtab_iter_init (struct dw2_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);
@@ -3518,10 +3530,18 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
       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)
@@ -3751,8 +3771,8 @@ dw2_map_matching_symbols (struct objfile *objfile,
 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)
 {
@@ -3849,13 +3869,14 @@ dw2_expand_symtabs_matching
       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
@@ -3867,6 +3888,8 @@ dw2_expand_symtabs_matching
        {
          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);
@@ -3878,6 +3901,15 @@ dw2_expand_symtabs_matching
            (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)
            {
@@ -6488,6 +6520,9 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
                               cu->per_cu->imported_symtabs, per_cu);
              }
              break;
+           case DW_TAG_imported_declaration:
+             add_partial_symbol (pdi, cu);
+             break;
            default:
              break;
            }
@@ -6759,6 +6794,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
                           &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,
@@ -6766,6 +6802,13 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
                           &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:
@@ -6836,6 +6879,10 @@ static void
 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)
@@ -8032,6 +8079,10 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
       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
@@ -8074,6 +8125,7 @@ die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
     case DW_TAG_enumerator:
     case DW_TAG_subprogram:
     case DW_TAG_member:
+    case DW_TAG_imported_declaration:
       return 1;
 
     case DW_TAG_variable:
@@ -8493,6 +8545,66 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
   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
@@ -10011,6 +10123,8 @@ lookup_dwo_unit_in_dwp (struct dwp_file *dwp_file, const char *comp_dir,
    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.  */
 
@@ -10058,6 +10172,12 @@ try_open_dwop_file (const char *file_name, int is_dwp, int search_cwd)
       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;
 }
 
@@ -10424,10 +10544,12 @@ open_and_init_dwp_file (void)
   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;
 
@@ -10575,11 +10697,25 @@ lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit,
 
   /* 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;
 }
 
@@ -13560,6 +13696,10 @@ static void
 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)
     {
@@ -14595,7 +14735,7 @@ abbrev_table_read_table (struct dwarf2_section_info *section,
   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,
@@ -14853,7 +14993,8 @@ load_partial_dies (const struct die_reader_specs *reader,
          && 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);
@@ -15183,13 +15324,7 @@ read_partial_die (const struct die_reader_specs *reader,
             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
@@ -17584,10 +17719,16 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
                           ? &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;
This page took 0.033808 seconds and 4 git commands to generate.