Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/3] Use std::optional in entry_point_address_query
Date: Fri, 13 Feb 2026 14:09:42 -0700	[thread overview]
Message-ID: <20260213-random-methods-v1-2-59bdac57c3e1@tromey.com> (raw)
In-Reply-To: <20260213-random-methods-v1-0-59bdac57c3e1@tromey.com>

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


  parent reply	other threads:[~2026-02-13 21:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=20260213-random-methods-v1-2-59bdac57c3e1@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