Return iteration_status from iterate_over_objfiles_in_search_order_cb_ftype

Message ID 20260505150228.474870-1-tromey@adacore.com
State New
Headers
Series Return iteration_status from iterate_over_objfiles_in_search_order_cb_ftype |

Commit Message

Tom Tromey May 5, 2026, 3:02 p.m. UTC
  This changes iterate_over_objfiles_in_search_order_cb_ftype to return
iteration_status rather than bool, and updates the callers.

In a couple of spots I also opportunistically converted a local 'int'
to a 'bool'.

Regression tested on x86-64 Fedora 43.
---
 gdb/ada-lang.c          |  4 ++--
 gdb/cp-support.c        |  2 +-
 gdb/elfread.c           | 28 ++++++++++++++--------------
 gdb/findvar.c           |  4 +++-
 gdb/progspace.c         |  2 +-
 gdb/progspace.h         |  5 +++--
 gdb/python/py-objfile.c | 20 ++++++++++----------
 gdb/solib-svr4.c        |  4 ++--
 gdb/solib.c             |  2 +-
 gdb/solib.h             |  3 ++-
 gdb/symtab.c            |  8 +++++---
 gdb/windows-tdep.c      |  4 ++--
 12 files changed, 46 insertions(+), 40 deletions(-)


base-commit: 8c0ac471835ec86a67c5b42713d9f138f31e4014
  

Comments

Simon Marchi May 5, 2026, 5:13 p.m. UTC | #1
> @@ -631,26 +631,26 @@ gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw)
>  	 {
>  	   /* Don't return separate debug files.  */
>  	   if (obj->separate_debug_objfile_backlink != nullptr)
> -	     return false;
> +	     return iteration_status::keep_going;
>  
>  	   if ((obj->flags & OBJF_NOT_FILENAME) != 0)
> -	     return false;
> +	     return iteration_status::keep_going;
>  
>  	   const char *filename = objfile_filename (obj);
>  	   if (filename != NULL
>  	       && compare_filenames_for_search (filename, name))
>  	     {
>  	       objfile = obj;
> -	       return true;
> +	       return iteration_status::keep_going;
>  	     }
>  
>  	   if (compare_filenames_for_search (obj->original_name, name))
>  	     {
>  	       objfile = obj;
> -	       return true;
> +	       return iteration_status::keep_going;
>  	     }

These last two look wrong.

Other than that, LGTM.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon
  
Tom Tromey May 5, 2026, 5:14 p.m. UTC | #2
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

>> -	       return true;
>> +	       return iteration_status::keep_going;
>> }
>> 
>> if (compare_filenames_for_search (obj->original_name, name))
>> {
>> objfile = obj;
>> -	       return true;
>> +	       return iteration_status::keep_going;
>> }

Simon> These last two look wrong.

I even re-read the patch to double-check :(

I will postpone fixing this until I can see if a test case is possible.

Tom
  

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 759b81d31e4..94eb0e5f672 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -4991,11 +4991,11 @@  ada_lookup_simple_minsym (const char *name, struct objfile *objfile)
 	       {
 		 result.minsym = msymbol;
 		 result.objfile = obj;
-		 return true;
+		 return iteration_status::stop;
 	       }
 	   }
 
-	 return false;
+	 return iteration_status::keep_going;
        }, objfile);
 
   return result;
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index d040ad79469..229172d86ca 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1500,7 +1500,7 @@  add_symbol_overload_list_qualified (const char *func_name,
 		      SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
 		      SEARCH_FUNCTION_DOMAIN);
 
