Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Joos, Christina" <christina.joos@intel.com>
To: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	"tom@tromey.com" <tom@tromey.com>
Subject: RE: [PATCH v4 13/13] gdb, mi: Add -shadow-stack-list-frames command
Date: Tue, 22 Sep 2026 07:49:14 +0000	[thread overview]
Message-ID: <SN7PR11MB76387AA41E7CBA6A9D99808F89832@SN7PR11MB7638.namprd11.prod.outlook.com> (raw)
In-Reply-To: <87jyp2pxfi.fsf@linaro.org>

> -----Original Message-----
> From: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
> Sent: Donnerstag, 3. September 2026 10:11
> To: Joos, Christina <christina.joos@intel.com>
> Cc: gdb-patches@sourceware.org; tom@tromey.com
> Subject: Re: [PATCH v4 13/13] gdb, mi: Add -shadow-stack-list-frames
> command
> 
> Christina Schimpe <christina.schimpe@intel.com> writes:
> 
> > Add the mi command for the command "backtrace -shadow".
> > Similar to the mi interface for the ordinary backtrace command,
> > support low-frame and high-frame as command line parameters.
> >
> > Example print of a full shadow stack backtrace:
> > ~~~
> > (gdb)
> > -shadow-stack-list-frames
> > ^done,shadow-stack=[
> > shadow-stack-frame={level="0",addr="0x00007ffff7c3fe70",
> >   func="__libc_start_call_main",file="../sysdeps/nptl/libc_start_call_main.h",
> >   fullname="/usr/[...]/sysdeps/nptl/libc_start_call_main.h",
> >   line="58",arch="i386:x86-64"},
> > shadow-stack-frame={level="1",addr="0x00007ffff7c3ff20",
> >   func="__libc_start_main_impl",file="../csu/libc-start.c",
> >   fullname="/usr/[...]/csu/libc-start.c",
> >   line="128",arch="i386:x86-64"},
> > shadow-stack-frame={level="2",addr="0x0000000000401075",
> >   func="_start",arch="i386:x86-64"}]
> > ~~~
> >
> > Example print of a shadow stack backtrace using low- and high-frame:
> > ~~~
> > (gdb)
> > -shadow-stack-list-frames 0 1
> > ^done,shadow-stack=[
> > shadow-stack-frame={level="0",addr="0x00007ffff7c3fe70",
> >   func="__libc_start_call_main",file="../sysdeps/nptl/libc_start_call_main.h",
> >   fullname="/usr/[...]/sysdeps/nptl/libc_start_call_main.h",
> >   line="58",arch="i386:x86-64"},
> > shadow-stack-frame={level="1",addr="0x00007ffff7c3ff20",
> >   func="__libc_start_main_impl",file="../csu/libc-start.c",
> >   fullname="/usr/[...]/csu/libc-start.c",
> >   line="128",arch="i386:x86-64"}]
> > ~~~
> > ---
> >  gdb/NEWS                                      |   8 ++
> >  gdb/doc/gdb.texinfo                           |  51 ++++++++
> >  gdb/mi/mi-cmd-stack.c                         | 100 +++++++++++++++
> >  gdb/mi/mi-cmds.c                              |   2 +
> >  gdb/mi/mi-cmds.h                              |   1 +
> >  gdb/shadow-stack.c                            | 121 ++++++++++++------
> >  gdb/shadow-stack.h                            |  40 ++++++
> >  .../gdb.mi/mi-shadow-stack-signal.exp         |  69 ++++++++++
> >  gdb/testsuite/gdb.mi/mi-shadow-stack.exp      |  93 ++++++++++++++
> >  9 files changed, 449 insertions(+), 36 deletions(-)  create mode
> > 100644 gdb/testsuite/gdb.mi/mi-shadow-stack-signal.exp
> >  create mode 100644 gdb/testsuite/gdb.mi/mi-shadow-stack.exp
> 
> I don't have much experience with MI, so I'll only comment on the translation
> strings. Though to be honest in all this time AFAICT GDB hasn't ever been
> translated so I wonder how useful it is to pay attention to this.

I don't know how often or if that happens, too....
But since I use the interface, I should probably better use it correctly. 😉 

