public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Document quick_symbol_functions::expand_symtabs_matching invariant
@ 2021-06-27 14:24 Tom Tromey
  2021-07-16 19:54 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2021-06-27 14:24 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

While working on my series to replace the DWARF psymbol reader, I
noticed that the expand_symtabs_matching has an undocumented
invariant.  I think that, if this invariant is not followed, then GDB
will crash.  So, this patch documents this in the relevant spots and
introduces some asserts to make it clear.

Regression tested on x86-64 Fedora 32.

gdb/ChangeLog
2021-06-27  Tom Tromey  <tom@tromey.com>

	* symfile-debug.c (objfile::expand_symtabs_matching): Add assert.
	* quick-symbol.h (struct quick_symbol_functions)
	<expand_symtabs_matching>: Add comment.
	* psymtab.c (psymbol_functions::expand_symtabs_matching): Add
	assert, simplify.
	* dwarf2/read.c (dwarf2_gdb_index::expand_symtabs_matching)
	(dwarf2_debug_names_index::expand_symtabs_matching): Add assert,
	simplify.
---
 gdb/ChangeLog       | 11 +++++++++++
 gdb/dwarf2/read.c   |  8 ++++++--
 gdb/psymtab.c       |  5 ++++-
 gdb/quick-symbol.h  |  2 ++
 gdb/symfile-debug.c |  3 +++
 5 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 760d4319c29..4f51470f151 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -4319,7 +4319,9 @@ dwarf2_gdb_index::expand_symtabs_matching
 
   dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
 
-  if (symbol_matcher == NULL && lookup_name == NULL)
+  /* This invariant is documented in quick-functions.h.  */
+  gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
+  if (lookup_name == nullptr)
     {
       for (const auto &per_cu : per_objfile->per_bfd->all_comp_units)
 	{
@@ -5307,7 +5309,9 @@ dwarf2_debug_names_index::expand_symtabs_matching
 
   dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
 
-  if (symbol_matcher == NULL && lookup_name == NULL)
+  /* This invariant is documented in quick-functions.h.  */
+  gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
+  if (lookup_name == nullptr)
     {
       for (const auto &per_cu : per_objfile->per_bfd->all_comp_units)
 	{
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 069052d712c..7c3017d36d2 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1130,6 +1130,9 @@ psymbol_functions::expand_symtabs_matching
   if (lookup_name != nullptr)
     psym_lookup_name = lookup_name->make_ignore_params ();
 
+  /* This invariant is documented in quick-functions.h.  */
+  gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
+
   for (partial_symtab *ps : m_partial_symtabs->range ())
     {
       QUIT;
@@ -1157,7 +1160,7 @@ psymbol_functions::expand_symtabs_matching
 	    continue;
 	}
 
-      if ((symbol_matcher == NULL && lookup_name == NULL)
+      if (lookup_name == nullptr
 	  || recursively_search_psymtabs (ps, objfile, search_flags,
 					  domain, search,
 					  *psym_lookup_name,
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 7af0aebb9fe..5eb7c8423e2 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -167,6 +167,8 @@ struct quick_symbol_functions
      If the symbol name does not match LOOKUP_NAME, the symbol is skipped.
 
      If SYMBOL_MATCHER returns false, then the symbol is skipped.
+     Note that if SYMBOL_MATCHER is non-NULL, then LOOKUP_NAME must
+     also be provided.
 
      Otherwise, the symbol's symbol table is expanded and the
      notification function is called.  If the notification function
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index a10af68f5b1..f3d5a68b72e 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -405,6 +405,9 @@ objfile::expand_symtabs_matching
    domain_enum domain,
    enum search_domain kind)
 {
+  /* This invariant is documented in quick-functions.h.  */
+  gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
+
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog,
 		      "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n",
-- 
2.26.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Document quick_symbol_functions::expand_symtabs_matching invariant
  2021-06-27 14:24 [PATCH] Document quick_symbol_functions::expand_symtabs_matching invariant Tom Tromey
@ 2021-07-16 19:54 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2021-07-16 19:54 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> While working on my series to replace the DWARF psymbol reader, I
Tom> noticed that the expand_symtabs_matching has an undocumented
Tom> invariant.  I think that, if this invariant is not followed, then GDB
Tom> will crash.  So, this patch documents this in the relevant spots and
Tom> introduces some asserts to make it clear.

Tom> Regression tested on x86-64 Fedora 32.

I'm checking this in.

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-16 19:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27 14:24 [PATCH] Document quick_symbol_functions::expand_symtabs_matching invariant Tom Tromey
2021-07-16 19:54 ` Tom Tromey

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).