Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Christina Joos <christina.joos@intel.com>
To: gdb-patches@sourceware.org
Cc: thiago.bauermann@linaro.org, tom@tromey.com, luis.machado.foss@gmail.com
Subject: [PATCH v5 03/13] gdb: Add get_main_func_start_pc to refactor frame.c:inside_main_func.
Date: Thu, 24 Sep 2026 10:33:00 +0200	[thread overview]
Message-ID: <20260924083311.1961530-4-christina.joos@intel.com> (raw)
In-Reply-To: <20260924083311.1961530-1-christina.joos@intel.com>

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(-)

diff --git a/gdb/frame.c b/gdb/frame.c
index 6b02c5f559a..6bf72b6908e 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -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.  */
diff --git a/gdb/frame.h b/gdb/frame.h
index b64650f3215..6f6259cf722 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -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
-- 
2.53.0

________________________________________
Intel Deutschland GmbH 

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany 

Tel: +49 (89) 99143-0 

www.intel.de 

Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman

Chairperson of the Supervisory Board: Sonja Pierer

Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


  parent reply	other threads:[~2026-09-24  8:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24  8:32 [PATCH v5 00/13] Add new command to print the shadow stack backtrace Christina Joos
2026-09-24  8:32 ` [PATCH v5 01/13] gdb: Generalize handling of the shadow stack pointer Christina Joos
2026-09-24 21:03   ` Thiago Jung Bauermann
2026-09-24  8:32 ` [PATCH v5 02/13] aarch64: Implement gdbarch function top_addr_empty_shadow_stack Christina Joos
2026-09-24 21:04   ` Thiago Jung Bauermann
2026-09-24  8:33 ` Christina Joos [this message]
2026-09-24  8:33 ` [PATCH v5 04/13] gdb: Refactor 'stack.c:print_frame' Christina Joos
2026-09-24  8:33 ` [PATCH v5 05/13] gdb: Introduce 'stack.c:print_pc' function without frame argument Christina Joos
2026-09-24  8:33 ` [PATCH v5 06/13] gdb: Refactor 'find_symbol_funname' and 'info_frame_command_core' in stack.c Christina Joos
2026-09-24  8:33 ` [PATCH v5 07/13] gdb: Refactor 'stack.c:print_frame_info' Christina Joos
2026-09-24  8:33 ` [PATCH v5 08/13] gdb: Add command option 'bt -shadow' to print the shadow stack backtrace Christina Joos
2026-09-24  9:37   ` Eli Zaretskii
2026-09-24  8:33 ` [PATCH v5 09/13] gdb: Provide gdbarch hook to distinguish shadow stack backtrace elements Christina Joos
2026-09-24  9:29   ` Eli Zaretskii
2026-09-24 13:10     ` Joos, Christina
2026-09-24  8:33 ` [PATCH v5 10/13] gdb: Implement the hook 'is_no_return_shadow_stack_address' for amd64 linux Christina Joos
2026-09-24  8:33 ` [PATCH v5 11/13] gdb: Enable inferior calls in the shadow stack backtrace Christina Joos
2026-09-24  8:33 ` [PATCH v5 12/13] gdb: Enable signal trampolines " Christina Joos
2026-09-24  8:33 ` [PATCH v5 13/13] gdb, mi: Add -shadow-stack-list-frames command Christina Joos
2026-09-24  9:39   ` Eli Zaretskii

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=20260924083311.1961530-4-christina.joos@intel.com \
    --to=christina.joos@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado.foss@gmail.com \
    --cc=thiago.bauermann@linaro.org \
    --cc=tom@tromey.com \
    /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