> > +/* Parse arguments of -shadow-stack-list-frames command and set
> FRAME_LOW
> > +   and FRAME_HIGH accordingly.  Throw an error in case the arguments are
> > +   invalid.  */
> > +static void
> > +mi_cmd_shadow_stack_list_frames_parse_args (const char *const *argv,
> > +					    int argc, int &frame_low,
> > +					    int &frame_high)
> > +{
> > +  const std::string mi_cmd_name = "-shadow-stack-list-frames";
> > +  /* There should either be low - high range, or no arguments.  */
> > +  if ((argc != 0) && (argc != 2))
> > +    error (_("%s: Usage: [FRAME_LOW FRAME_HIGH]"), mi_cmd_name.c_str
> > +());
> > +
> > +  /* If there is a range, set it.  */
> > +  if (argc == 2)
> > +    {
> > +      frame_low = atoi (argv[0]);
> > +      frame_high = atoi (argv[1]);
> > +      std::string err_str;
> > +      if (frame_low < 0)
> > +	{
> > +	  err_str = "``" + std::to_string (frame_low) + "''";
> > +	  if (frame_high < 0)
> > +	    err_str += " and ``" + std::to_string (frame_high) + "''";
> > +	}
> > +      else if (frame_high < 0)
> > +	err_str = "``" + std::to_string (frame_high) + "''";
> > +
> > +      if (!err_str.empty ())
> > +	{
> > +	  err_str = mi_cmd_name + ": Invalid option " + err_str + ".";
> > +	  error (_("%s"), err_str.c_str ());
> 
> Passing "%s" as a string to be translated doesn't work. gettext extracts the
> translatable strings by scanning the source code at build time, it's not done at
> runtime.
> 
> You can see this if you run this in the GDB build directory:
> 
> $ make -C gdb gdb.pot
> 
> Then you'll see in $build_dir/gdb/po/gdb.pot:
> 
> #: compile/compile.c:112 cp-namespace.c:528 dwarf2/read.c:1021
> #: dwarf2/read.c:1030 mi/mi-cmd-stack.c:802 shadow-stack.c:632
> #: shadow-stack.c:649 utils.c:657 read.c:1021 read.c:1030 mi-cmd-stack.c:802
> #: compile.c:112
> #, possible-c-format
> msgid "%s"
> msgstr ""
> 
> Which isn't very translatable. The only string containing "Invalid option" in
> gdb.pot is from mi-cmd-var.c, unrelated to this code.

Ah thanks a lot for pointing this out, I was not aware ! Will fix this.

I think there are some more occurrences in this series which I will double check.
There is one, for instance, in shadow-stack.c:

~~~
      error (_("Cannot print shadow stack backtrace: %s.\n"),
	     ssp_unwind_stop_reason_to_err_string (reason));
~~~

But in this case REASON is more like an error code, so I believe it doesn't have to
be translated.

> > +	}
> > +    }
> > +  else
> > +    {
> > +      /* No arguments, print the whole shadow stack backtrace.  */
> > +      frame_low = -1;
> > +      frame_high = -1;
> > +    }
> > +}
> 
> ⋮
> 
> > +CORE_ADDR
> > +get_validated_shadow_stack_pointer (gdbarch *gdbarch)
> >  {
> >    if (!target_has_stack ())
> > -    error (_("No shadow stack."));
> > +    {
> > +      if (!current_uiout->is_mi_like_p ())
> > +	error (_("No shadow stack."));
> > +      else
> > +	error (_("-shadow-stack-list-frames: No shadow stack."));
> > +    }
> >
> > -  gdbarch *gdbarch = get_current_arch ();
> >    if (!gdbarch_address_in_shadow_stack_memory_range_p (gdbarch)
> >        || !gdbarch_top_addr_empty_shadow_stack_p (gdbarch)
> >        || gdbarch_ssp_regnum (gdbarch) == -1)
> > -    error (_("Printing of the shadow stack backtrace is not supported for"
> > -	     " the current target."));
> > +    {
> > +      std::string err_str = "Printing of the shadow stack backtrace";
> > +      err_str += " is not supported for the current target.";
> > +      if (!current_uiout->is_mi_like_p ())
> > +	error (_("%s"), err_str.c_str());
> > +      else
> > +	error (_("-shadow-stack-list-frames: %s"), err_str.c_str());
> 
> Same problem in the two _() calls above, and the two below.

Yes, will fix.

> > +    }
> >
> >    regcache *regcache = get_thread_regcache (inferior_thread ());
> >    bool shadow_stack_enabled = false;
> > @@ -621,10 +642,25 @@ backtrace_shadow_command (const
> frame_print_options &fp_opts,
> >  					shadow_stack_enabled);
> >
> >    if (!start_ssp.has_value () || !shadow_stack_enabled)
> > -    error (_("Shadow stack is not enabled for the current thread."));
> > +    {
> > +      std::string err_str
> > +	= "Shadow stack is not enabled for the current thread.";
> > +      if (!current_uiout->is_mi_like_p ())
> > +	error (_("%s"), err_str.c_str());
> > +      else
> > +	error (_("-shadow-stack-list-frames: %s"), err_str.c_str());
> > +    }
> >
> > -  /* Check if START_SSP points to a shadow stack memory range and use
> > -     the returned range to determine when to stop unwinding.
> > +  return *start_ssp;
> > +}

Thanks!
Christina
________________________________________
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.

  reply	other threads:[~2026-09-22  7:51 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08 14:36 [PATCH v4 00/13] Add new command to print the shadow stack backtrace Christina Schimpe
2026-07-08 14:36 ` [PATCH v4 01/13] gdb: Generalize handling of the shadow stack pointer Christina Schimpe
2026-07-08 14:36 ` [PATCH v4 02/13] aarch64: Implement gdbarch function top_addr_empty_shadow_stack Christina Schimpe
2026-08-12 22:13   ` Luis
2026-08-25  9:01     ` Joos, Christina
2026-08-29  5:24       ` Thiago Jung Bauermann
2026-08-30 11:14         ` Joos, Christina
2026-09-03  6:49           ` Thiago Jung Bauermann
2026-09-12  6:02   ` Thiago Jung Bauermann
2026-09-21 19:50     ` Joos, Christina
2026-09-22  3:55       ` Thiago Jung Bauermann
2026-07-08 14:36 ` [PATCH v4 03/13] gdb: Add get_main_func_start_pc to refactor frame.c:inside_main_func Christina Schimpe
2026-09-03  6:53   ` Thiago Jung Bauermann
2026-07-08 14:36 ` [PATCH v4 04/13] gdb: Refactor 'stack.c:print_frame' Christina Schimpe
2026-07-08 14:36 ` [PATCH v4 05/13] gdb: Introduce 'stack.c:print_pc' function without frame argument Christina Schimpe
2026-07-08 14:36 ` [PATCH v4 06/13] gdb: Refactor 'find_symbol_funname' and 'info_frame_command_core' in stack.c Christina Schimpe
2026-07-08 14:36 ` [PATCH v4 07/13] gdb: Refactor 'stack.c:print_frame_info' Christina Schimpe
2026-07-08 14:36 ` [PATCH v4 08/13] gdb: Add command option 'bt -shadow' to print the shadow stack backtrace Christina Schimpe
2026-09-03  7:37   ` Thiago Jung Bauermann
2026-09-10 19:36     ` Joos, Christina
2026-09-12  5:52       ` Thiago Jung Bauermann
2026-07-08 14:36 ` [PATCH v4 09/13] gdb: Provide gdbarch hook to distinguish shadow stack backtrace elements Christina Schimpe
2026-09-03  7:44   ` Thiago Jung Bauermann
2026-07-08 14:36 ` [PATCH v4 10/13] gdb: Implement the hook 'is_no_return_shadow_stack_address' for amd64 linux Christina Schimpe
2026-09-03  7:49   ` Thiago Jung Bauermann
2026-09-21 19:49     ` Joos, Christina
2026-09-22  3:46       ` Thiago Jung Bauermann
2026-09-22 10:04         ` Joos, Christina
2026-07-08 14:36 ` [PATCH v4 11/13] gdb: Enable inferior calls in the shadow stack backtrace Christina Schimpe
2026-09-03  7:51   ` Thiago Jung Bauermann
2026-07-08 14:36 ` [PATCH v4 12/13] gdb: Enable signal trampolines " Christina Schimpe
2026-09-03  7:53   ` Thiago Jung Bauermann
2026-07-08 14:36 ` [PATCH v4 13/13] gdb, mi: Add -shadow-stack-list-frames command Christina Schimpe
2026-09-03  8:10   ` Thiago Jung Bauermann
2026-09-22  7:49     ` Joos, Christina [this message]
2026-08-04  7:45 ` RE:[PATCH v4 00/13] Add new command to print the shadow stack backtrace Joos, Christina
2026-09-03  6:44 ` [PATCH " Thiago Jung Bauermann
2026-09-10 19:42   ` Joos, Christina

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=SN7PR11MB76387AA41E7CBA6A9D99808F89832@SN7PR11MB7638.namprd11.prod.outlook.com \
    --to=christina.joos@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