-	 return false;
+	 return iteration_status::keep_going;
        }, current_objfile);
 }
 
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 7e2f4fe8f3f..5889a4297c9 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -757,7 +757,7 @@  static int
 elf_gnu_ifunc_resolve_by_cache (const char *name, CORE_ADDR *addr_p)
 {
   gnu_ifunc_debug_printf ("resolving \"%s\" by cache", name);
-  int found = 0;
+  bool found = false;
   const char *func = __func__;
 
   /* FIXME: we only search the initial namespace.
@@ -770,11 +770,11 @@  elf_gnu_ifunc_resolve_by_cache (const char *name, CORE_ADDR *addr_p)
 	 elf_gnu_ifunc_cache *cache
 	   = elf_objfile_gnu_ifunc_cache_data.get (objfile);
 	 if (cache == nullptr)
-	   return false;
+	   return iteration_status::keep_going;
 
 	 auto it = cache->find (name);
 	 if (it == cache->end ())
-	   return false;
+	   return iteration_status::keep_going;
 
 	 if (addr_p != nullptr)
 	   *addr_p = it->second;
@@ -782,8 +782,8 @@  elf_gnu_ifunc_resolve_by_cache (const char *name, CORE_ADDR *addr_p)
 	 gnu_ifunc_debug_printf_func
 	   (func, "cache hit for \"%s\" -> %s in objfile %s", name,
 	    paddress (objfile->arch (), it->second), objfile_name (objfile));
-	 found = 1;
-	 return true;
+	 found = true;
+	 return iteration_status::stop;
        }, nullptr);
 
   if (!found)
@@ -806,7 +806,7 @@  elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
   gnu_ifunc_debug_printf ("resolving \"%s\" by GOT", name);
   char *name_got_plt;
   const size_t got_suffix_len = strlen (SYMBOL_GOT_PLT_SUFFIX);
-  int found = 0;
+  bool found = false;
   const char *func = __func__;
 
   name_got_plt = (char *) alloca (strlen (name) + got_suffix_len + 1);
@@ -831,19 +831,19 @@  elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
 	   = lookup_minimal_symbol (current_program_space, name_got_plt,
 				    objfile);
 	 if (msym.minsym == NULL)
-	   return 0;
+	   return iteration_status::keep_going;
 	 if (msym.minsym->type () != mst_slot_got_plt)
-	   return 0;
+	   return iteration_status::keep_going;
 	 pointer_address = msym.value_address ();
 
 	 plt = bfd_get_section_by_name (obfd, ".plt");
 	 if (plt == NULL)
-	   return 0;
+	   return iteration_status::keep_going;
 
 	 if (msym.minsym->size () != ptr_size)
-	   return 0;
+	   return iteration_status::keep_going;
 	 if (target_read_memory (pointer_address, buf, ptr_size) != 0)
-	   return 0;
+	   return iteration_status::keep_going;
 	 addr = extract_typed_address (buf, ptr_type);
 	 addr = gdbarch_convert_from_func_ptr_addr
 	   (gdbarch, addr, current_inferior ()->top_target ());
@@ -860,11 +860,11 @@  elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
 	     gnu_ifunc_debug_printf_func (func,
 					  "resolved \"%s\" via GOT to %s",
 					  name, paddress (gdbarch, addr));
-	     found = 1;
-	     return 1;
+	     found = true;
+	     return iteration_status::stop;
 	   }
 
-	 return 0;
+	 return iteration_status::keep_going;
        }, nullptr);
 
   if (!found)
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 98351143e79..812a3bf923b 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -455,7 +455,9 @@  language_defn::read_var_value (struct symbol *var,
 					       var->linkage_name (), objfile);
 
 		/* Stop if a match is found.  */
-		return bmsym.minsym != nullptr;
+		if (bmsym.minsym != nullptr)
+		  return iteration_status::stop;
+		return iteration_status::keep_going;
 	     },
 	   var->objfile ());
 
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 1407b058dfd..e8bbc2df5e5 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -129,7 +129,7 @@  program_space::iterate_over_objfiles_in_search_order
       (cb, current_objfile);
 
   for (auto &objfile : this->objfiles ())
-    if (cb (&objfile))
+    if (cb (&objfile) == iteration_status::stop)
       return;
 }
 
diff --git a/gdb/progspace.h b/gdb/progspace.h
index e9261ff8590..e7df99f888d 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -207,8 +207,9 @@  struct program_space
   /* Iterate over all objfiles of the program space in the order that makes the
      most sense to make global symbol searches.
 
-     CB is a callback function passed an objfile to be searched.  The iteration stops
-     if this function returns true.
+     CB is a callback function passed an objfile to be searched.  It
+     returns an iteration_status to indicate whether the search should
+     continue.
 
      If not nullptr, CURRENT_OBJFILE corresponds to the objfile being
      inspected when the symbol search was requested.  */
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index d427f149429..24ee46ab515 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -609,21 +609,21 @@  gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw)
 	 {
 	   /* Don't return separate debug files.  */
 	   if (obj->separate_debug_objfile_backlink != nullptr)
-	     return false;
+	     return iteration_status::keep_going;
 
 	   bfd *obfd = obj->obfd.get ();
 	   if (obfd == nullptr)
-	     return false;
+	     return iteration_status::keep_going;
 
 	   const bfd_build_id *obfd_build_id = build_id_bfd_get (obfd);
 	   if (obfd_build_id == nullptr)
-	     return false;
+	     return iteration_status::keep_going;
 
 	   if (!objfpy_build_id_matches (obfd_build_id, name))
-	     return false;
+	     return iteration_status::keep_going;
 
 	   objfile = obj;
-	   return true;
+	   return iteration_status::stop;
 	 }, gdbpy_current_objfile);
   else
     current_program_space->iterate_over_objfiles_in_search_order
