Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Schimpe, Christina" <christina.schimpe@intel.com>
To: "thiago.bauermann@linaro.org" <thiago.bauermann@linaro.org>,
	Tom Tromey <tom@tromey.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH v2 0/9] Add new command to print the shadow stack backtrace
Date: Mon, 18 May 2026 08:39:34 +0000	[thread overview]
Message-ID: <SN7PR11MB763810682445985224C69D63F9032@SN7PR11MB7638.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20260123080532.878738-1-christina.schimpe@intel.com>

Hi Tom and Thiago, 

First, thanks a lot for your review efforts on this series so far!
As indicated in the cover letter of v2, I would like to post v3, including the -past-main option.

Enabling this made me realize that I need some refactoring of the commits:
- "gdb: Add command option 'bt -shadow' to print the shadow stack backtrace."
- "gdb: Provide gdbarch hook to distinguish shadow stack backtrace elements."

I have mixed feelings about this. On the one hand, the patches have already been very well
reviewed (thanks again!) and the refactoring means that new review effort is required. But
on the other hand, I think these changes improve the series overall. Below, I briefly describe
the main changes to those commits. If this approach makes sense to you, I will post v3
shortly after.

To avoid increasing your review effort, I also considered adding these changes as new
patches on top. However, it is probably cleaner to merge them into the existing commits.
Another option is that I post the V3 including fixups on top (and merge in a v4) to make
the review easier for you. Or, we could also consider merging the series (once fully approved)
without -past-main and I could submit a follow-up series for that feature. If you have any
preference, I'm happy about your feedback.

My main changes to enable -past-main are:

1) A new commit (required before "gdb: Add command option 'bt -shadow' to print the shadow stack backtrace."): 

    gdb: Add get_main_func_start_pc to refactor frame.c:inside_main_func.

    Refactor frame.c:inside_main_func to use the new function
    get_main_func_start_pc, which will be used in a following commit.

2) Refactoring of "gdb: Add command option 'bt -shadow' to print the shadow stack backtrace." :

    To enable the -past-main option in the shadow stack backtrace the function
    get_main_func_start_pc (gdbarch* gdbarch, const language lang) is called by a
    new function shadow_stack_frame_info::inside_main_func.  This probably requires
    a frame specific gdbarch and language in the struct shadow_stack_frame_info.
    I am not sure the gdbarch or language ever changes for IA, but it might be a good
    idea to add it to be safe. So, due to that we need some refactoring of the shadow
    stack backtrace implementation:
    a. The frame specific arch is extracted based on the symtab_and_line (SAL)
       object.  To avoid that we extract the SAL and gdbarch multiple times for
       the same frame we store it in the shadow stack frame.
    b. The gdbarch hook get_shadow_stack_size is obsolete since the function
       get_trailing_outermost_shadow_stack_frame_info now unwinds each frame.  This
       helps to configure the previous frame attributes in case the gdbarch or SAL
       information cannot be extracted for special shadow stack elements.  We don't need
       the COUNT parameter anymore in the function update_shadow_stack_pointer, too.
       Now, this is also inline with the function trailing_outermost_frame which is used
       for the normal backtrace.
    c. Introduce function get_shadow_stack_frame_info to share some more logic:
    ~~~
    /* If possible, get shadow stack frame info for the shadow stack pointer
       SSP and its current frame LEVEL.  Pass a fallback gdbarch FALLBACK_ARCH
       which can be used as fallback in case the gdbarch cannot be extracted
       from the SAL.  Usually this is the gdbarch of the previous frame.  */

    static std::optional<shadow_stack_frame_info>
    get_shadow_stack_frame_info
      (gdbarch *fallback_arch, const CORE_ADDR ssp, ULONGEST level)
    ~~~

