{
if (symtab_table.insert (symtab).second)
symtabs.push_back (symtab);
- return iteration_status::keep_going;
};
/* Find that file's data. */
if (pspace->executing_startup)
continue;
- iterate_over_symtabs (pspace, file, collector);
+ for_each_symtab (pspace, file, collector);
}
}
else
- iterate_over_symtabs (search_pspace, file, collector);
+ for_each_symtab (search_pspace, file, collector);
/* It is tempting to use the unordered_dense 'extract' method here,
and remove the separate vector -- but it's unclear if ordering
&& STRIP_DRIVE_SPEC (filename) == &filename[len - search_len]));
}
-/* See symtab.h. */
+/* Return the first symtab in PSPACE matching NAME and for which
+ CALLBACK returns true.
-void
-iterate_over_symtabs (program_space *pspace, const char *name,
- gdb::function_view<iteration_status (symtab *)> callback)
+ See documentation for for_each_symtab for how exactly NAME is matched. */
+
+static symtab *
+find_symtab (program_space *pspace, const char *name,
+ find_symtab_callback_ftype callback)
{
+ struct symtab *result = nullptr;
+
gdb::unique_xmalloc_ptr<char> real_path;
/* Here we are interested in canonicalizing an absolute path, not
gdb_assert (IS_ABSOLUTE_PATH (real_path.get ()));
}
+ auto map_callback = [&] (symtab *symtab)
+ {
+ if (callback (symtab))
+ {
+ result = symtab;
+ return iteration_status::stop;
+ }
+
+ return iteration_status::keep_going;
+ };
+
for (objfile &objfile : pspace->objfiles ())
if (objfile.map_symtabs_matching_filename (name, real_path.get (),
- callback)
+ map_callback)
== iteration_status::stop)
- return;
+ return result;
+
+ return nullptr;
}
/* See symtab.h. */
-symtab *
-lookup_symtab (program_space *pspace, const char *name)
+void
+for_each_symtab (program_space *pspace, const char *name,
+ for_each_symtab_callback_ftype callback)
{
- struct symtab *result = NULL;
+ find_symtab (pspace, name, [&] (symtab *symtab)
+ {
+ callback (symtab);
+ return false;
+ });
+}
- iterate_over_symtabs (pspace, name, [&] (symtab *symtab)
- {
- result = symtab;
- return iteration_status::stop;
- });
+/* See symtab.h. */
- return result;
+symtab *
+lookup_symtab (program_space *pspace, const char *name)
+{
+ return find_symtab (pspace, name, [&] (symtab *symtab) { return true; });
}
\f
/* Go through symtabs for SRCFILE and check the externs and statics
for symbols which match. */
- iterate_over_symtabs (current_program_space, srcfile, [&] (symtab *s)
+ for_each_symtab (current_program_space, srcfile, [&] (symtab *s)
{
add_symtab_completions (s->compunit (),
tracker, mode, lookup_name,
sym_text, word, TYPE_CODE_UNDEF);
- return iteration_status::keep_going;
});
}
bool compare_filenames_for_search (const char *filename,
const char *search_name);
-/* Check in PSPACE for a symtab of a specific name; first in symtabs, then in
- psymtabs. *If* there is no '/' in the name, a match after a '/' in the
- symtab filename will also work.
+/* Callback type for function for_each_symtab. */
- Call CALLBACK with each symtab that is found. If CALLBACK returns
- iteration_status::stop, the search stops. */
+using for_each_symtab_callback_ftype = std::function<void (symtab *)>;
-void iterate_over_symtabs
- (program_space *pspace, const char *name,
- gdb::function_view<iteration_status (symtab *)> callback);
+/* Check in PSPACE for symtabs of a specific name. *If* there is no '/' in
+ the name, a match after a '/' in the symtab filename will also work.
+
+ Call CALLBACK with each symtab that is found. */
+
+void for_each_symtab (program_space *pspace, const char *name,
+ for_each_symtab_callback_ftype callback);
+
+/* Callback type for function find_symtab. */
+
+using find_symtab_callback_ftype = std::function<bool (symtab *)>;
std::vector<const linetable_entry *> find_linetable_entries_for_symtab_line
(struct symtab *symtab, int line, const linetable_entry **best_entry);