Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Christina Schimpe <christina.schimpe@intel.com>
To: gdb-patches@sourceware.org
Cc: tom@tromey.com, thiago.bauermann@linaro.org
Subject: [PATCH v3 03/12] gdb: Add get_main_func_start_pc to refactor frame.c:inside_main_func.
Date: Mon,  6 Jul 2026 12:31:24 +0000	[thread overview]
Message-ID: <20260706123133.1990441-4-christina.schimpe@intel.com> (raw)
In-Reply-To: <20260706123133.1990441-1-christina.schimpe@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.
---
 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 cefdde5ed1e..a9f2675ce3a 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2641,27 +2641,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
@@ -2677,16 +2676,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 f6553fb7b6d..58732bceab4 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -887,6 +887,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.34.1

Intel Deutschland GmbH

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 89 991 430, www.intel.de
Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell
Chairperson of the Supervisory Board: Nicole Lau
Registered Seat: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


  parent reply	other threads:[~2026-07-06 12:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 12:31 [PATCH v3 00/12] Add new command to print the shadow stack backtrace Christina Schimpe
2026-07-06 12:31 ` [PATCH v3 01/12] gdb: Generalize handling of the shadow stack pointer Christina Schimpe
2026-07-06 12:31 ` [PATCH v3 02/12] aarch64: Implement gdbarch function top_addr_empty_shadow_stack Christina Schimpe
2026-07-06 12:31 ` Christina Schimpe [this message]
2026-07-06 12:31 ` [PATCH v3 04/12] gdb: Refactor 'stack.c:print_frame' Christina Schimpe
2026-07-06 12:31 ` [PATCH v3 05/12] gdb: Introduce 'stack.c:print_pc' function without frame argument Christina Schimpe
2026-07-06 12:31 ` [PATCH v3 06/12] gdb: Refactor 'find_symbol_funname' and 'info_frame_command_core' in stack.c Christina Schimpe
2026-07-06 12:31 ` [PATCH v3 07/12] gdb: Refactor 'stack.c:print_frame_info' Christina Schimpe
2026-07-06 12:31 ` [PATCH v3 08/12] gdb: Add command option 'bt -shadow' to print the shadow stack backtrace Christina Schimpe
2026-07-08  9:13   ` Schimpe, Christina
2026-07-06 12:31 ` [PATCH v3 09/12] gdb: Implement the hook 'is_no_return_shadow_stack_address' for amd64 linux Christina Schimpe
2026-07-06 12:31 ` [PATCH v3 10/12] gdb: Enable inferior calls in the shadow stack backtrace Christina Schimpe
2026-07-06 12:31 ` [PATCH v3 11/12] gdb: Enable signal trampolines " Christina Schimpe
2026-07-06 12:31 ` [PATCH v3 12/12] gdb, mi: Add -shadow-stack-list-frames command Christina Schimpe

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=20260706123133.1990441-4-christina.schimpe@intel.com \
    --to=christina.schimpe@intel.com \
    --cc=gdb-patches@sourceware.org \
    --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