Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 0/3] Change some functions to methods of program_space
@ 2026-02-13 21:09 Tom Tromey
  2026-02-13 21:09 ` [PATCH 1/3] Move entry point functions to program_space Tom Tromey
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Tom Tromey @ 2026-02-13 21:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes a few functions to become methods of program_space.
It also moves them to progspace.[ch], where they belong.

Regression tested on x86-64 Fedora 40.

Signed-off-by: Tom Tromey <tom@tromey.com>
---
Tom Tromey (3):
      Move entry point functions to program_space
      Use std::optional in entry_point_address_query
      Change have_*_symbols functions to methods of program_space

 gdb/ada-exp.y        |  4 ++--
 gdb/arc-tdep.c       |  2 +-
 gdb/arch-utils.c     |  2 +-
 gdb/c-exp.y          |  4 ++--
 gdb/cli/cli-cmds.c   |  4 ++--
 gdb/d-exp.y          |  4 ++--
 gdb/frame.c          |  8 +++----
 gdb/go-exp.y         |  4 ++--
 gdb/infcall.c        |  2 +-
 gdb/linespec.c       | 10 ++++----
 gdb/objfiles.c       | 65 ----------------------------------------------------
 gdb/objfiles.h       | 22 ------------------
 gdb/p-exp.y          |  4 ++--
 gdb/parse.c          |  4 ++--
 gdb/progspace.c      | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/progspace.h      | 20 ++++++++++++++++
 gdb/solib-frv.c      |  9 ++++----
 gdb/source.c         |  4 ++--
 gdb/symfile.c        |  8 +++----
 gdb/symtab.c         |  8 +++----
 gdb/tui/tui-disasm.c |  4 ++--
 21 files changed, 125 insertions(+), 129 deletions(-)
---
base-commit: 51b7445c65ff06a6d9740fc635be73287527a0a5
change-id: 20260213-random-methods-2f946240d78d

Best regards,
-- 
Tom Tromey <tom@tromey.com>


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

* [PATCH 1/3] Move entry point functions to program_space
  2026-02-13 21:09 [PATCH 0/3] Change some functions to methods of program_space Tom Tromey
@ 2026-02-13 21:09 ` Tom Tromey
  2026-02-13 21:09 ` [PATCH 2/3] Use std::optional in entry_point_address_query Tom Tromey
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-02-13 21:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes a couple of entry-point-related functions to be methods
on program_space, and moves them to progspace.c.
---
 gdb/arc-tdep.c   |  2 +-
 gdb/arch-utils.c |  2 +-
 gdb/frame.c      |  2 +-
 gdb/infcall.c    |  2 +-
 gdb/objfiles.c   | 28 ----------------------------
 gdb/objfiles.h   | 10 ----------
 gdb/progspace.c  | 28 ++++++++++++++++++++++++++++
 gdb/progspace.h  |  8 ++++++++
 gdb/solib-frv.c  |  2 +-
 9 files changed, 41 insertions(+), 43 deletions(-)

diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 48f83dd57c6..99f002341ee 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -861,7 +861,7 @@ arc_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, CORE_ADDR funaddr,
 		     struct regcache *regcache)
 {
   *real_pc = funaddr;
-  *bp_addr = entry_point_address (current_program_space);
+  *bp_addr = current_program_space->entry_point_address ();
   return sp;
 }
 
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index c3ed8f07dc1..9d3dbfa2d81 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -57,7 +57,7 @@ displaced_step_at_entry_point (struct gdbarch *gdbarch)
   CORE_ADDR addr;
   int bp_len;
 
-  addr = entry_point_address (current_program_space);
+  addr = current_program_space->entry_point_address ();
 
   /* Inferior calls also use the entry point as a breakpoint location.
      We don't want displaced stepping to interfere with those
diff --git a/gdb/frame.c b/gdb/frame.c
index 8cb1d0a5c42..bfc85296942 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2677,7 +2677,7 @@ inside_entry_func (const frame_info_ptr &this_frame)
 {
   CORE_ADDR entry_point;
 
-  if (!entry_point_address_query (current_program_space, &entry_point))
+  if (!current_program_space->entry_point_address_query (&entry_point))
     return false;
 
   return get_frame_func (this_frame) == entry_point;
diff --git a/gdb/infcall.c b/gdb/infcall.c
index dcbae679d07..51636ff5403 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -1279,7 +1279,7 @@ call_function_by_hand_dummy (struct value *function,
 	CORE_ADDR dummy_addr;
 
 	real_pc = funaddr;
-	dummy_addr = entry_point_address (current_program_space);
+	dummy_addr = current_program_space->entry_point_address ();
 
 	/* A call dummy always consists of just a single breakpoint, so
 	   its address is the same as the address of the dummy.
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 14c07371f15..4f5258e971d 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -284,34 +284,6 @@ objfile::objfile (gdb_bfd_ref_ptr bfd_, program_space *pspace,
   set_objfile_per_bfd (this);
 }
 
-/* See objfiles.h.  */
-
-int
-entry_point_address_query (program_space *pspace, CORE_ADDR *entry_p)
-{
-  objfile *objf = pspace->symfile_object_file;
-  if (objf == NULL || !objf->per_bfd->ei.entry_point_p)
-    return 0;
-
-  int idx = objf->per_bfd->ei.the_bfd_section_index;
-  *entry_p = objf->per_bfd->ei.entry_point + objf->section_offsets[idx];
-
-  return 1;
-}
-
-/* See objfiles.h.  */
-
-CORE_ADDR
-entry_point_address (program_space *pspace)
-{
-  CORE_ADDR retval;
-
-  if (!entry_point_address_query (pspace, &retval))
-    error (_("Entry point address is not known."));
-
-  return retval;
-}
-
 separate_debug_iterator &
 separate_debug_iterator::operator++ ()
 {
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 59ad70dfffa..371fd223693 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -904,16 +904,6 @@ obj_section::set_offset (CORE_ADDR offset)
 
 /* Declarations for functions defined in objfiles.c */
 
-/* If there is a valid and known entry point in PSPACE, fill *ENTRY_P with it
-   and return non-zero.  */
-
-extern int entry_point_address_query (program_space *pspace,
-				      CORE_ADDR *entry_p);
-
-/* Get the entry point address in PSPACE.  Call error if it is not known.  */
-
-extern CORE_ADDR entry_point_address (program_space *pspace);
-
 extern void build_objfile_section_table (struct objfile *);
 
 extern void free_objfile_separate_debug (struct objfile *);
diff --git a/gdb/progspace.c b/gdb/progspace.c
index f16c222ec80..bfd7ca5bcb9 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -285,6 +285,34 @@ program_space::empty ()
   return find_inferior_for_program_space (this) == nullptr;
 }
 
+/* See progspace.h.  */
+
+int
+program_space::entry_point_address_query (CORE_ADDR *entry_p) const
+{
+  objfile *objf = symfile_object_file;
+  if (objf == NULL || !objf->per_bfd->ei.entry_point_p)
+    return 0;
+
+  int idx = objf->per_bfd->ei.the_bfd_section_index;
+  *entry_p = objf->per_bfd->ei.entry_point + objf->section_offsets[idx];
+
+  return 1;
+}
+
+/* See progspace.h.  */
+
+CORE_ADDR
+program_space::entry_point_address () const
+{
+  CORE_ADDR retval;
+
+  if (!entry_point_address_query (&retval))
+    error (_("Entry point address is not known."));
+
+  return retval;
+}
+
 /* Prints the list of program spaces and their details on UIOUT.  If
    REQUESTED is not -1, it's the ID of the pspace that should be
    printed.  Otherwise, all spaces are printed.  */
diff --git a/gdb/progspace.h b/gdb/progspace.h
index d013920b0f6..68d5ad35413 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -332,6 +332,14 @@ struct program_space
     return m_target_sections;
   }
 
+  /* If there is a valid and known entry point in this program space,
+     fill *ENTRY_P with it and return non-zero.  */
+  int entry_point_address_query (CORE_ADDR *entry_p) const;
+
+  /* Get the entry point address in this program space.  Call error if
+     it is not known.  */
+  CORE_ADDR entry_point_address () const;
+
   /* Unique ID number.  */
   int num = 0;
 
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index 5cf853c4115..4460362a57f 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -697,7 +697,7 @@ enable_break (void)
       return 0;
     }
 
-  if (!entry_point_address_query (current_program_space, &entry_point))
+  if (!current_program_space->entry_point_address_query (&entry_point))
     {
       solib_debug_printf ("Symbol file has no entry point.");
       return 0;

-- 
2.49.0


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

* [PATCH 2/3] Use std::optional in entry_point_address_query
  2026-02-13 21:09 [PATCH 0/3] Change some functions to methods of program_space Tom Tromey
  2026-02-13 21:09 ` [PATCH 1/3] Move entry point functions to program_space Tom Tromey
