mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2026-08-27 00:26:02 -04:00
gdb: change objfile::map_symtabs_matching_filename to find_symtab_matching_filename
The only user of objfile::map_symtabs_matching_filename uses that method to find the first matching symtab. It would therefore be more natural for that method to be a "find" method, returning the first symtab matching the predicate. Change map_symtabs_matching_filename to be find_symtab_matching_filename, and the internal iterate_over_one_compunit_symtab to be find_symtab_in_compunit_symtab. This makes function find_symtab simpler. Change-Id: Id14a95498fad243495d6eab18810d0c4ab8dbf90 Approved-By: Andrew Burgess <aburgess@redhat.com>
This commit is contained in:
parent
5f5a59e211
commit
808005684b
3 changed files with 52 additions and 70 deletions
|
|
@ -571,21 +571,17 @@ public:
|
|||
/* See quick_symbol_functions. */
|
||||
void forget_cached_source_info ();
|
||||
|
||||
/* Expand and iterate over each "partial" symbol table in OBJFILE
|
||||
where the source file is named NAME.
|
||||
/* Find the first symtab where the source file matches NAME and REAL_PATH,
|
||||
and for which CALLBACK returns true.
|
||||
|
||||
If NAME is not absolute, a match after a '/' in the symbol table's
|
||||
file name will also work, REAL_PATH is NULL then. If NAME is
|
||||
absolute then REAL_PATH is non-NULL absolute file name as resolved
|
||||
via gdb_realpath from NAME.
|
||||
via gdb_realpath from NAME. */
|
||||
|
||||
If a match is found, the "partial" symbol table is expanded.
|
||||
Then, this calls iterate_over_some_symtabs (or equivalent) over
|
||||
all newly-created symbol tables, passing CALLBACK to it.
|
||||
The result of this call is returned. */
|
||||
iteration_status map_symtabs_matching_filename
|
||||
(const char *name, const char *real_path,
|
||||
gdb::function_view<iteration_status (symtab *)> callback);
|
||||
symtab *find_symtab_matching_filename (const char *name,
|
||||
const char *real_path,
|
||||
find_symtab_callback_ftype callback);
|
||||
|
||||
/* Check to see if the symbol is defined in a "partial" symbol table
|
||||
of this objfile. BLOCK_INDEX should be either GLOBAL_BLOCK or
|
||||
|
|
|
|||
|
|
@ -159,29 +159,30 @@ objfile::forget_cached_source_info ()
|
|||
iter->forget_cached_source_info (this);
|
||||
}
|
||||
|
||||
/* Check for a symtab of a specific name by searching some symtabs.
|
||||
/* Find the first symtab of CUST matching BASE_NAME, NAME and REAL_PATH, for
|
||||
which CALLBACK returns true.
|
||||
|
||||
If NAME is not absolute, then REAL_PATH is NULL
|
||||
If NAME is absolute, then REAL_PATH is the gdb_realpath form of NAME.
|
||||
|
||||
The return value, NAME, REAL_PATH and CALLBACK are identical to the
|
||||
`map_symtabs_matching_filename' method of quick_symbol_functions.
|
||||
`objfile::find_symtab_matching_filename' method.
|
||||
|
||||
CUST indicates which compunit symtab to search. Each symtab within
|
||||
the specified compunit symtab is also searched. */
|
||||
|
||||
static iteration_status
|
||||
iterate_over_one_compunit_symtab
|
||||
(const char *base_name, const char *name, const char *real_path,
|
||||
compunit_symtab *cust,
|
||||
gdb::function_view<iteration_status (symtab *)> callback)
|
||||
static symtab *
|
||||
find_symtab_in_compunit_symtab (const char *base_name, const char *name,
|
||||
const char *real_path, compunit_symtab *cust,
|
||||
find_symtab_callback_ftype callback)
|
||||
{
|
||||
for (symtab *s : cust->filetabs ())
|
||||
{
|
||||
if (compare_filenames_for_search (s->filename (), name))
|
||||
{
|
||||
if (callback (s) == iteration_status::stop)
|
||||
return iteration_status::stop;
|
||||
if (callback (s))
|
||||
return s;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -193,8 +194,9 @@ iterate_over_one_compunit_symtab
|
|||
|
||||
if (compare_filenames_for_search (symtab_to_fullname (s), name))
|
||||
{
|
||||
if (callback (s) == iteration_status::stop)
|
||||
return iteration_status::stop;
|
||||
if (callback (s))
|
||||
return s;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -211,30 +213,32 @@ iterate_over_one_compunit_symtab
|
|||
fullname = fullname_real_path.get ();
|
||||
if (FILENAME_CMP (real_path, fullname) == 0)
|
||||
{
|
||||
if (callback (s) == iteration_status::stop)
|
||||
return iteration_status::stop;
|
||||
if (callback (s))
|
||||
return s;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (compunit_symtab *iter : cust->includes)
|
||||
if (iterate_over_one_compunit_symtab (base_name, name, real_path, iter,
|
||||
callback)
|
||||
== iteration_status::stop)
|
||||
return iteration_status::stop;
|
||||
if (symtab *result = find_symtab_in_compunit_symtab (base_name, name,
|
||||
real_path, iter,
|
||||
callback);
|
||||
result != nullptr)
|
||||
return result;
|
||||
|
||||
return iteration_status::keep_going;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
iteration_status
|
||||
objfile::map_symtabs_matching_filename
|
||||
(const char *name, const char *real_path,
|
||||
gdb::function_view<iteration_status (symtab *)> callback)
|
||||
symtab *
|
||||
objfile::find_symtab_matching_filename (const char *name,
|
||||
const char *real_path,
|
||||
find_symtab_callback_ftype callback)
|
||||
{
|
||||
if (debug_symfile)
|
||||
gdb_printf (gdb_stdlog,
|
||||
"qf->map_symtabs_matching_filename (%s, \"%s\", "
|
||||
"qf->find_symtab_matching_filename (%s, \"%s\", "
|
||||
"\"%s\", %s)\n",
|
||||
objfile_debug_name (this), name,
|
||||
real_path ? real_path : NULL,
|
||||
|
|
@ -254,40 +258,34 @@ objfile::map_symtabs_matching_filename
|
|||
return false;
|
||||
};
|
||||
|
||||
symtab *result = nullptr;
|
||||
auto compunit_callback = [&] (compunit_symtab *symtab)
|
||||
{
|
||||
/* Skip included compunits, as they are searched by
|
||||
iterate_over_one_compunit_symtab. */
|
||||
find_symtab_in_compunit_symtab. */
|
||||
if (symtab->user != nullptr)
|
||||
return iteration_status::keep_going;
|
||||
|
||||
/* iterate_over_one_compunit_symtab returns true to stop,
|
||||
convert to iteration_status. */
|
||||
return iterate_over_one_compunit_symtab (name_basename, name, real_path,
|
||||
result = find_symtab_in_compunit_symtab (name_basename, name, real_path,
|
||||
symtab, callback);
|
||||
return (result == nullptr
|
||||
? iteration_status::keep_going
|
||||
: iteration_status::stop);
|
||||
};
|
||||
|
||||
iteration_status retval = iteration_status::keep_going;
|
||||
|
||||
for (const auto &iter : qf)
|
||||
{
|
||||
if (iter->search (this, match_one_filename, nullptr, nullptr,
|
||||
compunit_callback,
|
||||
SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
|
||||
SEARCH_ALL_DOMAINS)
|
||||
== iteration_status::stop)
|
||||
{
|
||||
retval = iteration_status::stop;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (iter->search (this, match_one_filename, nullptr, nullptr,
|
||||
compunit_callback,
|
||||
SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
|
||||
SEARCH_ALL_DOMAINS)
|
||||
== iteration_status::stop)
|
||||
break;
|
||||
|
||||
if (debug_symfile)
|
||||
gdb_printf (gdb_stdlog,
|
||||
"qf->map_symtabs_matching_filename (...) = %s\n",
|
||||
iteration_status_str (retval));
|
||||
gdb_printf (gdb_stdlog, "qf->find_symtab_matching_filename (...) = %p\n",
|
||||
result);
|
||||
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
struct compunit_symtab *
|
||||
|
|
|
|||
20
gdb/symtab.c
20
gdb/symtab.c
|
|
@ -638,8 +638,6 @@ 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
|
||||
|
|
@ -650,21 +648,11 @@ find_symtab (program_space *pspace, const char *name,
|
|||
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 (),
|
||||
map_callback)
|
||||
== iteration_status::stop)
|
||||
if (symtab *result
|
||||
= objfile.find_symtab_matching_filename (name, real_path.get (),
|
||||
callback);
|
||||
result != nullptr)
|
||||
return result;
|
||||
|
||||
return nullptr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue