From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id deGWIqErmWrESCMAWB0awg (envelope-from ) for ; Thu, 03 Sep 2026 04:11:13 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=P/aVsFcR; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 7286F1E166; Thu, 03 Sep 2026 04:11:13 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 124DA1E09B for ; Thu, 03 Sep 2026 04:11:12 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 61B374BAE7E5 for ; Thu, 3 Sep 2026 08:11:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61B374BAE7E5 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=P/aVsFcR Received: from mail-yw1-x1130.google.com (mail-yw1-x1130.google.com [IPv6:2607:f8b0:4864:20::1130]) by sourceware.org (Postfix) with ESMTPS id 716394BA902F for ; Thu, 3 Sep 2026 08:10:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 716394BA902F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 716394BA902F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788423045; cv=none; b=jAiGhH53woHqPwph3ONo65IhSeCYMgUdimln3Qcmp7HUsk+9jAHCSYV2aVNvdwmCfL+TcgevqkUYQteV7Lu3oSbchofoyB91D+kOn5pqM2haxfywWShkygdPZNphFUK6H3ziG3k/Jpikf4e3Hd24ZZKbvnWVcFTFL7cpqqu/aYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788423045; c=relaxed/simple; bh=R3dHdtkd9pObWTsqTzUtoL8JQgqAma0K2bKOsPD0Ees=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xKjLnw4vl/VyFFXOJ2aBiM8asVXaNphRXvbQSFkfjMsP5+Xye1TfubwtbvtJ6lOkF7zCb2BLCuxfbrge/CKUBI2eHLE1S/KiTn58kjre+mbRlgecw+5UkJ2sfnzlXpJnAMj+HntW36O3hZFYV/PRQ9dr8vbKy+oq0i06ih2nJg0= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=P/aVsFcR DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 716394BA902F Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-855c26cf490so18785267b3.0 for ; Thu, 03 Sep 2026 01:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1788423045; x=1789027845; darn=sourceware.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :user-agent:references:in-reply-to:subject:cc:to:from:from:to:cc :subject:date:message-id:reply-to:content-type; bh=fCkwZFfR6r7wG914v5xmXK+wOSNjZZZF/6W6fpBZe/Y=; b=P/aVsFcRNtJrtqxH//MHYEGe63ai9FtVaQxrs0RIVYmekBe/bs4GfiIWqLa+ra9DZn R+Cg8D7xeBZ3Pu/irIZLGZE16vEfm9UPtIYvz5wm7QKEsEsVkjKDfK9ZhxbUI1aCcVAZ JJ006kr942m1jrduMlNuXuzfapv4dYJyKpPotm2AeSjilxZZAoiPp8vU4w0gQTxpg4iQ Ks/MmpopEfOmIz0n0V5bC154TFN7a5A8X8b2QE1Z6vuetCAX3xGL7A5A+A5SINRrMJJM DtD0DKhNgpwwoO36PjbmbjYSGbVyFiKOflPh9ENn5pgfC1+K4DZJQJC1ZTMUdVeTFvzI jNMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788423045; x=1789027845; h=content-transfer-encoding:content-type:mime-version:message-id:date :user-agent:references:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=fCkwZFfR6r7wG914v5xmXK+wOSNjZZZF/6W6fpBZe/Y=; b=IMS4Y/3zWRTbMYvOl3KtSojIor2FJLcYQMz0jp5RhfPgYqtoItsciktc1dSUtZPxiy +ob1lccC8jML5RAQcYiLCzg9Atwgk+64tLx3QisWnHiSa+hd5dNL4e8YT94ds/MBp1fs WyvWAxnEZY8hZJ01pZn4oS4XB1dqHrE7i92l8SFVSHEHUbXeaiPVqW2HjFFbA+Kl2XBz WX83XHdlstobddyPXap2/jJVas04R0cbWn68TCzWNDsqpL+o0ZriXD1d8nd3VR1BGNyu Z5739/j3/CIxdrffDD7fQEf/FsCzaShtOLQ/znO06rVfB68qQe8zP01dqdl2ffaYFZbB jBNw== X-Gm-Message-State: AFuF++nxO1x0PLGV2uNuIFNwpjEgAFasxHrgq5w41VcRH+kVYhgu3p47 9uoaP/9K3bC4OMFZOrC8wytMZV55dvKBNJdfE0dmvrrglB+GY1OZCSWIXujQQmCTbYekB6TxXqM OjNWQ X-Gm-Gg: AYBFou2gSBg7/s84AUr37UY5Nan7ZfV6sgf4R9TLwCz8WCJV+WETicClHVcVktCPHCb jvOZZSUV8DDnjn7XESP+irLA2wkFNqnNRjcyWn/d1DVlO2HkflO808kBQdIrbgBrNSYkqgzEfvr jYjVAEhN2X6lJxBW5VHwwZk8/40qM4bQncyPZoxau/Vy3Wgb/+c/FYpf+bzYH7sdCypRp5+JRPN E7RY38GlJ3gagYs6qc9AnNvAZhI9ON9bBu4OqUqvdrlsZI/e2g/ObKtrW3AYyzE6FXSUCZTJ28k gUMbZ/StjZ6aatFQTSMNF3vRIvxAuH6J/DRSnmRT++5riy2GwE8R9rYnPQ8Bcy0znDnuqftRiBD v8/eR4Zp5+ghPyh+6yOtta8rQkOXJTsLdO9hVowt8pF2LCXy9t/m4HfrISxFqhwJNfMkX8o0bzR j8WfCLq/RDdDoLdzVvmeEEmsXMVXCNyWmSdT8Xg0quVYNEr9A64oECr+n0Pmj8LXnGWVKZU6w= X-Received: by 2002:a05:690c:6e85:b0:870:2898:fd68 with SMTP id 00721157ae682-8702898ffacmr1649677b3.30.1788423044486; Thu, 03 Sep 2026 01:10:44 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8083:f04c:42e3:5943:38f6]) by smtp.gmail.com with ESMTPSA id 00721157ae682-86c184e4b6csm34684157b3.33.2026.09.03.01.10.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 01:10:44 -0700 (PDT) From: Thiago Jung Bauermann To: Christina Schimpe Cc: gdb-patches@sourceware.org, tom@tromey.com Subject: Re: [PATCH v4 13/13] gdb, mi: Add -shadow-stack-list-frames command In-Reply-To: <20260708143639.2214689-14-christina.schimpe@intel.com> (Christina Schimpe's message of "Wed, 8 Jul 2026 14:36:39 +0000") References: <20260708143639.2214689-1-christina.schimpe@intel.com> <20260708143639.2214689-14-christina.schimpe@intel.com> User-Agent: mu4e 1.14.3; emacs 30.2 Date: Thu, 03 Sep 2026 08:10:41 +0000 Message-ID: <87jyp2pxfi.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Christina Schimpe 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=3D[ > shadow-stack-frame=3D{level=3D"0",addr=3D"0x00007ffff7c3fe70", > func=3D"__libc_start_call_main",file=3D"../sysdeps/nptl/libc_start_call= _main.h", > fullname=3D"/usr/[...]/sysdeps/nptl/libc_start_call_main.h", > line=3D"58",arch=3D"i386:x86-64"}, > shadow-stack-frame=3D{level=3D"1",addr=3D"0x00007ffff7c3ff20", > func=3D"__libc_start_main_impl",file=3D"../csu/libc-start.c", > fullname=3D"/usr/[...]/csu/libc-start.c", > line=3D"128",arch=3D"i386:x86-64"}, > shadow-stack-frame=3D{level=3D"2",addr=3D"0x0000000000401075", > func=3D"_start",arch=3D"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=3D[ > shadow-stack-frame=3D{level=3D"0",addr=3D"0x00007ffff7c3fe70", > func=3D"__libc_start_call_main",file=3D"../sysdeps/nptl/libc_start_call= _main.h", > fullname=3D"/usr/[...]/sysdeps/nptl/libc_start_call_main.h", > line=3D"58",arch=3D"i386:x86-64"}, > shadow-stack-frame=3D{level=3D"1",addr=3D"0x00007ffff7c3ff20", > func=3D"__libc_start_main_impl",file=3D"../csu/libc-start.c", > fullname=3D"/usr/[...]/csu/libc-start.c", > line=3D"128",arch=3D"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. > +/* 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 =3D "-shadow-stack-list-frames"; > + /* There should either be low - high range, or no arguments. */ > + if ((argc !=3D 0) && (argc !=3D 2)) > + error (_("%s: Usage: [FRAME_LOW FRAME_HIGH]"), mi_cmd_name.c_str ()); > + > + /* If there is a range, set it. */ > + if (argc =3D=3D 2) > + { > + frame_low =3D atoi (argv[0]); > + frame_high =3D atoi (argv[1]); > + std::string err_str; > + if (frame_low < 0) > + { > + err_str =3D "``" + std::to_string (frame_low) + "''"; > + if (frame_high < 0) > + err_str +=3D " and ``" + std::to_string (frame_high) + "''"; > + } > + else if (frame_high < 0) > + err_str =3D "``" + std::to_string (frame_high) + "''"; > + > + if (!err_str.empty ()) > + { > + err_str =3D 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=20 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. > + } > + } > + else > + { > + /* No arguments, print the whole shadow stack backtrace. */ > + frame_low =3D -1; > + frame_high =3D -1; > + } > +} =E2=8B=AE > +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.")); > + } >=20=20 > - gdbarch *gdbarch =3D 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) =3D=3D -1) > - error (_("Printing of the shadow stack backtrace is not supported fo= r" > - " the current target.")); > + { > + std::string err_str =3D "Printing of the shadow stack backtrace"; > + err_str +=3D " 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. > + } >=20=20 > regcache *regcache =3D get_thread_regcache (inferior_thread ()); > bool shadow_stack_enabled =3D false; > @@ -621,10 +642,25 @@ backtrace_shadow_command (const frame_print_options= &fp_opts, > shadow_stack_enabled); >=20=20 > if (!start_ssp.has_value () || !shadow_stack_enabled) > - error (_("Shadow stack is not enabled for the current thread.")); > + { > + std::string err_str > + =3D "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()); > + } >=20=20 > - /* 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; > +} --=20 Thiago (he/him)