3) Refactoring of "gdb: Provide gdbarch hook to distinguish shadow stack backtrace elements.

    a. Like normal frames used in the ordinary backtrace command, introduce an enum
       ssp_frame_type (normal_frame, non_return_frame) which classifies each frame and is
       an attribute of the shadow stack frame info.  Calling of inside_main_func () to check
       if we should stop unwinding is only done for normal frames.  For the currently known
       cases of non-return-address shadow stack elements, the value is not a PC of the program
       and the past-main check is not applicable.
       More frame types will be added in the following patches to enable sigtramp and inferior
       call frames.
    b. The gdbarch hook is_no_return_shadow_stack_address now returns the complete shadow stack
       frame (classified as non_return_frame) in case the element on the shadow stack is not a return
       address (instead of the optional return address description string used before). The target can
       then assign the correct gdbarch and an optional SAL object. Due to that hook is no longer called 
       when printing the frame, but already when constructing it in get_shadow_stack_frame_info and
       we don't pass the shadow stack frame as argument anymore, but the shadow stack pointer, its
       value and level.

       The new interface looks as follows:
    ~~~
    Method(
        comment="""
    There can be elements on the shadow stack which are not return addresses.
    This happens for example on x86 with CET in case of signals.
    If an architecture implements the command options 'backtrace -shadow' and
    the shadow stack can contain elements which are not return addresses, this
    function has to be provided.
    Return a shadow stack frame info with frame type
    ssp_frame_type::non_return_frame, if the shadow stack pointer SSP belongs
    to a valid shadow stack frame while the element on the shadow stack
    VALUE does not refer to a return address.  In that case, also the frame's
    attribute non_return_description must be set to a string which is displayed
    instead of the element on the shadow stack in the shadow stack backtrace.
    Otherwise, return an empty optional.
    """,
        type="std::optional<shadow_stack_frame_info>",
        name="is_no_return_shadow_stack_address",
        params=[
          ("const CORE_ADDR", "ssp"),
          ("const CORE_ADDR", "value"),
          ("const unsigned long", "level")
        ],
        predicate=True,
    )
    ~~~
    c. The shadow stack frame contains a new string attribute "non_return_description"
        which is printed instead of the element on the shadow stack in case the frame is
        classified as non-return address frame.  It is empty in case the frame is not a
       " ssp_frame_type::non_return_frame" frame.  We could also use an optional here,
       I am not sure what is preferred.

This is now the class for a shadow stack frame:

/* Information of a shadow stack frame belonging to a shadow stack element
   at shadow stack pointer SSP.  */

class shadow_stack_frame_info
{
public:
  /* If possible, unwind the previous shadow stack frame info.  RANGE is
     the shadow stack memory range [start_address, end_address) belonging
     to this frame's shadow stack pointer.  If we cannot unwind the
     previous frame info, set the unwind_stop_reason attribute.  If we
     reached the bottom of the shadow stack just don't return a value.  */
  std::optional<shadow_stack_frame_info> unwind_prev_shadow_stack_frame_info
    (std::pair<CORE_ADDR, CORE_ADDR> range);

  /* The shadow stack pointer.  */
  CORE_ADDR ssp;

  /* The value of the shadow stack at SSP.  */
  CORE_ADDR value;

  /* The level of the element on the shadow stack.  */
  unsigned long level;

  /* Architecture of the current shadow stack frame.  */
  struct gdbarch *arch;

  /* Optional SAL object of the current shadow stack frame.  */
  std::optional<symtab_and_line> sal;

  /* The shadow stack frame type.  */
  ssp_frame_type type;

  /* If this is not a normal shadow stack frame belonging to a return
     address of the program execution flow then the frame will have the
     type ssp_frame_type::non_return_frame.  In this case, this string
     is configured to describe this specific frame type and it will
     be printed in the shadow stack backtrace instead of the element on
     the shadow stack.  */
  std::string non_return_description;

  /* If unwinding of the previous frame info fails assign this value to a
     matching condition ssp_unwind_stop_reason
     > ssp_unwind_stop_reason::no_error.  */
  ssp_unwind_stop_reason unwind_stop_reason
    = ssp_unwind_stop_reason::no_error;

  /* Return true if this frame is inside the "main"() function.  If the frame
     is outside the "main"() function, does not have a SAL object or if the
     symbol information cannot be extracted, return false.  */
  bool inside_main_func () const;
};

I am looking forward to your feedback!

