proc-service, extern "C"
[deliverable/binutils-gdb.git] / gdb / ada-lang.c
index 5d4ea2f5c08d491fecbae25b241744ce92836f44..b01672358b1698d81ad3337ff5f064307b59e3e0 100644 (file)
@@ -1,6 +1,6 @@
 /* Ada language support routines for GDB, the GNU debugger.
 
-   Copyright (C) 1992-2014 Free Software Foundation, Inc.
+   Copyright (C) 1992-2015 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -274,7 +274,7 @@ struct cache_entry
   /* The name used to perform the lookup.  */
   const char *name;
   /* The namespace used during the lookup.  */
-  domain_enum namespace;
+  domain_enum domain;
   /* The symbol returned by the lookup, or NULL if no matching symbol
      was found.  */
   struct symbol *sym;
@@ -2928,8 +2928,19 @@ ada_array_bound_from_type (struct type *arr_type, int n, int which)
   else
     type = arr_type;
 
-  index_type_desc = ada_find_parallel_type (type, "___XA");
-  ada_fixup_array_indexes_type (index_type_desc);
+  if (TYPE_FIXED_INSTANCE (type))
+    {
+      /* The array has already been fixed, so we do not need to
+        check the parallel ___XA type again.  That encoding has
+        already been applied, so ignore it now.  */
+      index_type_desc = NULL;
+    }
+  else
+    {
+      index_type_desc = ada_find_parallel_type (type, "___XA");
+      ada_fixup_array_indexes_type (index_type_desc);
+    }
+
   if (index_type_desc != NULL)
     index_type = to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, n - 1),
                                      NULL);
@@ -3716,7 +3727,10 @@ See set/show multiple-symbol."));
             (SYMBOL_CLASS (syms[i].sym) == LOC_CONST
              && SYMBOL_TYPE (syms[i].sym) != NULL
              && TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) == TYPE_CODE_ENUM);
-          struct symtab *symtab = symbol_symtab (syms[i].sym);
+         struct symtab *symtab = NULL;
+
+         if (SYMBOL_OBJFILE_OWNED (syms[i].sym))
+           symtab = symbol_symtab (syms[i].sym);
 
           if (SYMBOL_LINE (syms[i].sym) != 0 && symtab != NULL)
             printf_unfiltered (_("[%d] %s at %s:%d\n"),
@@ -4390,15 +4404,14 @@ static struct ada_symbol_cache *
 ada_get_symbol_cache (struct program_space *pspace)
 {
   struct ada_pspace_data *pspace_data = get_ada_pspace_data (pspace);
-  struct ada_symbol_cache *sym_cache = pspace_data->sym_cache;
 
-  if (sym_cache == NULL)
+  if (pspace_data->sym_cache == NULL)
     {
-      sym_cache = XCNEW (struct ada_symbol_cache);
-      ada_init_symbol_cache (sym_cache);
+      pspace_data->sym_cache = XCNEW (struct ada_symbol_cache);
+      ada_init_symbol_cache (pspace_data->sym_cache);
     }
 
-  return sym_cache;
+  return pspace_data->sym_cache;
 }
 
 /* Clear all entries from the symbol cache.  */
@@ -4413,11 +4426,11 @@ ada_clear_symbol_cache (void)
   ada_init_symbol_cache (sym_cache);
 }
 
-/* Search our cache for an entry matching NAME and NAMESPACE.
+/* Search our cache for an entry matching NAME and DOMAIN.
    Return it if found, or NULL otherwise.  */
 
 static struct cache_entry **
-find_entry (const char *name, domain_enum namespace)
+find_entry (const char *name, domain_enum domain)
 {
   struct ada_symbol_cache *sym_cache
     = ada_get_symbol_cache (current_program_space);
@@ -4426,23 +4439,23 @@ find_entry (const char *name, domain_enum namespace)
 
   for (e = &sym_cache->root[h]; *e != NULL; e = &(*e)->next)
     {
-      if (namespace == (*e)->namespace && strcmp (name, (*e)->name) == 0)
+      if (domain == (*e)->domain && strcmp (name, (*e)->name) == 0)
         return e;
     }
   return NULL;
 }
 
-/* Search the symbol cache for an entry matching NAME and NAMESPACE.
+/* Search the symbol cache for an entry matching NAME and DOMAIN.
    Return 1 if found, 0 otherwise.
 
    If an entry was found and SYM is not NULL, set *SYM to the entry's
    SYM.  Same principle for BLOCK if not NULL.  */
 
 static int