@ 2026-02-13 21:09 ` Tom Tromey
  2026-02-13 21:09 ` [PATCH 3/3] Change have_*_symbols functions to methods of program_space Tom Tromey
  2026-02-14  4:17 ` [PATCH 0/3] Change some " Simon Marchi
  3 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-02-13 21:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes entry_point_address_query to return a std::optional.
---
 gdb/frame.c     |  8 ++++----
 gdb/progspace.c | 16 +++++++---------
 gdb/progspace.h |  4 ++--
 gdb/solib-frv.c |  9 +++++----
 4 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/gdb/frame.c b/gdb/frame.c
index bfc85296942..5509e5ab7d7 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2675,12 +2675,12 @@ inside_main_func (const frame_info_ptr &this_frame)
 static bool
 inside_entry_func (const frame_info_ptr &this_frame)
 {
-  CORE_ADDR entry_point;
-
-  if (!current_program_space->entry_point_address_query (&entry_point))
+  std::optional<CORE_ADDR> entry_point
+    = current_program_space->entry_point_address_query ();
+  if (!entry_point.has_value ())
     return false;
 
-  return get_frame_func (this_frame) == entry_point;
+  return get_frame_func (this_frame) == *entry_point;
 }
 
 /* Return a structure containing various interesting information about
diff --git a/gdb/progspace.c b/gdb/progspace.c
index bfd7ca5bcb9..3e10e57012b 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -287,17 +287,15 @@ program_space::empty ()
 
 /* See progspace.h.  */
 
-int
-program_space::entry_point_address_query (CORE_ADDR *entry_p) const
+std::optional<CORE_ADDR>
+program_space::entry_point_address_query () const
 {
   objfile *objf = symfile_object_file;
   if (objf == NULL || !objf->per_bfd->ei.entry_point_p)
-    return 0;
+    return {};
 
   int idx = objf->per_bfd->ei.the_bfd_section_index;
-  *entry_p = objf->per_bfd->ei.entry_point + objf->section_offsets[idx];
-
-  return 1;
+  return objf->per_bfd->ei.entry_point + objf->section_offsets[idx];
 }
 
 /* See progspace.h.  */
@@ -305,12 +303,12 @@ program_space::entry_point_address_query (CORE_ADDR *entry_p) const
 CORE_ADDR
 program_space::entry_point_address () const
 {
-  CORE_ADDR retval;
+  std::optional<CORE_ADDR> retval = entry_point_address_query ();
 
-  if (!entry_point_address_query (&retval))
+  if (!retval.has_value ())
     error (_("Entry point address is not known."));
 
-  return retval;
+  return *retval;
 }
 
 /* Prints the list of program spaces and their details on UIOUT.  If
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 68d5ad35413..3ed33b2e472 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -333,8 +333,8 @@ struct program_space
   }
 
   /* If there is a valid and known entry point in this program space,
-     fill *ENTRY_P with it and return non-zero.  */
-  int entry_point_address_query (CORE_ADDR *entry_p) const;
+     return it.  Otherwise return an empty optional.  */
+  std::optional<CORE_ADDR> entry_point_address_query () const;
 
   /* Get the entry point address in this program space.  Call error if
      it is not known.  */
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index 4460362a57f..95f97dc1133 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -689,7 +689,6 @@ static int
 enable_break (void)
 {
   asection *interp_sect;
-  CORE_ADDR entry_point;
 
   if (current_program_space->symfile_object_file == NULL)
     {
@@ -697,7 +696,9 @@ enable_break (void)
       return 0;
     }
 
-  if (!current_program_space->entry_point_address_query (&entry_point))
+  std::optional<CORE_ADDR> entry_point
+    = current_program_space->entry_point_address_query ();
+  if (!entry_point.has_value ())
     {
       solib_debug_printf ("Symbol file has no entry point.");
       return 0;
@@ -715,10 +716,10 @@ enable_break (void)
       return 0;
     }
 
-  create_solib_event_breakpoint (current_inferior ()->arch (), entry_point);
+  create_solib_event_breakpoint (current_inferior ()->arch (), *entry_point);
 
   solib_debug_printf ("solib event breakpoint placed at entry point: %s",
-		      hex_string_custom (entry_point, 8));
+		      hex_string_custom (*entry_point, 8));
   return 1;
 }
 

-- 
2.49.0


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

* [PATCH 3/3] Change have_*_symbols functions to methods of program_space
  2026-02-13 21:09 [PATCH 0/3] Change some functions to methods of program_space Tom Tromey
  2026-02-13 21:09 ` [PATCH 1/3] Move entry point functions to program_space Tom Tromey
  2026-02-13 21:09 ` [PATCH 2/3] Use std::optional in entry_point_address_query Tom Tromey
@ 2026-02-13 21:09 ` Tom Tromey
  2026-02-14  4:16   ` Simon Marchi
  2026-02-14  4:17 ` [PATCH 0/3] Change some " Simon Marchi
  3 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2026-02-13 21:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes the have_*_symbols functions to be methods of