Kind Regards,
Christina
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-05-18  8:40 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-23  8:05 Christina Schimpe
2026-01-23  8:05 ` [PATCH v2 1/9] gdb: Generalize handling of the shadow stack pointer Christina Schimpe
2026-02-19 17:55   ` Tom Tromey
2026-02-27 18:09     ` Schimpe, Christina
2026-02-27 18:26       ` Tom Tromey
2026-03-02 11:53         ` Schimpe, Christina
2026-04-09  9:49           ` Schimpe, Christina
2026-04-14 17:34             ` Tom Tromey
2026-04-15  7:35               ` Schimpe, Christina
2026-04-15 15:54                 ` Tom Tromey
2026-02-27 22:54       ` Thiago Jung Bauermann
2026-03-06  3:15   ` Thiago Jung Bauermann
2026-03-06  3:57     ` Thiago Jung Bauermann
2026-04-09 11:57       ` Schimpe, Christina
2026-04-10  5:03         ` Thiago Jung Bauermann
2026-04-10  7:53           ` Schimpe, Christina
2026-04-09 12:06   ` Schimpe, Christina
2026-04-10  5:05     ` Thiago Jung Bauermann
2026-01-23  8:05 ` [PATCH v2 2/9] gdb: Refactor 'stack.c:print_frame' Christina Schimpe
2026-01-23  8:05 ` [PATCH v2 3/9] gdb: Introduce 'stack.c:print_pc' function without frame argument Christina Schimpe
2026-01-23  8:05 ` [PATCH v2 4/9] gdb: Refactor 'find_symbol_funname' and 'info_frame_command_core' in stack.c Christina Schimpe
2026-02-19 17:32   ` Tom Tromey
2026-04-09 12:40     ` Schimpe, Christina
2026-01-23  8:05 ` [PATCH v2 5/9] gdb: Refactor 'stack.c:print_frame_info' Christina Schimpe
2026-01-23  8:05 ` [PATCH v2 6/9] gdb: Add command option 'bt -shadow' to print the shadow stack backtrace Christina Schimpe
2026-01-23  8:52   ` Eli Zaretskii
2026-02-13 16:42     ` Schimpe, Christina
2026-04-14  8:43       ` Schimpe, Christina
2026-04-14 11:53         ` Eli Zaretskii
2026-04-14 13:28           ` Schimpe, Christina
2026-04-14 14:12             ` Eli Zaretskii
2026-04-14 15:05               ` Schimpe, Christina
2026-02-19 18:19   ` Tom Tromey
2026-04-09 16:48     ` Schimpe, Christina
2026-03-06  4:31   ` Thiago Jung Bauermann
2026-03-06  9:39     ` Schimpe, Christina
2026-04-09 15:12     ` Schimpe, Christina
2026-04-10  6:21       ` Thiago Jung Bauermann
2026-04-10 12:12         ` Schimpe, Christina
2026-05-12  3:32   ` Thiago Jung Bauermann
2026-05-18 10:06     ` Schimpe, Christina
2026-01-23  8:05 ` [PATCH v2 7/9] gdb: Provide gdbarch hook to distinguish shadow stack backtrace elements Christina Schimpe
2026-01-23  8:47   ` Eli Zaretskii
2026-02-19 17:41   ` Tom Tromey
2026-05-12  3:49   ` Thiago Jung Bauermann
2026-05-18 10:11     ` Schimpe, Christina
2026-01-23  8:05 ` [PATCH v2 8/9] gdb: Implement the hook 'is_no_return_shadow_stack_address' for amd64 linux Christina Schimpe
2026-02-19 17:43   ` Tom Tromey
2026-05-12  3:58   ` Thiago Jung Bauermann
2026-05-18 10:13     ` Schimpe, Christina
2026-01-23  8:05 ` [PATCH v2 9/9] gdb, mi: Add -shadow-stack-list-frames command Christina Schimpe
2026-01-23  8:46   ` Eli Zaretskii
2026-02-13 19:17     ` Schimpe, Christina
2026-02-19 18:26   ` Tom Tromey
2026-04-22 19:25     ` Schimpe, Christina
2026-03-02 12:39 ` [PATCH v2 0/9] Add new command to print the shadow stack backtrace Schimpe, Christina
2026-05-07  4:14 ` Thiago Jung Bauermann
2026-05-07  5:09   ` Thiago Jung Bauermann
2026-05-18 10:08     ` Schimpe, Christina
2026-05-18 10:10   ` Schimpe, Christina
2026-05-21  2:57     ` Thiago Jung Bauermann
2026-05-18  8:39 ` Schimpe, Christina [this message]
2026-05-21  2:23   ` Thiago Jung Bauermann

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=SN7PR11MB763810682445985224C69D63F9032@SN7PR11MB7638.namprd11.prod.outlook.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