-lookup_cached_symbol (const char *name, domain_enum namespace,
+lookup_cached_symbol (const char *name, domain_enum domain,
                       struct symbol **sym, const struct block **block)
 {
-  struct cache_entry **e = find_entry (name, namespace);
+  struct cache_entry **e = find_entry (name, domain);
 
   if (e == NULL)
     return 0;
@@ -4454,10 +4467,10 @@ lookup_cached_symbol (const char *name, domain_enum namespace,
 }
 
 /* Assuming that (SYM, BLOCK) is the result of the lookup of NAME
-   in domain NAMESPACE, save this result in our symbol cache.  */
+   in domain DOMAIN, save this result in our symbol cache.  */
 
 static void
-cache_symbol (const char *name, domain_enum namespace, struct symbol *sym,
+cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
               const struct block *block)
 {
   struct ada_symbol_cache *sym_cache
@@ -4466,6 +4479,11 @@ cache_symbol (const char *name, domain_enum namespace, struct symbol *sym,
   char *copy;
   struct cache_entry *e;
 
+  /* Symbols for builtin types don't have a block.
+     For now don't cache such symbols.  */
+  if (sym != NULL && !SYMBOL_OBJFILE_OWNED (sym))
+    return;
+
   /* If the symbol is a local symbol, then do not cache it, as a search
      for that symbol depends on the context.  To determine whether
      the symbol is local or not, we check the block where we found it
@@ -4485,7 +4503,7 @@ cache_symbol (const char *name, domain_enum namespace, struct symbol *sym,
   e->name = copy = obstack_alloc (&sym_cache->cache_space, strlen (name) + 1);
   strcpy (copy, name);
   e->sym = sym;
-  e->namespace = namespace;
+  e->domain = domain;
   e->block = block;
 }
 \f
@@ -4707,7 +4725,7 @@ ada_lookup_simple_minsym (const char *name)
 
 static void
 add_symbols_from_enclosing_procs (struct obstack *obstackp,
-                                  const char *name, domain_enum namespace,
+                                  const char *name, domain_enum domain,
                                   int wild_match_p)
 {
 }
@@ -5386,7 +5404,7 @@ add_nonlocal_symbols (struct obstack *obstackp, const char *name,
 
 static int
 ada_lookup_symbol_list_worker (const char *name0, const struct block *block0,
-                              domain_enum namespace,
+                              domain_enum domain,
                               struct ada_symbol_info **results,
                               int full_search)
 {
@@ -5394,14 +5412,12 @@ ada_lookup_symbol_list_worker (const char *name0, const struct block *block0,
   const struct block *block;
   const char *name;
   const int wild_match_p = should_use_wild_match (name0);
-  int cacheIfUnique;
+  int syms_from_global_search = 0;
   int ndefns;
 
   obstack_free (&symbol_list_obstack, NULL);
   obstack_init (&symbol_list_obstack);
 
-  cacheIfUnique = 0;
-
   /* Search specified block and its superiors.  */
 
   name = name0;
@@ -5427,7 +5443,7 @@ ada_lookup_symbol_list_worker (const char *name0, const struct block *block0,
       if (full_search)
        {
          ada_add_local_symbols (&symbol_list_obstack, name, block,
-                                namespace, wild_match_p);
+                                domain, wild_match_p);
        }
       else
        {
@@ -5435,7 +5451,7 @@ ada_lookup_symbol_list_worker (const char *name0, const struct block *block0,
             ada_iterate_over_symbols, and we don't want to search
             superblocks.  */
          ada_add_block_symbols (&symbol_list_obstack, block, name,
-                                namespace, NULL, wild_match_p);
+                                domain, NULL, wild_match_p);
        }
       if (num_defns_collected (&symbol_list_obstack) > 0 || !full_search)
        goto done;
@@ -5445,24 +5461,25 @@ ada_lookup_symbol_list_worker (const char *name0, const struct block *block0,
      already performed this search before.  If we have, then return
      the same result.  */
 
-  cacheIfUnique = 1;
-  if (lookup_cached_symbol (name0, namespace, &sym, &block))
+  if (lookup_cached_symbol (name0, domain, &sym, &block))
     {
       if (sym != NULL)
         add_defn_to_vec (&symbol_list_obstack, sym, block);
       goto done;
     }
 
+  syms_from_global_search = 1;
+
   /* Search symbols from all global blocks.  */
  
-  add_nonlocal_symbols (&symbol_list_obstack, name, namespace, 1,
+  add_nonlocal_symbols (&symbol_list_obstack, name, domain, 1,
                        wild_match_p);
 
   /* Now add symbols from all per-file blocks if we've gotten no hits
      (not strictly correct, but perhaps better than an error).  */
 
   if (num_defns_collected (&symbol_list_obstack) == 0)
-    add_nonlocal_symbols (&symbol_list_obstack, name, namespace, 0,
+    add_nonlocal_symbols (&symbol_list_obstack, name, domain, 0,
                          wild_match_p);
 
 done:
@@ -5471,11 +5488,11 @@ done:
 
   ndefns = remove_extra_symbols (*results, ndefns);
 
-  if (ndefns == 0 && full_search)
-    cache_symbol (name0, namespace, NULL, NULL);
+  if (ndefns == 0 && full_search && syms_from_global_search)
+    cache_symbol (name0, domain, NULL, NULL);
 
-  if (ndefns == 1 && full_search && cacheIfUnique)
-    cache_symbol (name0, namespace, (*results)[0].sym, (*results)[0].block);
+  if (ndefns == 1 && full_search && syms_from_global_search)
+    cache_symbol (name0, domain, (*results)[0].sym, (*results)[0].block);
 
   ndefns = remove_irrelevant_renamings (*results, ndefns, block0);
 
@@ -5547,7 +5564,7 @@ ada_name_for_lookup (const char *name)
 
 void
 ada_lookup_encoded_symbol (const char *name, const struct block *block,
-                          domain_enum namespace,
+                          domain_enum domain,
                           struct ada_symbol_info *info)
 {
   struct ada_symbol_info *candidates;
@@ -5556,7 +5573,7 @@ ada_lookup_encoded_symbol (const char *name, const struct block *block,
   gdb_assert (info != NULL);
   memset (info, 0, sizeof (struct ada_symbol_info));
 
-  n_candidates = ada_lookup_symbol_list (name, block, namespace, &candidates);
+  n_candidates = ada_lookup_symbol_list (name, block, domain, &candidates);
   if (n_candidates == 0)
     return;
 
@@ -5572,7 +5589,7 @@ ada_lookup_encoded_symbol (const char *name, const struct block *block,
 
 struct symbol *
 ada_lookup_symbol (const char *name, const struct block *block0,
-                   domain_enum namespace, int *is_a_field_of_this)
+                   domain_enum domain, int *is_a_field_of_this)
 {
   struct ada_symbol_info info;
 
@@ -5580,7 +5597,7 @@ ada_lookup_symbol (const char *name, const struct block *block0,
     *is_a_field_of_this = 0;
 
   ada_lookup_encoded_symbol (ada_encode (ada_fold_name (name)),
-                            block0, namespace, &info);
+                            block0, domain, &info);
   return info.sym;
 }
 
@@ -5590,7 +5607,38 @@ ada_lookup_symbol_nonlocal (const struct language_defn *langdef,
                             const struct block *block,
                             const domain_enum domain)
 {
-  return ada_lookup_symbol (name, block_static_block (block), domain, NULL);
+  struct symbol *sym;
+
+  sym = ada_lookup_symbol (name, block_static_block (block), domain, NULL);
+  if (sym != NULL)
+    return sym;
+
+  /* If we haven't found a match at this point, try the primitive
+     types.  In other languages, this search is performed before
+     searching for global symbols in order to short-circuit that
+     global-symbol search if it happens that the name corresponds
+     to a primitive type.  But we cannot do the same in Ada, because
+     it is perfectly legitimate for a program to declare a type which
+     has the same name as a standard type.  If looking up a type in
+     that situation, we have traditionally ignored the primitive type
+     in favor of user-defined types.  This is why, unlike most other
+     languages, we search the primitive types this late and only after
+     having searched the global symbols without success.  */
+
+  if (domain == VAR_DOMAIN)
+    {
+      struct gdbarch *gdbarch;
+
+      if (block == NULL)
+       gdbarch = target_gdbarch ();
+      else
+       gdbarch = block_gdbarch (block);
+      sym = language_lookup_primitive_type_as_symbol (langdef, gdbarch, name);
+      if (sym != NULL)
+       return sym;
+    }
+
+  return NULL;
 }
 
 
@@ -6197,8 +6245,8 @@ ada_make_symbol_completion_list (const char *text0, const char *word,
     data.word = word;
     data.wild_match = wild_match_p;
     data.encoded = encoded_p;
-    expand_symtabs_matching (NULL, ada_complete_symbol_matcher, ALL_DOMAIN,
-                            &data);
+    expand_symtabs_matching (NULL, ada_complete_symbol_matcher, NULL,
+                            ALL_DOMAIN, &data);
   }
 
   /* At this point scan through the misc symbol vectors and add each
@@ -7742,17 +7790,17 @@ struct type *
 ada_find_parallel_type (struct type *type, const char *suffix)
 {
   char *name;
-  const char *typename = ada_type_name (type);
+  const char *type_name = ada_type_name (type);
   int len;
 
-  if (typename == NULL)
+  if (type_name == NULL)
     return NULL;
 
-  len = strlen (typename);
+  len = strlen (type_name);
 
   name = (char *) alloca (len + strlen (suffix) + 1);
 
-  strcpy (name, typename);
+  strcpy (name, type_name);
   strcpy (name + len, suffix);
 
   return ada_find_parallel_type_with_name (type, name);
@@ -7815,9 +7863,9 @@ variant_field_index (struct type *type)
 /* A record type with no fields.  */
 
 static struct type *
-empty_record (struct type *template)
+empty_record (struct type *templ)
 {
-  struct type *type = alloc_type_copy (template);
+  struct type *type = alloc_type_copy (templ);
 
   TYPE_CODE (type) = TYPE_CODE_STRUCT;
   TYPE_NFIELDS (type) = 0;
@@ -12942,7 +12990,7 @@ ada_add_global_exceptions (regex_t *preg, VEC(ada_exc_info) **exceptions)
   struct objfile *objfile;
   struct compunit_symtab *s;
 
-  expand_symtabs_matching (NULL, ada_exc_search_name_matches,
+  expand_symtabs_matching (NULL, ada_exc_search_name_matches, NULL,
                           VARIABLES_DOMAIN, preg);
 
   ALL_COMPUNITS (objfile, s)
This page took 0.034172 seconds and 4 git commands to generate.