]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use std::optional in entry_point_address_query
authorTom Tromey <tom@tromey.com>
Thu, 12 Feb 2026 23:57:40 +0000 (16:57 -0700)
committerTom Tromey <tom@tromey.com>
Sat, 14 Feb 2026 17:27:50 +0000 (10:27 -0700)
This changes entry_point_address_query to return a std::optional.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/frame.c
gdb/progspace.c
gdb/progspace.h
gdb/solib-frv.c

index bfc85296942f8f447dc0e62d4394e7d9a9852486..5509e5ab7d7338092ab6fd2ec7c88cbd58c44f44 100644 (file)
@@ -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
index bfd7ca5bcb94c83c0fb4b8598a5334e8ae0b1d8b..3e10e57012bde6a2b2c41425bc9821ec36154920 100644 (file)
@@ -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
index 68d5ad35413a3f6a4758430930c7aa77c5d5d8ec..3ed33b2e472745f8b5c7fdbb942a1dd7bbd0314a 100644 (file)
@@ -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.  */
index 4460362a57fa6c05c8dd246342747b61a3d9ddff..95f97dc11333c361093d939e0e5ee6c1c2c8549f 100644 (file)
@@ -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;
 }