From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id TK03CLpYqmlCXRgAWB0awg (envelope-from ) for ; Thu, 05 Mar 2026 23:31:54 -0500 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=oso5a3xF; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id EF1D01E0DD; Thu, 05 Mar 2026 23:31:53 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED 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 E18151E08D for ; Thu, 05 Mar 2026 23:31:52 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 838844BA2E19 for ; Fri, 6 Mar 2026 04:31:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 838844BA2E19 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=oso5a3xF Received: from mail-ua1-x92f.google.com (mail-ua1-x92f.google.com [IPv6:2607:f8b0:4864:20::92f]) by sourceware.org (Postfix) with ESMTPS id E1D2D4BA2E0E for ; Fri, 6 Mar 2026 04:31:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1D2D4BA2E0E 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 E1D2D4BA2E0E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::92f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772771483; cv=none; b=bWYwSdHeXpboYQWo80pVDzofOw92og1tMRba8ljVL8k9kuHu24VYt2kRDGRCrw9ZLsK9EJdueA9oj60B8xyOJUc4NeOQY8AdoofD7hiIPvnYW+gL23tedl4JWHBM6EbrQVCEv+nD2mrbtEm8JJF1Jgu4+cW4GgHGlVEYhvnvyQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772771483; c=relaxed/simple; bh=ozpHpInrgbKlgmOUrGXKYeK/Ano0S1nW0Rucemj7vqg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jQ6gjXf6DK6+LnXbPytk+70//OLrWzYfVvJY7NrRjupW91H42hJfrNTqCK/smyRPZie5ztZMh9+IcaahqLKDXO53Lzmk0QJHrOlkfMD6I6Y950k1LbmUDVSIZL89eTow1gIiYW1adUOEEU92PhEl/e/vF/b4yGXEiOLQHvqSQq0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1D2D4BA2E0E Received: by mail-ua1-x92f.google.com with SMTP id a1e0cc1a2514c-94dd05a4b44so5175767241.1 for ; Thu, 05 Mar 2026 20:31:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1772771482; x=1773376282; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lOpoSuh7UUiNpZ5uNHzKv47nvG2PxOaTPuDqgMopxrg=; b=oso5a3xFyAdLVjtipKOiOtobm04I1TeokuH9WkNLkTRbRYH0fCzkuXJvH1wxvJ3cNC M6mtQarKdfWsH0Oa9FwmuhSBArAy8xtacBECrrqsq/0iicn8Wkzv7A1N3k6rPOhbrdXv aC3rTg6bqa5kxevFEwyeII7tcVmkkmIn/VprmE57PUuPEScAPXNOn/2MtCbD2xYsRj0Y 890NksA4HY13+JqOqz0G1JqG5pr0Ane33+YUc+zs1YWHqiqNrBP2ifGmAvOvA/Q9k9Lg ExwzX4hTryRu9E7Xb8KvP4Z662LVC8wOQs7n/wSsPCuuZ0eB8Ei4RM8syOkrZPmYzNsy 4qAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772771482; x=1773376282; h=content-transfer-encoding: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; bh=lOpoSuh7UUiNpZ5uNHzKv47nvG2PxOaTPuDqgMopxrg=; b=O/oCfsmdzFKk+r3EfRiGNrWmfBMqiuEcb1CBLmKZuqk0Adv6p+XcfG/tnu/aCNzSdz gR96IHXtXWAHOPh+xcVqEovo9OLwmTSDGm+jX8hObseQS08DWD/IYT0MwrCJLRzHt+fa yvj0OOvQwn8RR0jStXMPPFdzJ1h8ODKa0smEhIMM7nOtr1kQ5vjbNo0/T2d41ItUjS7s /D5c0VNKmVbDcbnHZ5BjvsJhTsGBMTINakky/PVNgnCGKM2cBp1XZJqQaFJjfsTVN6yr z67kIw5J9Hy9RcpfUceJbHFa3EAapJ2MtybSLNj5BRC6bwY/0jAQbzcC8ts1ywHV78Ht 0+cg== X-Gm-Message-State: AOJu0Yy4eK+ymIgp4gwz2L/4S7c4ZZQxaEuai+QSSfcgocqWOu3Qq6aR 0nB2Ntu8/hYuTx6bxpThkuDhUqKzDmTA/bvUKNBA8wLIHOs7T5n3HV9569I9k+I5oXQ= X-Gm-Gg: ATEYQzwgGyqWfD+tDemgTWe22Dh7RNRtrbgrVPfdZQOxptuJZbIG8y9wHc08cvnXVCL vQwZDM80gnQ6tq9GT3GuE5Fb5ZtP/bGQQ0idldfd6c2o/RUAWKZF5LnD6nXcFXUqzZV4mgvpXwg 3DeBt6HLKnzcgH6hNomzlpsgiJ/vFMcDiPcvp65+MQOfvziUumpRenAKMXWpHzXZAl8FelJ0v7B KC0UE/UTCY+rdIs+l+IYkuOUtD0xWZWEBd0RUp0eIKaStE1wVtKLFYegbSGNkOpK+1ZceANJ0uf AktoYd394sya0ok3bOwJqtobkg5jh1Lr3fTABYPy7tUDV8lzbQ+1OjHuJSMhLXk53XWxG2B/kyj 5ZgtjOPGxphmWq23ALqKUpMSNtscmodPle9fzR86R+1H2UzdFWCvoMU6u/O4KM4cDmcKoMrB+3z np3RIcjG0Fzp0Zaq+8l6H5YJ36yX5Dv4F6Uw== X-Received: by 2002:a05:6102:38c7:b0:5ff:ea89:449a with SMTP id ada2fe7eead31-5ffea895b05mr77781137.13.1772771482191; Thu, 05 Mar 2026 20:31:22 -0800 (PST) Received: from localhost ([2804:14d:7e39:8083:f04c:42e3:5943:38f6]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-56b09a261c9sm270245e0c.8.2026.03.05.20.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2026 20:31:21 -0800 (PST) From: Thiago Jung Bauermann To: Christina Schimpe Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v2 6/9] gdb: Add command option 'bt -shadow' to print the shadow stack backtrace. In-Reply-To: <20260123080532.878738-7-christina.schimpe@intel.com> (Christina Schimpe's message of "Fri, 23 Jan 2026 08:05:28 +0000") References: <20260123080532.878738-1-christina.schimpe@intel.com> <20260123080532.878738-7-christina.schimpe@intel.com> User-Agent: mu4e 1.12.15; emacs 30.2 Date: Fri, 06 Mar 2026 01:31:19 -0300 Message-ID: <87bjh1y3xk.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 I'll have a closer look at this patch next week, including your comments about the count argument to the get_trailing_outermost_shadow_stack_frame_info in the thread for v1 of this series.. Unfortunately I didn't have much time to dig into it yet. Some minor comments for now: Christina Schimpe writes: > diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c > index 656daa0f0ee..a4eabccf667 100644 > --- a/gdb/amd64-linux-tdep.c > +++ b/gdb/amd64-linux-tdep.c > @@ -1963,6 +1963,29 @@ amd64_linux_top_addr_empty_shadow_stack > return addr =3D=3D range.second; > } >=20=20 > +/* Return the number of elements which are currently on the shadow stack > + based on the shadow stack memory RANGE [start_address, end_address) > + of the current thread. In case shadow stack is not enabled for the > + current thread, return -1. */ > + > +static long > +amd64_linux_get_shadow_stack_size > + (gdbarch *gdbarch, > + const std::optional ssp, > + const std::pair range) > +{ > + /* For x86, if we don't have a shadow stack pointer, we can assume > + that the shadow stack is disabled for the current thread. */ > + if (!ssp.has_value ()) > + return -1; As I mention a bit below, the only caller of this function passes a value for the ssp argument, so this is dead code. > + const unsigned long shadow_stack_bytes =3D range.second - *ssp; > + > + gdb_assert ((shadow_stack_bytes % 8) =3D=3D 0); I don't think this should be an assert. If it fails, it triggers an internal error in GDB. In this case it could indeed mean an internal error (GDB somehow got the SSP or range wrong), but it could also be (and probably more likely) an inconsistent state of the inferior. This can happen in a program being debugged so GDB should be able to handle it gracefully, and if possible provide useful information to the user. > + return shadow_stack_bytes / 8; > +} =E2=8B=AE > +/* Read the memory at shadow stack pointer SSP and assign it to > + RETURN_VALUE. In case we cannot read the memory, set REASON to > + ssp_unwind_stop_reason::memory_read_error and return false. */ > + > +static bool > +read_shadow_stack_memory (gdbarch *gdbarch, CORE_ADDR ssp, > + CORE_ADDR &return_value, > + ssp_unwind_stop_reason *reason) The reason argument can also be a reference. > +{ > + /* On x86 there can be a shadow stack token at bit 63. For x32, the > + address size is only 32 bit. Thus, we still must use > + gdbarch_shadow_stack_element_size_aligned (and not gdbarch_addr_bit) > + to read the full element for x32 as well. */ > + const int element_size > + =3D gdbarch_shadow_stack_element_size_aligned (gdbarch); > + > + const bfd_endian byte_order =3D gdbarch_byte_order (gdbarch); > + if (!safe_read_memory_unsigned_integer (ssp, element_size, byte_order, > + &return_value)) > + { > + *reason =3D ssp_unwind_stop_reason::memory_read_error; > + return false; > + } > + > + return true; > +} > + > +/* If possible, return the starting shadow stack frame info needed to h= andle > + COUNT outermost frames. FRAME should point to the innermost (newest) > + element of the shadow stack. RANGE is the shadow stack memory range > + [start_address, end_address) corresponding to FRAME's shadow stack p= ointer. > + If COUNT is bigger than the number of elements on the shadow stack, = return > + FRAME. In case of failure, assign an appropriate ssp_unwind_stop_re= ason in > + FRAME->UNWIND_stop_REASON. */ > + > +static std::optional > +get_trailing_outermost_shadow_stack_frame_info > + (gdbarch *gdbarch, const std::pair range, > + const ULONGEST count, shadow_stack_frame_info &frame) > +{ > + gdb_assert (gdbarch_get_shadow_stack_size_p (gdbarch)); > + > + const long shadow_stack_size > + =3D gdbarch_get_shadow_stack_size (gdbarch, > + std::optional (frame.ssp), > + range); This is the only caller of gdbarch_get_shadow_stack_size. Does its ssp argument need to be std::optional, or can it simply be a CORE_ADDR? > + /* We should only get here in case shadow stack is enabled for the > + current thread. */ > + gdb_assert (shadow_stack_size >=3D 0); > + > + const long level =3D shadow_stack_size - count; > + > + /* COUNT exceeds the number of elements on the shadow stack. Return t= he > + starting shadow stack frame info FRAME. */ > + if (level <=3D 0) > + return std::optional (frame); > + > + CORE_ADDR new_ssp =3D update_shadow_stack_pointer > + (gdbarch, frame.ssp, level, ssp_update_direction::outer); > + > + if (gdbarch_stack_grows_down (gdbarch)) > + gdb_assert (new_ssp < range.second); > + else > + gdb_assert (new_ssp >=3D range.first); > + > + CORE_ADDR new_value; > + if (!read_shadow_stack_memory (gdbarch, new_ssp, new_value, > + &frame.unwind_stop_reason)) > + return {}; > + > + return std::optional > + ({new_ssp, new_value, (unsigned long) level, > + ssp_unwind_stop_reason::no_error}); > +} =E2=8B=AE > diff --git a/gdb/shadow-stack.h b/gdb/shadow-stack.h > index 5f8395ec047..5370becfc9a 100644 > --- a/gdb/shadow-stack.h > +++ b/gdb/shadow-stack.h > @@ -35,4 +35,10 @@ void shadow_stack_push (regcache *regcache, const CORE= _ADDR new_addr); > value *dwarf2_prev_ssp (const frame_info_ptr &this_frame, > void **this_cache, int regnum); >=20=20 > +/* Implementation of "backtrace shadow" comand. */ > + > +void backtrace_shadow_command > + (const frame_print_options &fp_opts, > + const char *count_exp, int from_tty); > + > #endif /* GDB_SHADOW_STACK_H */ This header needs to forward-declare "struct frame_print_options;", similarly to the "class regcache;" forward declaration. Actually, one thing I missed in my review of patch 1 is that it also needs to forward-declare "class frame_info_ptr;" which is used in the prototype of dwarf2_prev_ssp. --=20 Thiago