Revert "Sync readline/ to version 7.0 alpha"
[deliverable/binutils-gdb.git] / gdb / block.c
index e791c73accff1ce69a7b33917a1bdc7e693748ce..f7621aa6102e3684373bfda6da8ca134732762d3 100644 (file)
@@ -1,6 +1,6 @@
 /* Block-related functions for the GNU debugger, GDB.
 
-   Copyright (C) 2003-2014 Free Software Foundation, Inc.
+   Copyright (C) 2003-2015 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -25,6 +25,7 @@
 #include "cp-support.h"
 #include "addrmap.h"
 #include "gdbtypes.h"
+#include "objfiles.h"
 
 /* This is used by struct block to store namespace-related info for
    C++ files, namely using declarations and the current namespace in
 struct block_namespace_info
 {
   const char *scope;
-  struct using_direct *using;
+  struct using_direct *using_decl;
 };
 
 static void block_initialize_namespace (struct block *block,
                                        struct obstack *obstack);
 
+/* See block.h.  */
+
+struct objfile *
+block_objfile (const struct block *block)
+{
+  const struct global_block *global_block;
+
+  if (BLOCK_FUNCTION (block) != NULL)
+    return symbol_objfile (BLOCK_FUNCTION (block));
+
+  global_block = (struct global_block *) block_global_block (block);
+  return COMPUNIT_OBJFILE (global_block->compunit_symtab);
+}
+
+/* See block.  */
+
+struct gdbarch *
+block_gdbarch (const struct block *block)
+{
+  if (BLOCK_FUNCTION (block) != NULL)
+    return symbol_arch (BLOCK_FUNCTION (block));
+
+  return get_objfile_arch (block_objfile (block));
+}
+
 /* Return Nonzero if block a is lexically nested within block b,
    or if a and b have the same pc range.
    Return zero otherwise.  */
@@ -300,7 +326,7 @@ block_using (const struct block *block)
   if (block == NULL || BLOCK_NAMESPACE (block) == NULL)
     return NULL;
   else
-    return BLOCK_NAMESPACE (block)->using;
+    return BLOCK_NAMESPACE (block)->using_decl;
 }
 
 /* Set BLOCK's using member to USING; if needed, allocate memory via
@@ -309,12 +335,12 @@ block_using (const struct block *block)
 
 void
 block_set_using (struct block *block,
-                struct using_direct *using,
+                struct using_direct *using_decl,
                 struct obstack *obstack)
 {
   block_initialize_namespace (block, obstack);
 
-  BLOCK_NAMESPACE (block)->using = using;
+  BLOCK_NAMESPACE (block)->using_decl = using_decl;
 }
 
 /* If BLOCK_NAMESPACE (block) is NULL, allocate it via OBSTACK and
@@ -328,7 +354,7 @@ block_initialize_namespace (struct block *block, struct obstack *obstack)
       BLOCK_NAMESPACE (block)
        = obstack_alloc (obstack, sizeof (struct block_namespace_info));
       BLOCK_NAMESPACE (block)->scope = NULL;
-      BLOCK_NAMESPACE (block)->using = NULL;
+      BLOCK_NAMESPACE (block)->using_decl = NULL;
     }
 }
 
@@ -713,13 +739,21 @@ block_lookup_symbol (const struct block *block, const char *name,
 
   if (!BLOCK_FUNCTION (block))
     {
+      struct symbol *other = NULL;
+
       ALL_BLOCK_SYMBOLS_WITH_NAME (block, name, iter, sym)
        {
+         if (SYMBOL_DOMAIN (sym) == domain)
+           return sym;
+         /* This is a bit of a hack, but symbol_matches_domain might ignore
+            STRUCT vs VAR domain symbols.  So if a matching symbol is found,
+            make sure there is no "better" matching symbol, i.e., one with
+            exactly the same domain.  PR 16253.  */
          if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
                                     SYMBOL_DOMAIN (sym), domain))
-           return sym;
+           other = sym;
        }
-      return NULL;
+      return other;
     }
   else
     {
@@ -727,7 +761,10 @@ block_lookup_symbol (const struct block *block, const char *name,
         list; this loop makes sure to take anything else other than
         parameter symbols first; it only uses parameter symbols as a
         last resort.  Note that this only takes up extra computation
-        time on a match.  */
+        time on a match.
+        It's hard to define types in the parameter list (at least in
+        C/C++) so we don't do the same PR 16253 hack here that is done
+        for the !BLOCK_FUNCTION case.  */
 
       struct symbol *sym_found = NULL;
 
@@ -753,21 +790,76 @@ struct symbol *
 block_lookup_symbol_primary (const struct block *block, const char *name,
                             const domain_enum domain)
 {
-  struct symbol *sym;
+  struct symbol *sym, *other;
   struct dict_iterator dict_iter;
 
   /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK.  */
   gdb_assert (BLOCK_SUPERBLOCK (block) == NULL
              || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL);
 
+  other = NULL;
   for (sym = dict_iter_name_first (block->dict, name, &dict_iter);
        sym != NULL;
        sym = dict_iter_name_next (name, &dict_iter))
     {
+      if (SYMBOL_DOMAIN (sym) == domain)
+       return sym;
+
+      /* This is a bit of a hack, but symbol_matches_domain might ignore
+        STRUCT vs VAR domain symbols.  So if a matching symbol is found,
+        make sure there is no "better" matching symbol, i.e., one with
+        exactly the same domain.  PR 16253.  */
       if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
                                 SYMBOL_DOMAIN (sym), domain))
-       return sym;
+       other = sym;
     }
 
+  return other;
+}
+
+/* See block.h.  */
+
+struct symbol *
+block_find_symbol (const struct block *block, const char *name,
+                  const domain_enum domain,
+                  block_symbol_matcher_ftype *matcher, void *data)
+{
+  struct block_iterator iter;
+  struct symbol *sym;
+
+  /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK.  */
+  gdb_assert (BLOCK_SUPERBLOCK (block) == NULL
+             || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL);
+
+  ALL_BLOCK_SYMBOLS_WITH_NAME (block, name, iter, sym)
+    {
+      /* MATCHER is deliberately called second here so that it never sees
+        a non-domain-matching symbol.  */
+      if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
+                                SYMBOL_DOMAIN (sym), domain)
+         && matcher (sym, data))
+       return sym;
+    }
   return NULL;
 }
+
+/* See block.h.  */
+
+int
+block_find_non_opaque_type (struct symbol *sym, void *data)
+{
+  return !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym));
+}
+
+/* See block.h.  */
+
+int
+block_find_non_opaque_type_preferred (struct symbol *sym, void *data)
+{
+  struct symbol **best = data;
+
+  if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
+    return 1;
+  *best = sym;
+  return 0;
+}
This page took 0.026603 seconds and 4 git commands to generate.