@@ -631,26 +631,26 @@  gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw)
 	 {
 	   /* Don't return separate debug files.  */
 	   if (obj->separate_debug_objfile_backlink != nullptr)
-	     return false;
+	     return iteration_status::keep_going;
 
 	   if ((obj->flags & OBJF_NOT_FILENAME) != 0)
-	     return false;
+	     return iteration_status::keep_going;
 
 	   const char *filename = objfile_filename (obj);
 	   if (filename != NULL
 	       && compare_filenames_for_search (filename, name))
 	     {
 	       objfile = obj;
-	       return true;
+	       return iteration_status::keep_going;
 	     }
 
 	   if (compare_filenames_for_search (obj->original_name, name))
 	     {
 	       objfile = obj;
-	       return true;
+	       return iteration_status::keep_going;
 	     }
 
-	   return false;
+	   return iteration_status::keep_going;
 	 }, gdbpy_current_objfile);
 
   if (objfile != NULL)
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 8e3de4d3ea1..766cc21840e 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -3664,7 +3664,7 @@  svr4_solib_ops::iterate_over_objfiles_in_search_order
 	  && gdb_bfd_scan_elf_dyntag (DT_SYMBOLIC, abfd, nullptr, nullptr) == 1)
 	{
 	  checked_current_objfile = true;
-	  if (cb (current_objfile))
+	  if (cb (current_objfile) == iteration_status::stop)
 	    return;
 	}
     }
@@ -3700,7 +3700,7 @@  svr4_solib_ops::iterate_over_objfiles_in_search_order
       if (solib_base != debug_base)
 	continue;
 
-      if (cb (&objfile))
+      if (cb (&objfile) == iteration_status::stop)
 	return;
     }
 }
diff --git a/gdb/solib.c b/gdb/solib.c
index 782b844aa2f..6db5973b392 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -451,7 +451,7 @@  solib_ops::iterate_over_objfiles_in_search_order
    objfile *current_objfile) const
 {
   for (objfile &objfile : m_pspace->objfiles ())
-    if (cb (&objfile))
+    if (cb (&objfile) == iteration_status::stop)
       return;
 }
 
diff --git a/gdb/solib.h b/gdb/solib.h
index 564655c4a57..9471871b953 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -23,6 +23,7 @@ 
 #include "gdb_bfd.h"
 #include "gdbsupport/function-view.h"
 #include "gdbsupport/intrusive_list.h"
+#include "gdbsupport/iteration-status.h"
 #include "gdbsupport/owning_intrusive_list.h"
 #include "symfile-add-flags.h"
 #include "target-section.h"
@@ -141,7 +142,7 @@  using solib_up = std::unique_ptr<solib>;
    methods.  */
 
 using iterate_over_objfiles_in_search_order_cb_ftype
-  = gdb::function_view<bool (objfile *)>;
+  = gdb::function_view<iteration_status (objfile *)>;
 
 struct solib_ops
 {
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 3c10e1fd750..d9390d98c26 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2564,7 +2564,9 @@  lookup_global_or_static_symbol (const char *name,
 	 {
 	   result = lookup_symbol_in_objfile (objfile_iter, block_index,
 					      name, domain);
-	   return result.symbol != nullptr;
+	   if (result.symbol != nullptr)
+	     return iteration_status::stop;
+	   return iteration_status::keep_going;
 	 },
        objfile);
 
@@ -6407,10 +6409,10 @@  find_main_name (void)
 	 if (symbol_found_p)
 	   {
 	     set_main_name (pspace, "main", lang);
-	     return true;
+	     return iteration_status::stop;
 	   }
 
-	 return false;
+	 return iteration_status::keep_going;
        }, nullptr);
 
   if (symbol_found_p)
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index 38ee1d7275e..efca38d9438 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -915,14 +915,14 @@  windows_solib_ops::iterate_over_objfiles_in_search_order
 {
   if (current_objfile)
     {
-      if (cb (current_objfile))
+      if (cb (current_objfile) == iteration_status::stop)
 	return;
     }
 
   for (objfile &objfile : m_pspace->objfiles ())
     if (&objfile != current_objfile)
       {
-	if (cb (&objfile))
+	if (cb (&objfile) == iteration_status::stop)
 	  return;
       }
 }