From: Tom Tromey Date: Thu, 12 Feb 2026 23:57:40 +0000 (-0700) Subject: Use std::optional in entry_point_address_query X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48c1417cc205948e911878d4a03a1f147326417a;p=thirdparty%2Fbinutils-gdb.git Use std::optional in entry_point_address_query This changes entry_point_address_query to return a std::optional. Approved-By: Simon Marchi --- 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 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 +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 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 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 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; }