[v5,03/13] gdb: Add get_main_func_start_pc to refactor frame.c:inside_main_func.
Checks
Commit Message
Refactor frame.c:inside_main_func to use the new function
get_main_func_start_pc, which will be called in a following commmit.
Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
---
gdb/frame.c | 37 +++++++++++++++++++++++++------------
gdb/frame.h | 6 ++++++
2 files changed, 31 insertions(+), 12 deletions(-)
@@ -2650,27 +2650,26 @@ frame_debug_got_null_frame (const frame_info_ptr &this_frame,
}
}
-/* Is this (non-sentinel) frame in the "main"() function? */
+/* See frame.h. */
-static bool
-inside_main_func (const frame_info_ptr &this_frame)
+std::optional<CORE_ADDR>
+get_main_func_start_pc (gdbarch *gdbarch, const language lang)
{
if (current_program_space->symfile_object_file == nullptr)
- return false;
+ return {};
- CORE_ADDR sym_addr = 0;
const char *name = main_name ();
bound_minimal_symbol msymbol
= lookup_minimal_symbol (current_program_space, name,
current_program_space->symfile_object_file);
+ CORE_ADDR sym_addr = 0;
if (msymbol.minsym != nullptr)
sym_addr = msymbol.value_address ();
/* Favor a full symbol in Fortran, for the case where the Fortran main
is also called "main". */
- if (msymbol.minsym == nullptr
- || get_frame_language (this_frame) == language_fortran)
+ if (msymbol.minsym == nullptr || lang == language_fortran)
{
/* In some language (for example Fortran) there will be no minimal
symbol with the name of the main function. In this case we should
@@ -2686,16 +2685,30 @@ inside_main_func (const frame_info_ptr &this_frame)
sym_addr = block->start ();
}
else if (msymbol.minsym == nullptr)
- return false;
+ return {};
}
/* Convert any function descriptor addresses into the actual function
code address. */
- sym_addr = (gdbarch_convert_from_func_ptr_addr
- (get_frame_arch (this_frame), sym_addr,
- current_inferior ()->top_target ()));
+ return {gdbarch_convert_from_func_ptr_addr
+ (gdbarch,
+ sym_addr,
+ current_inferior ()->top_target ())};
+}
+
+/* Is this (non-sentinel) frame in the "main"() function? */
+
+static bool
+inside_main_func (const frame_info_ptr &this_frame)
+{
+ std::optional<CORE_ADDR> sym_addr
+ = get_main_func_start_pc (get_frame_arch (this_frame),
+ get_frame_language (this_frame));
+
+ if (!sym_addr.has_value ())
+ return false;
- return sym_addr == get_frame_func (this_frame);
+ return get_frame_func (this_frame) == *sym_addr;
}
/* Test whether THIS_FRAME is inside the process entry point function. */
@@ -888,6 +888,12 @@ extern struct symbol *get_frame_function (const frame_info_ptr &);
extern CORE_ADDR get_pc_function_start (CORE_ADDR);
+/* If possible, get the start pc of the main function of the current program
+ space for the language LANG. */
+
+extern std::optional<CORE_ADDR> get_main_func_start_pc (gdbarch *gdbarch,
+ const language lang);
+
extern frame_info_ptr find_relative_frame (frame_info_ptr, int *);
/* Wrapper over print_stack_frame modifying current_uiout with UIOUT for