From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/9] Let expand_symtabs_matching short-circuit
Date: Thu, 25 Mar 2021 11:04:51 -0600 [thread overview]
Message-ID: <20210325170458.2351251-3-tom@tromey.com> (raw)
In-Reply-To: <20210325170458.2351251-1-tom@tromey.com>
This changes expand_symtabs_exp_notify_ftype to return bool, and
updates all the uses. Now, if the notification function returns
false, the call is short-circuited and stops examining symtabs. This
is a step toward replacing map_symtabs_matching_filename with
expand_symtabs_matching.
2021-03-25 Tom Tromey <tom@tromey.com>
* symtab.c (default_collect_symbol_completion_matches_break_on):
Update.
* symfile.h (expand_symtabs_matching): Return bool.
* symfile.c (expand_symtabs_matching): Return bool.
* symfile-debug.c (objfile::expand_symtabs_matching): Return
bool.
* quick-symbol.h (expand_symtabs_exp_notify_ftype): Return bool.
(struct quick_symbol_functions) <expand_symtabs_matching>: Return
bool.
* psymtab.c (psymbol_functions::expand_symtabs_matching): Return
bool.
* psympriv.h (struct psymbol_functions)
<expand_symtabs_matching>: Return bool.
* objfiles.h (struct objfile) <expand_symtabs_matching>: Return
bool.
* dwarf2/read.c (struct dwarf2_gdb_index)
<expand_symtabs_matching>: Return bool.
(struct dwarf2_debug_names_index) <expand_symtabs_matching>:
Return bool.
(dw2_expand_symtabs_matching_symbol): Return bool.
(dw2_expand_symtabs_matching_one, dw2_expand_marked_cus)
(dw2_expand_symtabs_matching)
(dwarf2_gdb_index::expand_symtabs_matching)
(dwarf2_debug_names_index::expand_symtabs_matching)
(dwarf2_debug_names_index::expand_symtabs_matching): Return bool.
---
gdb/ChangeLog | 28 ++++++++++++++
gdb/dwarf2/read.c | 91 ++++++++++++++++++++++++++++-----------------
gdb/objfiles.h | 2 +-
gdb/psympriv.h | 2 +-
gdb/psymtab.c | 7 +++-
gdb/quick-symbol.h | 14 +++++--
gdb/symfile-debug.c | 9 +++--
gdb/symfile.c | 12 +++---
gdb/symfile.h | 2 +-
gdb/symtab.c | 1 +
10 files changed, 117 insertions(+), 51 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ee6f3f7f7e1..c351c9491aa 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2254,7 +2254,7 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions
gdb::function_view<symbol_found_callback_ftype> callback,
symbol_compare_ftype *ordered_compare) override;
- void expand_symtabs_matching
+ bool expand_symtabs_matching
(struct objfile *objfile,
gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
const lookup_name_info *lookup_name,
@@ -2283,7 +2283,7 @@ struct dwarf2_debug_names_index : public dwarf2_base_index_functions
gdb::function_view<symbol_found_callback_ftype> callback,
symbol_compare_ftype *ordered_compare) override;
- void expand_symtabs_matching
+ bool expand_symtabs_matching
(struct objfile *objfile,
gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
const lookup_name_info *lookup_name,
@@ -3793,7 +3793,7 @@ dwarf2_base_index_functions::expand_symtabs_with_fullname
}
}
-static void
+static bool
dw2_expand_symtabs_matching_symbol
(mapped_index_base &index,
const lookup_name_info &lookup_name_in,
@@ -3801,7 +3801,7 @@ dw2_expand_symtabs_matching_symbol
gdb::function_view<bool (offset_type)> match_callback,
dwarf2_per_objfile *per_objfile);
-static void
+static bool
dw2_expand_symtabs_matching_one
(dwarf2_per_cu_data *per_cu,
dwarf2_per_objfile *per_objfile,
@@ -4108,7 +4108,7 @@ mapped_index_base::build_name_components (dwarf2_per_objfile *per_objfile)
symbol name that matches, calls MATCH_CALLBACK, passing it the
symbol's index in the mapped_index_base symbol table. */
-static void
+static bool
dw2_expand_symtabs_matching_symbol
(mapped_index_base &index,
const lookup_name_info &lookup_name_in,
@@ -4193,12 +4193,16 @@ dw2_expand_symtabs_matching_symbol
/* Finally call the callback, once per match. */
ULONGEST prev = -1;
+ bool result = true;
for (offset_type idx : matches)
{
if (prev != idx)
{
if (!match_callback (idx))
- break;
+ {
+ result = false;
+ break;
+ }
prev = idx;
}
}
@@ -4206,6 +4210,8 @@ dw2_expand_symtabs_matching_symbol
/* Above we use a type wider than idx's for 'prev', since 0 and
(offset_type)-1 are both possible values. */
static_assert (sizeof (prev) > sizeof (offset_type), "");
+
+ return result;
}
#if GDB_SELF_TEST
@@ -4646,7 +4652,7 @@ run_test ()
dw_expand_symtabs_matching_file_matcher), expand the CU and call
EXPANSION_NOTIFY on it. */
-static void
+static bool
dw2_expand_symtabs_matching_one
(dwarf2_per_cu_data *per_cu,
dwarf2_per_objfile *per_objfile,
@@ -4662,15 +4668,16 @@ dw2_expand_symtabs_matching_one
gdb_assert (symtab != nullptr);
if (expansion_notify != NULL && symtab_was_null)
- expansion_notify (symtab);
+ return expansion_notify (symtab);
}
+ return true;
}
/* Helper for dw2_expand_matching symtabs. Called on each symbol
matched, to expand corresponding CUs that were marked. IDX is the
index of the symbol name that matched. */
-static void
+static bool
dw2_expand_marked_cus
(dwarf2_per_objfile *per_objfile, offset_type idx,
gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -4747,9 +4754,12 @@ dw2_expand_marked_cus
}
dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cutu (cu_index);
- dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
- expansion_notify);
+ if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
+ expansion_notify))
+ return false;
}
+
+ return true;
}
/* If FILE_MATCHER is non-NULL, set all the
@@ -4829,7 +4839,7 @@ dw_expand_symtabs_matching_file_matcher
}
}
-static void
+static bool
dw2_expand_symtabs_matching
(struct objfile *objfile,
gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -4842,7 +4852,7 @@ dw2_expand_symtabs_matching
/* index_table is NULL if OBJF_READNOW. */
if (!per_objfile->per_bfd->index_table)
- return;
+ return true;
dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
@@ -4852,25 +4862,31 @@ dw2_expand_symtabs_matching
{
QUIT;
- dw2_expand_symtabs_matching_one (per_cu, per_objfile,
- file_matcher, expansion_notify);
+ if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
+ file_matcher,
+ expansion_notify))
+ return false;
}
- return;
+ return true;
}
mapped_index &index = *per_objfile->per_bfd->index_table;
- dw2_expand_symtabs_matching_symbol (index, *lookup_name,
- symbol_matcher,
- [&] (offset_type idx)
+ bool result
+ = dw2_expand_symtabs_matching_symbol (index, *lookup_name,
+ symbol_matcher,
+ [&] (offset_type idx)
{
- dw2_expand_marked_cus (per_objfile, idx, file_matcher, expansion_notify,
- kind);
+ if (!dw2_expand_marked_cus (per_objfile, idx, file_matcher,
+ expansion_notify, kind))
+ return false;
return true;
}, per_objfile);
+
+ return result;
}
-void
+bool
dwarf2_gdb_index::expand_symtabs_matching
(struct objfile *objfile,
gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -4879,8 +4895,8 @@ dwarf2_gdb_index::expand_symtabs_matching
gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
enum search_domain kind)
{
- dw2_expand_symtabs_matching (objfile, file_matcher, lookup_name,
- symbol_matcher, expansion_notify, kind);
+ return dw2_expand_symtabs_matching (objfile, file_matcher, lookup_name,
+ symbol_matcher, expansion_notify, kind);
}
/* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
@@ -5892,7 +5908,7 @@ dwarf2_debug_names_index::map_matching_symbols
}
}
-void
+bool
dwarf2_debug_names_index::expand_symtabs_matching
(struct objfile *objfile,
gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -5905,7 +5921,7 @@ dwarf2_debug_names_index::expand_symtabs_matching
/* debug_names_table is NULL if OBJF_READNOW. */
if (!per_objfile->per_bfd->debug_names_table)
- return;
+ return true;
dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
@@ -5915,17 +5931,20 @@ dwarf2_debug_names_index::expand_symtabs_matching
{
QUIT;
- dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
- expansion_notify);
+ if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
+ file_matcher,
+ expansion_notify))
+ return false;
}
- return;
+ return true;
}
mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
- dw2_expand_symtabs_matching_symbol (map, *lookup_name,
- symbol_matcher,
- [&] (offset_type namei)
+ bool result
+ = dw2_expand_symtabs_matching_symbol (map, *lookup_name,
+ symbol_matcher,
+ [&] (offset_type namei)
{
/* The name was matched, now expand corresponding CUs that were
marked. */
@@ -5933,10 +5952,14 @@ dwarf2_debug_names_index::expand_symtabs_matching
struct dwarf2_per_cu_data *per_cu;
while ((per_cu = iter.next ()) != NULL)
- dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
- expansion_notify);
+ if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
+ file_matcher,
+ expansion_notify))
+ return false;
return true;
}, per_objfile);
+
+ return result;
}
/* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 41f8fc913d8..f8dca8c6d56 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -575,7 +575,7 @@ struct objfile
symbol_compare_ftype *ordered_compare);
/* See quick_symbol_functions. */
- void expand_symtabs_matching
+ bool expand_symtabs_matching
(gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
const lookup_name_info *lookup_name,
gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index bbae2fc90e4..4fa1feb9461 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -540,7 +540,7 @@ struct psymbol_functions : public quick_symbol_functions
gdb::function_view<symbol_found_callback_ftype> callback,
symbol_compare_ftype *ordered_compare) override;
- void expand_symtabs_matching
+ bool expand_symtabs_matching
(struct objfile *objfile,
gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
const lookup_name_info *lookup_name,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 1ea7376a8c8..ea554e8bebb 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1293,7 +1293,7 @@ recursively_search_psymtabs
/* Psymtab version of expand_symtabs_matching. See its definition in
the definition of quick_symbol_functions in symfile.h. */
-void
+bool
psymbol_functions::expand_symtabs_matching
(struct objfile *objfile,
gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -1346,9 +1346,12 @@ psymbol_functions::expand_symtabs_matching
psymtab_to_symtab (objfile, ps);
if (expansion_notify != NULL)
- expansion_notify (symtab);
+ if (!expansion_notify (symtab))
+ return false;
}
}
+
+ return true;
}
/* Psymtab version of has_symbols. See its definition in
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 1ca4945bf60..fa41b70fc3a 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -52,9 +52,11 @@ typedef bool (expand_symtabs_file_matcher_ftype) (const char *filename,
typedef bool (expand_symtabs_symbol_matcher_ftype) (const char *name);
/* Callback for quick_symbol_functions->expand_symtabs_matching
- to be called after a symtab has been expanded. */
+ to be called after a symtab has been expanded. If this returns
+ true, more symtabs are checked; if it returns false, iteration
+ stops. */
-typedef void (expand_symtabs_exp_notify_ftype) (compunit_symtab *symtab);
+typedef bool (expand_symtabs_exp_notify_ftype) (compunit_symtab *symtab);
/* The "quick" symbol functions exist so that symbol readers can
avoiding an initial read of all the symbols. For example, symbol
@@ -206,8 +208,12 @@ struct quick_symbol_functions
If SYMBOL_MATCHER returns false, then the symbol is skipped.
- Otherwise, the symbol's symbol table is expanded. */
- virtual void expand_symtabs_matching
+ Otherwise, the symbol's symbol table is expanded and the
+ notification function is called. If the notification function
+ returns false, execution stops and this method returns false.
+ Otherwise, more files are considered. This method will return
+ true if all calls to the notification function return true. */
+ virtual bool expand_symtabs_matching
(struct objfile *objfile,
gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
const lookup_name_info *lookup_name,
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 3daede88292..9890bfbd52f 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -265,7 +265,7 @@ objfile::map_matching_symbols
callback, ordered_compare);
}
-void
+bool
objfile::expand_symtabs_matching
(gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
const lookup_name_info *lookup_name,
@@ -283,8 +283,11 @@ objfile::expand_symtabs_matching
search_domain_name (kind));
for (const auto &iter : qf)
- iter->expand_symtabs_matching (this, file_matcher, lookup_name,
- symbol_matcher, expansion_notify, kind);
+ if (!iter->expand_symtabs_matching (this, file_matcher, lookup_name,
+ symbol_matcher, expansion_notify,
+ kind))
+ return false;
+ return true;
}
struct compunit_symtab *
diff --git a/gdb/symfile.c b/gdb/symfile.c
index e417878031d..09318474489 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3717,7 +3717,7 @@ symfile_free_objfile (struct objfile *objfile)
Expand all symtabs that match the specified criteria.
See quick_symbol_functions.expand_symtabs_matching for details. */
-void
+bool
expand_symtabs_matching
(gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
const lookup_name_info &lookup_name,
@@ -3726,10 +3726,12 @@ expand_symtabs_matching
enum search_domain kind)
{
for (objfile *objfile : current_program_space->objfiles ())
- objfile->expand_symtabs_matching (file_matcher,
- &lookup_name,
- symbol_matcher,
- expansion_notify, kind);
+ if (!objfile->expand_symtabs_matching (file_matcher,
+ &lookup_name,
+ symbol_matcher,
+ expansion_notify, kind))
+ return false;
+ return true;
}
/* Wrapper around the quick_symbol_functions map_symbol_filenames "method".
diff --git a/gdb/symfile.h b/gdb/symfile.h
index bae2a798703..b44c139a0b2 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -321,7 +321,7 @@ symfile_segment_data_up get_symfile_segment_data (bfd *abfd);
extern scoped_restore_tmpl<int> increment_reading_symtab (void);
-void expand_symtabs_matching
+bool expand_symtabs_matching
(gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
const lookup_name_info &lookup_name,
gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 122fdf0b1d3..779d7a8de31 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -5735,6 +5735,7 @@ default_collect_symbol_completion_matches_break_on
add_symtab_completions (symtab,
tracker, mode, lookup_name,
sym_text, word, code);
+ return true;
},
ALL_DOMAIN);
--
2.26.2
next prev parent reply other threads:[~2021-03-25 17:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-25 17:04 [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
2021-03-25 17:04 ` [PATCH 1/9] Add block_search_flags Tom Tromey
2021-03-25 17:04 ` Tom Tromey [this message]
2021-03-25 17:04 ` [PATCH 3/9] Add search_flags to expand_symtabs_matching Tom Tromey
2021-03-25 17:04 ` [PATCH 4/9] Add 'domain' parameter " Tom Tromey
2021-03-25 17:04 ` [PATCH 5/9] Remove quick_symbol_functions::lookup_symbol Tom Tromey
2021-03-25 17:04 ` [PATCH 6/9] Remove quick_symbol_functions::map_symtabs_matching_filename Tom Tromey
2021-03-25 17:04 ` [PATCH 7/9] Remove quick_symbol_functions::expand_symtabs_for_function Tom Tromey
2021-03-25 17:04 ` [PATCH 8/9] Remove quick_symbol_functions::expand_symtabs_with_fullname Tom Tromey
2021-03-25 17:04 ` [PATCH 9/9] Simplify quick_symbol_functions::map_matching_symbols Tom Tromey
2021-04-17 15:38 ` [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210325170458.2351251-3-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).