From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Ek+mOeIjmWpiHSMAWB0awg (envelope-from ) for ; Thu, 03 Sep 2026 03:38:10 -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=QA1KJyyj; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CB5061E166; Thu, 03 Sep 2026 03:38:10 -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 [38.145.34.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 D045D1E09B for ; Thu, 03 Sep 2026 03:38:09 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 469374BA9028 for ; Thu, 3 Sep 2026 07:38:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 469374BA9028 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=QA1KJyyj Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by sourceware.org (Postfix) with ESMTPS id D25E34BA2E16 for ; Thu, 3 Sep 2026 07:37:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D25E34BA2E16 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 D25E34BA2E16 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788421064; cv=none; b=b71CGMFx9fIEQYdXwLj2zR54q4lpv30UtBxKMFF+XwHf9nxyPTywrW7axpgd9tFbgJVTHU6i7Zk2I0Gy7f17NrvMHqabfRq8ab9sDgT1VxvtoqF5GPysTsEF1Qo5x89jius0NMQV53z3SUhluj78KmjDBHj4JMJRFt0r1aNWqpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788421064; c=relaxed/simple; bh=uLFnEBpfCU+w9fPeDCsKL+rXywKgch6/jixSZABZzPs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=lz7KsCXZh2Th9CWzUecM/37cMuy0vjcP8kzCaeBnjnMMjZRqSwQuEwi7diGCoxsNQpSYG04ocBULgfMcaNoJFGDV3mU979gsgzgRE6NVSsjjQRcY2EnssGFZld/eSPFw+3qZGyyGuK88Y/Lmboz4h0u47XeKDF37QaAEWUJISCk= 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=QA1KJyyj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D25E34BA2E16 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-86d43cdee51so17991307b3.2 for ; Thu, 03 Sep 2026 00:37:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1788421063; x=1789025863; darn=sourceware.org; h=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=4D05xqlx8OxNhrRmTQYy+VK0O9faMimY+LfvzV1H8CQ=; b=QA1KJyyjEQwRlmDhcvAw2pypzcFX/9rB3oI9McdOJTFjvJVCPFPidPXAAHaZ+k8Ybr xJwIYKR5baWFcWT8pExP81YY9zUR+cJpEGDMYULJZro6iCz0HroCgmy8w0xdpe6r1xE2 D0RLj6fVEwzYGO70HplwMsUqjnMXbWM4XeOIVKr8kShzeqWmoweTu2u0CiwcmX6vYMK2 yJuQRDuhWeAwnIZjbfxM3wmHYBb6J+lr4BwFqfkSvAZt2rJgBYgnLnmobuaHmGU163zR ewT7bPAq+iz7JjLaG4ng0GCD+AlfapH3bmWQSitbRNXzcjbWgInzUxTI/rT+hLcUflNA dXcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788421063; x=1789025863; h=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=4D05xqlx8OxNhrRmTQYy+VK0O9faMimY+LfvzV1H8CQ=; b=deWwY61GZNQRArWtqRW3t9jl8GLDGh748RvmJO9JaUplaSSl0IPsHQy8su0Tt7igDL bQ9Nz7Jt3SciTWhR1wqfA++A7wad9P3jKA6eduyxX0lAo8/RD4cM1UAaE3iPNbCgUKFJ 6J03uGs17mkk/At/E+hxBJUcc5myB9BgEflN3KQyTRnXLjP5upFs3PFiWS3Hb7JePrvP tg8HSKsWy9VoT9WOBXNobWNdZEVEA4ucUS0nR2pq3JZ1VtkJNJKofUfgvLNPkGts62mV HW7VsCEY8GrD4UhZjv3wvHoOFPQqHlc6L4QGvo+wwU1Wbc+DTbDzKI2DIaGH4PBv/62K soMg== X-Gm-Message-State: AFuF++lEIws2W5Mfrhbq5l/GmakoEd/VmlSg/Pox5348RWip9BAg62rO j/FFPk/L5zGUyG0x3JVPyX+FoCZyt8qcj+3El33sqRkq3/doq3GcrL3V6mXXSnx6m8YEhXHNu/x UkJit X-Gm-Gg: AYBFou27ei4UH5zcDBUBK2XITyQJoV9CtqLg03anehglzDdbPz2g7EAAOE5kKLJmTNd a5be2doDVnCGxII3CHtQEYRLjfUkDypuazfYC63KsoolRPDjiVBUs/6k6zanyscsJuOWsLQU1P5 +6ncMWDlUoSb4VIukqHcJp+gBMmDCAa5p1BLSu7CIpwz4QPtVUVMrJDVO2IDCQXgbG99YTdSsjt jjwVt80etrBOhTxccKSkhvvzx5a6aO4FBseqNZGo9sluAhcjxIafZYqUiGOtKPgKTo8fo47ozZR M1dnm9fPEdgBI69qW0kDXNh2iC2AHRsp5I1gAl1V7FxruACJgd8ihzJKWWddr+7W8JWv8WGxhqb e5ae/c51SdUak7LgeB97Den3zC8MrsoZDLdCjyD/rtmFBqUqsAfIIymTaa/+AShUvfYW4FbLup5 ei0oWJuRro9LMhz1bLxWk/HyMvXC0YWMB2s4M1Wwn94q919xlqfcwtGE/jMAiWzMb2xHrAnJydE v6UR7RydA== X-Received: by 2002:a05:690c:a5d6:b0:833:f9bd:b289 with SMTP id 00721157ae682-86c552e5e02mr46614717b3.31.1788421063037; Thu, 03 Sep 2026 00:37:43 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8083:f04c:42e3:5943:38f6]) by smtp.gmail.com with ESMTPSA id 00721157ae682-86c1975de9bsm34206137b3.48.2026.09.03.00.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 00:37:42 -0700 (PDT) From: Thiago Jung Bauermann To: Christina Schimpe Cc: gdb-patches@sourceware.org, tom@tromey.com Subject: Re: [PATCH v4 08/13] gdb: Add command option 'bt -shadow' to print the shadow stack backtrace. In-Reply-To: <20260708143639.2214689-9-christina.schimpe@intel.com> (Christina Schimpe's message of "Wed, 8 Jul 2026 14:36:34 +0000") References: <20260708143639.2214689-1-christina.schimpe@intel.com> <20260708143639.2214689-9-christina.schimpe@intel.com> User-Agent: mu4e 1.14.3; emacs 30.2 Date: Thu, 03 Sep 2026 07:37:40 +0000 Message-ID: <878q5iss3f.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain 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 command option '-shadow" to the backtrace command to print the shadow > stack backtrace instead of the normal backtrace. > > This option may be combined with '-frame-info' and implies '-no-filters' > and '-frame-arguments none'. Also the options @samp{-past-entry} or > @samp{-hide} are not supported. > > This is an example for the output of 'bt -shadow' on amd64 linux: > ~~ > (gdb) bt -shadow > /#0 0x000055555555514a in call1 at amd64-shadow-stack.c:27 > /#1 0x000055555555515f in main at amd64-shadow-stack.c:38 > ~~ > > Note that the normal backtrace includes one additional frame, since > the shadow stack backtrace relies on return addresses of the shadow > stack only. But except the missing frame arguments and frame #0 of > the normal backtrace, the backtrace is the same. > ~~ > (gdb) bt > /#0 call2 () at amd64-shadow-stack.c:21 > /#1 0x000055555555514a in call1 () at amd64-shadow-stack.c:27 > /#2 0x000055555555515f in main () at amd64-shadow-stack.c:38 > ~~ > > This commit also adds a test for 'bt -shadow' on amd64. > Although the test is OS independent we can only test this on linux, > as GDB does not support shadow stack on other OS for now. > Also we do not add a test for 32 bit, as support for shadow stack is > limited to 64 bit by the linux kernel. > --- > gdb/NEWS | 3 + > gdb/doc/gdb.texinfo | 25 + > gdb/gdbarch-gen.h | 2 + > gdb/gdbarch.h | 1 + > gdb/gdbarch_components.py | 2 + > gdb/shadow-stack.c | 475 ++++++++++++++++++ > gdb/shadow-stack.h | 65 +++ > gdb/stack.c | 49 +- > gdb/stack.h | 43 ++ > .../gdb.arch/amd64-shadow-stack-cmds.exp | 47 ++ > gdb/testsuite/gdb.base/options.exp | 2 +- > 11 files changed, 689 insertions(+), 25 deletions(-) Just one comment. In any case: Reviewed-by: Thiago Jung Bauermann > +/* If possible, get shadow stack frame info for the shadow stack pointer > + SSP and its current frame LEVEL. Pass FALLBACK_ARCH which can be used > + as fallback gdbarch in case the gdbarch cannot be extracted from the > + SAL. Usually this is the gdbarch of the previous frame. */ > + > +static std::optional > +get_shadow_stack_frame_info > + (gdbarch *fallback_arch, const CORE_ADDR ssp, unsigned long level) > +{ > + CORE_ADDR value; > + if (!read_shadow_stack_memory (fallback_arch, ssp, value)) > + return {}; > + > + /* At this point, we know that SSP points to VALUE which is a return > + address. In contrast to find_frame_sal which is used for the normal > + backtrace command, VALUE always points at the return instruction > + (which is *after* the call instruction). Since we want to get the > + line containing the call (because the call is where the user thinks > + the program is), we pass 1 here as second argument. */ > + symtab_and_line sal = find_sal_for_pc (value, 1); > + struct gdbarch *sal_arch = get_sal_arch (sal); Nit: remove unnecessary struct keyword. Also just FYI I'm encountering a snag here in the case of aarch64, which I'm still looking into: The gdbarch returned by get_sal_arch here doesn't have the shadow stack hooks set. This causes "bt -shadow" from a signal handler not to show "", because this "simpler" gdbarch will get passed as fallback_arch in the next call to get_shadow_stack_frame_info by shadow_stack_frame_info::unwind_prev_shadow_stack_frame_info, and then gdbarch_is_no_return_shadow_stack_address_p (fallback_arch) will be false and the corresponding aarch64 hook won't get a change to identify the sigframe token. I think get_sal_arch is returning a gdbarch that was created before the inferior was started, and at that time GDB couldn't know that GCS would be enabled. In any case, if this is working fine for x86 then don't worry about it. I can fix it when posting the aarch64 support for "bt -shadow". > + > + /* Fall back to the previous gdbarch in case we cannot extract it from > + SAL. */ > + if (sal_arch == nullptr) > + sal_arch = fallback_arch; > + > + return std::optional > + ({ssp, value, level, sal_arch, sal, > + ssp_unwind_stop_reason::no_error}); > +} -- Thiago (he/him)