Simplify psym_map_matching_symbols
authorTom Tromey <tromey@adacore.com>
Fri, 12 Jul 2019 17:00:39 +0000 (11:00 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 10 Sep 2019 14:30:45 +0000 (08:30 -0600)
This introduces a new helper function,
iterate_over_symbols_terminated, and changes psym_map_matching_symbols
to use it.  A subsequent patch will introduce a new user of this
function in the DWARF reader.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tromey@adacore.com>

* psymtab.c (map_block): Remove.
(psym_map_matching_symbols): Use iterate_over_symbols_terminated.
* symtab.c (iterate_over_symbols_terminated): New function.
* symtab.c (iterate_over_symbols_terminated): Declare.

gdb/ChangeLog
gdb/psymtab.c
gdb/symtab.c
gdb/symtab.h

index e2ebafe714cfef68ed5bd2a12f5f1e91e91b38f6..129aaad7d202c0aba2781c2c21a6644d43d7089f 100644 (file)
@@ -1,3 +1,10 @@
+2019-09-10  Tom Tromey  <tromey@adacore.com>
+
+       * psymtab.c (map_block): Remove.
+       (psym_map_matching_symbols): Use iterate_over_symbols_terminated.
+       * symtab.c (iterate_over_symbols_terminated): New function.
+       * symtab.c (iterate_over_symbols_terminated): Declare.
+
 2019-09-10  Tom Tromey  <tromey@adacore.com>
 
        * ada-lang.c (ada_iterate_over_symbols): Return bool.
index cd577bc4c53bdeaf4098d1b576dde4ff13dce1cf..81138bbe901f27d8ff1fc60ce31b9247252a1cff 100644 (file)
@@ -1168,38 +1168,6 @@ psymtab_to_fullname (struct partial_symtab *ps)
   return ps->fullname;
 }
 
-/* For all symbols, s, in BLOCK that are in DOMAIN and match NAME
-   according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
-   BLOCK is assumed to come from OBJFILE.  Returns false iff CALLBACK
-   ever returns false, and otherwise returns true.  */
-
-static bool
-map_block (const char *name, domain_enum domain, struct objfile *objfile,
-          const struct block *block,
-          gdb::function_view<symbol_found_callback_ftype> callback,
-          symbol_name_match_type match)
-{
-  struct block_iterator iter;
-  struct symbol *sym;
-
-  lookup_name_info lookup_name (name, match);
-
-  for (sym = block_iter_match_first (block, lookup_name, &iter);
-       sym != NULL;
-       sym = block_iter_match_next (lookup_name, &iter))
-    {
-      if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
-                                SYMBOL_DOMAIN (sym), domain))
-       {
-         struct block_symbol block_sym = {sym, block};
-         if (!callback (&block_sym))
-           return false;
-       }
-    }
-
-  return true;
-}
-
 /* Psymtab version of map_matching_symbols.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
@@ -1214,6 +1182,8 @@ psym_map_matching_symbols
 {
   const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
 
+  lookup_name_info lookup_name (name, match);
+
   for (partial_symtab *ps : require_partial_symbols (objfile, 1))
     {
       QUIT;
@@ -1227,10 +1197,8 @@ psym_map_matching_symbols
          if (cust == NULL)
            continue;
          block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind);
-         if (!map_block (name, domain, objfile, block, callback, match))
-           return;
-         struct block_symbol block_sym = {nullptr, block};
-         if (!callback (&block_sym))
+         if (!iterate_over_symbols_terminated (block, lookup_name,
+                                               domain, callback))
            return;
        }
     }
index 5f184454bd153bdb16acd96e688cbd5b318cf10c..e1bf3692a5be9e20868ecdcba025af6f3c5b1038 100644 (file)
@@ -2847,6 +2847,21 @@ iterate_over_symbols (const struct block *block,
   return true;
 }
 
+/* See symtab.h.  */
+
+bool
+iterate_over_symbols_terminated
+  (const struct block *block,
+   const lookup_name_info &name,
+   const domain_enum domain,
+   gdb::function_view<symbol_found_callback_ftype> callback)
+{
+  if (!iterate_over_symbols (block, name, domain, callback))
+    return false;
+  struct block_symbol block_sym = {nullptr, block};
+  return callback (&block_sym);
+}
+
 /* Find the compunit symtab associated with PC and SECTION.
    This will read in debug info as necessary.  */
 
index 49feea62e2a5435c417818ef202d2a1481edfe8e..4fb00cba9f53fc9a12ce762dc4bfdf8f56c5a6b4 100644 (file)
@@ -2106,6 +2106,16 @@ bool iterate_over_symbols (const struct block *block,
                           const domain_enum domain,
                           gdb::function_view<symbol_found_callback_ftype> callback);
 
+/* Like iterate_over_symbols, but if all calls to CALLBACK return
+   true, then calls CALLBACK one additional time with a block_symbol
+   that has a valid block but a NULL symbol.  */
+
+bool iterate_over_symbols_terminated
+  (const struct block *block,
+   const lookup_name_info &name,
+   const domain_enum domain,
+   gdb::function_view<symbol_found_callback_ftype> callback);
+
 /* Storage type used by demangle_for_lookup.  demangle_for_lookup
    either returns a const char * pointer that points to either of the
    fields of this type, or a pointer to the input NAME.  This is done