program_space.
---
 gdb/ada-exp.y        |  4 ++--
 gdb/c-exp.y          |  4 ++--
 gdb/cli/cli-cmds.c   |  4 ++--
 gdb/d-exp.y          |  4 ++--
 gdb/go-exp.y         |  4 ++--
 gdb/linespec.c       | 10 +++++-----
 gdb/objfiles.c       | 37 -------------------------------------
 gdb/objfiles.h       | 12 ------------
 gdb/p-exp.y          |  4 ++--
 gdb/parse.c          |  4 ++--
 gdb/progspace.c      | 36 ++++++++++++++++++++++++++++++++++++
 gdb/progspace.h      | 12 ++++++++++++
 gdb/source.c         |  4 ++--
 gdb/symfile.c        |  8 ++++----
 gdb/symtab.c         |  8 ++++----
 gdb/tui/tui-disasm.c |  4 ++--
 16 files changed, 79 insertions(+), 80 deletions(-)

diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 771a867c4ae..1a7d17f9d04 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1870,8 +1870,8 @@ write_var_or_type (struct parser_state *par_state,
 	    }
 	}
 
-      if (!have_full_symbols (current_program_space)
-	  && !have_partial_symbols (current_program_space)
+      if (!current_program_space->have_full_symbols ()
+	  && !current_program_space->have_partial_symbols ()
 	  && block == NULL)
 	error (_("No symbol table is loaded.  Use the \"file\" command."));
       if (block == par_state->expression_context_block)
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 9a37eb5fb69..68e728ef1b0 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1201,8 +1201,8 @@ variable:	name_not_typename
 				= lookup_minimal_symbol (current_program_space, arg.c_str ());
 			      if (msymbol.minsym == NULL)
 				{
-				  if (!have_full_symbols (current_program_space)
-				      && !have_partial_symbols (current_program_space))
+				  if (!current_program_space->have_full_symbols ()
+				      && !current_program_space->have_partial_symbols ())
 				    error (_("No symbol table is loaded.  Use the \"file\" command."));
 				  else
 				    error (_("No symbol \"%s\" in current context."),
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 5cf8f87cd75..21d067c4f5d 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1349,8 +1349,8 @@ list_command (const char *arg, int from_tty)
      and clear NO_END; however, if one of the arguments is blank,
      set DUMMY_BEG or DUMMY_END to record that fact.  */
 
-  if (!have_full_symbols (current_program_space)
-      && !have_partial_symbols (current_program_space))
+  if (!current_program_space->have_full_symbols ()
+      && !current_program_space->have_partial_symbols ())
     error (_("No symbol table is loaded.  Use the \"file\" command."));
 
   std::vector<symtab_and_line> sals;
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index eef87702353..e0ce8a86473 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -466,8 +466,8 @@ PrimaryExpression:
 			= lookup_minimal_symbol (current_program_space, copy.c_str ());
 		      if (msymbol.minsym != NULL)
 			pstate->push_new<var_msym_value_operation> (msymbol);
-		      else if (!have_full_symbols (current_program_space)
-			       && !have_partial_symbols (current_program_space))
+		      else if (!current_program_space->have_full_symbols ()
+			       && !current_program_space->have_partial_symbols ())
 			error (_("No symbol table is loaded.  Use the \"file\" command"));
 		      else
 			error (_("No symbol \"%s\" in current context."),
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index d6060c9567d..a7114152069 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -575,8 +575,8 @@ variable:	name_not_typename
 			      if (msymbol.minsym != NULL)
 				pstate->push_new<var_msym_value_operation>
 				  (msymbol);
-			      else if (!have_full_symbols (current_program_space)
-				       && !have_partial_symbols (current_program_space))
+			      else if (!current_program_space->have_full_symbols ()
+				       && !current_program_space->have_partial_symbols ())
 				error (_("No symbol table is loaded.  "
 				       "Use the \"file\" command."));
 			      else
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 4376a769e49..873e085a4c8 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1524,9 +1524,9 @@ symbol_not_found_error (const char *symbol, const char *filename)
   if (symbol == NULL)
     symbol = "";
 
-  if (!have_full_symbols (current_program_space)
-      && !have_partial_symbols (current_program_space)
-      && !have_minimal_symbols (current_program_space))
+  if (!current_program_space->have_full_symbols ()
+      && !current_program_space->have_partial_symbols ()
+      && !current_program_space->have_minimal_symbols ())
     throw_error (NOT_FOUND_ERROR,
 		 _("No symbol table is loaded.  Use the \"file\" command."));
 
@@ -3648,8 +3648,8 @@ symtabs_from_filename (const char *filename,
 
   if (result.empty ())
     {
-      if (!have_full_symbols (current_program_space)
-	  && !have_partial_symbols (current_program_space))
+      if (!current_program_space->have_full_symbols ()
+	  && !current_program_space->have_partial_symbols ())
 	throw_error (NOT_FOUND_ERROR,
 		     _("No symbol table is loaded.  "
 		       "Use the \"file\" command."));
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 4f5258e971d..ff98cf28ca6 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -611,31 +611,6 @@ objfile::has_symbols ()
   return false;
 }
 
-/* See objfiles.h.  */
-
-bool
-have_partial_symbols (program_space *pspace)
-{
-  for (objfile &ofp : pspace->objfiles ())
-    if (ofp.has_partial_symbols ())
-      return true;
-
-  return false;
-}
-
-/* See objfiles.h.  */
-
-bool
-have_full_symbols (program_space *pspace)
-{
-  for (objfile &ofp : pspace->objfiles ())
-    if (ofp.has_full_symbols ())
-      return true;
-
-  return false;
-}
-
-
 /* See objfiles.h.  */
 
 void
@@ -651,18 +626,6 @@ objfile_purge_solibs (program_space *pspace)
     }
 }
 
-/* See objfiles.h.  */
-
-bool
-have_minimal_symbols (program_space *pspace)
-{
-  for (objfile &ofp : pspace->objfiles ())
-    if (ofp.per_bfd->minimal_symbol_count > 0)
-      return true;
-
-  return false;
-}
-
 /* Qsort comparison function.  */
 
 static bool
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 371fd223693..89ac559ce81 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -912,14 +912,6 @@ extern void objfile_relocate (struct objfile *,
 			      gdb::array_view<const CORE_ADDR>);
 extern void objfile_rebase (struct objfile *, CORE_ADDR);
 
-/* Return true if any objfile of PSPACE has partial symbols.  */
-
-extern bool have_partial_symbols (program_space *pspace);
-
-/* Return true if any objfile of PSPACE has full symbols.  */
-
-extern bool have_full_symbols (program_space *pspace);
-
 extern void objfile_set_sym_fns (struct objfile *objfile,
 				 const struct sym_fns *sf);
 
@@ -948,10 +940,6 @@ extern void objfile_purge_solibs (program_space *pspace);
 /* Functions for dealing with the minimal symbol table, really a misc
    address<->symbol mapping for things we don't have debug symbols for.  */
 
-/* Return true if any objfile of PSPACE has minimal symbols.  */
-
-extern bool have_minimal_symbols (program_space *pspace);
-
 extern struct obj_section *find_pc_section (CORE_ADDR pc);
 
 /* Return true if PC is in a section called NAME.  */
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index 8195a08c1ac..000ac5342e2 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -723,8 +723,8 @@ variable:	name_not_typename
 			      if (msymbol.minsym != NULL)
 				pstate->push_new<var_msym_value_operation>
 				  (msymbol);
-			      else if (!have_full_symbols (current_program_space)
-				       && !have_partial_symbols (current_program_space))
+			      else if (!current_program_space->have_full_symbols ()
+				       && !current_program_space->have_partial_symbols ())
 				error (_("No symbol table is loaded.  "
 				       "Use the \"file\" command."));
 			      else
diff --git a/gdb/parse.c b/gdb/parse.c
index 21a59d0f2be..e7592d0fd23 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -148,8 +148,8 @@ parser_state::push_symbol (const char *name, block_symbol sym)
 	= lookup_minimal_symbol (current_program_space, name);
       if (msymbol.minsym != NULL)
 	push_new<expr::var_msym_value_operation> (msymbol);
-      else if (!have_full_symbols (current_program_space)
-	       && !have_partial_symbols (current_program_space))
+      else if (!current_program_space->have_full_symbols ()
+	       && !current_program_space->have_partial_symbols ())
 	error (_("No symbol table is loaded.  Use the \"file\" command."));
       else
 	error (_("No symbol \"%s\" in current context."), name);
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 3e10e57012b..6edd750334c 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -311,6 +311,42 @@ program_space::entry_point_address () const
   return *retval;
 }
 
+/* See progspace.h.  */
+
+bool
+program_space::have_partial_symbols ()
+{
+  for (objfile &ofp : objfiles ())
+    if (ofp.has_partial_symbols ())
+      return true;
+
+  return false;
+}
+
+/* See progspace.h.  */
+
+bool
+program_space::have_full_symbols ()
+{
+  for (objfile &ofp : objfiles ())
+    if (ofp.has_full_symbols ())
+      return true;
+
+  return false;
+}
+
+/* See progspace.h.  */
+
+bool
+program_space::have_minimal_symbols ()
+{
+  for (objfile &ofp : objfiles ())
+    if (ofp.per_bfd->minimal_symbol_count > 0)
+      return true;
+
+  return false;
+}
+
 /* Prints the list of program spaces and their details on UIOUT.  If
    REQUESTED is not -1, it's the ID of the pspace that should be
    printed.  Otherwise, all spaces are printed.  */
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 3ed33b2e472..b3d8d6d39ed 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -340,6 +340,18 @@ struct program_space
      it is not known.  */
   CORE_ADDR entry_point_address () const;
 
+  /* Return true if any objfile of this program space has partial
+     symbols.  */
+  bool have_partial_symbols ();
+
+  /* Return true if any objfile of this program space has full
+     symbols.  */
+  bool have_full_symbols ();
+
+  /* Return true if any objfile of this program space has minimal
+     symbols.  */
+  bool have_minimal_symbols ();
+
   /* Unique ID number.  */
   int num = 0;
 
diff --git a/gdb/source.c b/gdb/source.c
index f890533b931..cd5434a80a2 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -254,8 +254,8 @@ get_current_source_symtab_and_line (program_space *pspace)
 void
 set_default_source_symtab_and_line (void)
 {
-  if (!have_full_symbols (current_program_space)
-      && !have_partial_symbols (current_program_space))
+  if (!current_program_space->have_full_symbols ()
+      && !current_program_space->have_partial_symbols ())
     error (_("No symbol table is loaded.  Use the \"file\" command."));
 
   /* Pull in a current source symtab if necessary.  */
diff --git a/gdb/symfile.c b/gdb/symfile.c
index aadb449153e..48daf66673d 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1040,8 +1040,8 @@ symbol_file_add_with_addrs (const gdb_bfd_ref_ptr &abfd, const char *name,
 
   if (from_tty
       && (always_confirm
-	  || ((have_full_symbols (current_program_space)
-	       || have_partial_symbols (current_program_space))
+	  || ((current_program_space->have_full_symbols ()
+	       || current_program_space->have_partial_symbols ())
 	      && mainline))
       && !query (_("Load new symbol table from \"%s\"? "), name))
     error (_("Not confirmed."));
@@ -1189,8 +1189,8 @@ symbol_file_add_main_1 (const char *args, symfile_add_flags add_flags,
 void
 symbol_file_clear (int from_tty)
 {
-  if ((have_full_symbols (current_program_space)
-       || have_partial_symbols (current_program_space))
+  if ((current_program_space->have_full_symbols ()
+       || current_program_space->have_partial_symbols ())
       && from_tty
       && (current_program_space->symfile_object_file
 	  ? !query (_("Discard symbol table from `%s'? "),
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 07436104ce7..1aaa1d9e5d7 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4573,8 +4573,8 @@ info_sources_worker (struct ui_out *uiout,
 static void
 info_sources_command (const char *args, int from_tty)
 {
-  if (!have_full_symbols (current_program_space)
-      && !have_partial_symbols (current_program_space))
+  if (!current_program_space->have_full_symbols ()
+      && !current_program_space->have_partial_symbols ())
     error (_("No symbol table is loaded.  Use the \"file\" command."));
 
   filename_partial_match_opts match_opts;
@@ -6258,8 +6258,8 @@ make_source_files_completion_list (const char *text)
   const char *base_name;
   struct add_partial_filename_data datum;
 
-  if (!have_full_symbols (current_program_space)
-      && !have_partial_symbols (current_program_space))
+  if (!current_program_space->have_full_symbols ()
+      && !current_program_space->have_partial_symbols ())
     return list;
 
   filename_seen_cache filenames_seen;
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 2b22ca9efca..fee5eb53c61 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -393,8 +393,8 @@ tui_get_begin_asm_address (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
 
   if (tui_location.addr () == 0)
     {
-      if (have_full_symbols (current_program_space)
-	  || have_partial_symbols (current_program_space))
+      if (current_program_space->have_full_symbols ()
+	  || current_program_space->have_partial_symbols ())
 	{
 	  set_default_source_symtab_and_line ();
 	  symtab_and_line sal

-- 
2.49.0


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

* Re: [PATCH 3/3] Change have_*_symbols functions to methods of program_space
  2026-02-13 21:09 ` [PATCH 3/3] Change have_*_symbols functions to methods of program_space Tom Tromey
@ 2026-02-14  4:16   ` Simon Marchi
  2026-02-14 17:33     ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Marchi @ 2026-02-14  4:16 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches


>  /* Prints the list of program spaces and their details on UIOUT.  If
>     REQUESTED is not -1, it's the ID of the pspace that should be
>     printed.  Otherwise, all spaces are printed.  */
> diff --git a/gdb/progspace.h b/gdb/progspace.h
> index 3ed33b2e472..b3d8d6d39ed 100644
> --- a/gdb/progspace.h
> +++ b/gdb/progspace.h
> @@ -340,6 +340,18 @@ struct program_space
>       it is not known.  */
>    CORE_ADDR entry_point_address () const;
>  
> +  /* Return true if any objfile of this program space has partial
> +     symbols.  */
> +  bool have_partial_symbols ();
> +
> +  /* Return true if any objfile of this program space has full
> +     symbols.  */
> +  bool have_full_symbols ();
> +
> +  /* Return true if any objfile of this program space has minimal
> +     symbols.  */
> +  bool have_minimal_symbols ();

Maybe just a naming nit, I would s/have_/has_/ in the names.  I feel
like it would read and sound better:

  pspace->have_partial_symbols ()

vs

  pspace->has_partial_symbols ()

Assuming that the pspace is the entity that "has" the symbols.

Simon

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

* Re: [PATCH 0/3] Change some functions to methods of program_space
  2026-02-13 21:09 [PATCH 0/3] Change some functions to methods of program_space Tom Tromey
                   ` (2 preceding siblings ...)
  2026-02-13 21:09 ` [PATCH 3/3] Change have_*_symbols functions to methods of program_space Tom Tromey
@ 2026-02-14  4:17 ` Simon Marchi
  3 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2026-02-14  4:17 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches



On 2026-02-13 16:09, Tom Tromey wrote:
> This changes a few functions to become methods of program_space.
> It also moves them to progspace.[ch], where they belong.
> 
> Regression tested on x86-64 Fedora 40.
> 
> Signed-off-by: Tom Tromey <tom@tromey.com>
> ---
> Tom Tromey (3):
>       Move entry point functions to program_space
>       Use std::optional in entry_point_address_query
>       Change have_*_symbols functions to methods of program_space
> 
>  gdb/ada-exp.y        |  4 ++--
>  gdb/arc-tdep.c       |  2 +-
>  gdb/arch-utils.c     |  2 +-
>  gdb/c-exp.y          |  4 ++--
>  gdb/cli/cli-cmds.c   |  4 ++--
>  gdb/d-exp.y          |  4 ++--
>  gdb/frame.c          |  8 +++----
>  gdb/go-exp.y         |  4 ++--
>  gdb/infcall.c        |  2 +-
>  gdb/linespec.c       | 10 ++++----
>  gdb/objfiles.c       | 65 ----------------------------------------------------
>  gdb/objfiles.h       | 22 ------------------
>  gdb/p-exp.y          |  4 ++--
>  gdb/parse.c          |  4 ++--
>  gdb/progspace.c      | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
>  gdb/progspace.h      | 20 ++++++++++++++++
>  gdb/solib-frv.c      |  9 ++++----
>  gdb/source.c         |  4 ++--
>  gdb/symfile.c        |  8 +++----
>  gdb/symtab.c         |  8 +++----
>  gdb/tui/tui-disasm.c |  4 ++--
>  21 files changed, 125 insertions(+), 129 deletions(-)
> ---
> base-commit: 51b7445c65ff06a6d9740fc635be73287527a0a5
> change-id: 20260213-random-methods-2f946240d78d
> 
> Best regards,

I sent a comment about the naming on patch 3, but otherwise it all LGTM.

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

Simon

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

* Re: [PATCH 3/3] Change have_*_symbols functions to methods of program_space
  2026-02-14  4:16   ` Simon Marchi
@ 2026-02-14 17:33     ` Tom Tromey
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-02-14 17:33 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, gdb-patches

>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

Simon> Maybe just a naming nit, I would s/have_/has_/ in the names.  I feel
Simon> like it would read and sound better:

Alright, I'll do that.

Tom

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

end of thread, other threads:[~2026-02-14 17:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-13 21:09 [PATCH 0/3] Change some functions to methods of program_space Tom Tromey
2026-02-13 21:09 ` [PATCH 1/3] Move entry point functions to program_space Tom Tromey
2026-02-13 21:09 ` [PATCH 2/3] Use std::optional in entry_point_address_query Tom Tromey
2026-02-13 21:09 ` [PATCH 3/3] Change have_*_symbols functions to methods of program_space Tom Tromey
2026-02-14  4:16   ` Simon Marchi
2026-02-14 17:33     ` Tom Tromey
2026-02-14  4:17 ` [PATCH 0/3] Change some " Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox