From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4ZPBAOjFcGmGGw4AWB0awg (envelope-from ) for ; Wed, 21 Jan 2026 07:26:16 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=KLVSeWfg; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=L2PQB5HO; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=KLVSeWfg; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=L2PQB5HO; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E53771E0AD; Wed, 21 Jan 2026 07:26:15 -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 D3F151E08D for ; Wed, 21 Jan 2026 07:26:14 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 53F1B4BC896D for ; Wed, 21 Jan 2026 12:26:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 53F1B4BC896D Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=KLVSeWfg; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=L2PQB5HO; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=KLVSeWfg; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=L2PQB5HO Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id DE15E4BA9026 for ; Wed, 21 Jan 2026 12:25:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE15E4BA9026 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DE15E4BA9026 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768998345; cv=none; b=u2q94tLXYnhx/eZlf9paLssZ1DbTx91dTizj4krmMXUV7jCbOkZbrTbSzc/e95+SjNRnKooJVi2fLUrJfIKjSO7cWgoig8U2HZGG6OTit8QjyL5049uhNLRF/Vsv/QBBAPBOaRkSToYBFUFKTyIR4HZ5/k3z8H6o5W6eWDCPrqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768998345; c=relaxed/simple; bh=Xg0f+4sExpMW604hOcUiMPxL0C05p7ZydpxdH1Mln40=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=feOqKRTLrS864gISeAP2JTtiJUb+J2vCpwVHVBfSgrQrCL4YrvF4AoU4NBLRGA9srcZ9OgeA3ijQwci5Rodb2wJTC5KkC572umehGm4jFMxDp2kJaToD1/2j7mErirkBeDyZCcKycOPDmAaqW3HFlTMH/6a69bAdnaUn9pRnovo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE15E4BA9026 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C977933691 for ; Wed, 21 Jan 2026 12:25:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768998343; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=p5kl+ce7oLAbQTLPNXS/K1GeazKy+raWMAB8BLxpuDA=; b=KLVSeWfgkx6+3azVSHWQhmjlWV1EwvnPYxaFYvoK73nodA78aR74Xuc96M1rywg6FFgejg cMIiXItqdm/rkyzkcRPxK52HrwXajLTKiSotBLtWdqXRyEiEsJ6FymkdjAOWAgUkhi1X7q AhkKIm+hcMhLH75LQL4F54a62wuzSL4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768998343; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=p5kl+ce7oLAbQTLPNXS/K1GeazKy+raWMAB8BLxpuDA=; b=L2PQB5HO/e/rb2iQXmkgSafn9dnZtpH9H0zyXH+raUdnhrUpd1zi6KbhASxrB8vGjFOdWq D28q5TLPGBYs8tBQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768998343; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=p5kl+ce7oLAbQTLPNXS/K1GeazKy+raWMAB8BLxpuDA=; b=KLVSeWfgkx6+3azVSHWQhmjlWV1EwvnPYxaFYvoK73nodA78aR74Xuc96M1rywg6FFgejg cMIiXItqdm/rkyzkcRPxK52HrwXajLTKiSotBLtWdqXRyEiEsJ6FymkdjAOWAgUkhi1X7q AhkKIm+hcMhLH75LQL4F54a62wuzSL4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768998343; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=p5kl+ce7oLAbQTLPNXS/K1GeazKy+raWMAB8BLxpuDA=; b=L2PQB5HO/e/rb2iQXmkgSafn9dnZtpH9H0zyXH+raUdnhrUpd1zi6KbhASxrB8vGjFOdWq D28q5TLPGBYs8tBQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id AE8833EA63 for ; Wed, 21 Jan 2026 12:25:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id A2P0KMfFcGkFbgAAD6G6ig (envelope-from ) for ; Wed, 21 Jan 2026 12:25:43 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2] [gdb/testsuite] Fix gdb.base/inline-frame-cycle-unwind.exp for s390x (alternative) Date: Wed, 21 Jan 2026 13:25:43 +0100 Message-ID: <20260121122543.4129049-1-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] 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 From: Andrew Burgess With test-case gdb.base/inline-frame-cycle-unwind.exp on s390x-linux, I run into: ... (gdb) bt #0 inline_func () at inline-frame-cycle-unwind.c:49 #1 normal_func () at inline-frame-cycle-unwind.c:32 #2 0x000000000100065c in inline_func () at inline-frame-cycle-unwind.c:45 #3 normal_func () at inline-frame-cycle-unwind.c:32 Backtrace stopped: previous frame identical to this frame (corrupt stack?) (gdb) FAIL: $exp: bt: cycle at level 5: backtrace when the unwind is broken \ at frame 5 ... In contrast, on x86_64-linux, I get: ... (gdb) bt #0 inline_func () at inline-frame-cycle-unwind.c:49 #1 normal_func () at inline-frame-cycle-unwind.c:32 #2 0x0000000000401157 in inline_func () at inline-frame-cycle-unwind.c:45 #3 normal_func () at inline-frame-cycle-unwind.c:32 #4 0x0000000000401157 in inline_func () at inline-frame-cycle-unwind.c:45 #5 normal_func () at inline-frame-cycle-unwind.c:32 Backtrace stopped: previous frame identical to this frame (corrupt stack?) (gdb) PASS: $exp: bt: cycle at level 5: backtrace when the unwind is broken \ at frame 5 ... Let's first see what happens on x86_64-linux. The test-case installs a custom unwinder, which gets triggered with pending_frame.level() == 5. The responsibility of the unwinder at that point is to: - calculate a frame ID for the pending frame, and - provided the register values for the previous frame (with level pending_frame.level() + 1), as saved in the pending frame. However, the custom unwinder does some else. While it does calculate the frame ID for the pending frame, instead it provides the register values for the pending frame, which causes the unwinder to stop. After adding some debugging prints, we can see that the frame ID calculated by the custom unwinder: ... LEVEL: 5 FrameID: sp: 7fffffffcd50, pc: 401116 ... matches the frame ID as calculated by GDB: ... (gdb) maint print frame-id 5 frame-id for frame #5: {stack=0x7fffffffcd50,code=0x0000000000401116,!special} ... Now back to s390x-linux. This time, the frame ID calculated by the custom unwinder: ... LEVEL: 5 FrameID: sp: 3ffffffe8d0, pc: 1000608 ... does not match the frame ID as calculated by GDB: ... (gdb) maint print frame-id 5 frame-id for frame #5: {stack=0x3ffffffe970,code=0x0000000001000608,!special} ... Instead, it matches the frame ID for frame #3: ... (gdb) maint print frame-id 3 frame-id for frame #3: {stack=0x3ffffffe8d0,code=0x0000000001000608,!special} ... Fix this by using "maint print frame-id" to get all frame-ids, and using those instead. Tested on x86_64-linux and s390x-linux. Co-Authored-By: Tom de Vries --- .../gdb.base/inline-frame-cycle-unwind.exp | 3 + .../gdb.base/inline-frame-cycle-unwind.py | 58 +++++++++++++------ 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.exp b/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.exp index cc9585ee325..fd9cba78f9a 100644 --- a/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.exp +++ b/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.exp @@ -72,6 +72,9 @@ gdb_continue_to_breakpoint "stop at test breakpoint" gdb_test_no_output "source ${pyfile}"\ "import python scripts" +# Print the captured frame IDs. +gdb_test "python print_frame_ids()" + # Test with and without filters. foreach bt_cmd { "bt" "bt -no-filters" } { with_test_prefix "$bt_cmd" { diff --git a/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.py b/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.py index 80cfb864f21..09ddfb7e536 100644 --- a/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.py +++ b/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import re + import gdb from gdb.unwinder import Unwinder @@ -21,10 +23,14 @@ from gdb.unwinder import Unwinder # was written for. stop_at_level = None -# Set this to the stack frame size of frames 1, 3, and 5. These -# frames will all have the same stack frame size as they are the same -# function called recursively. -stack_adjust = None +# List of FrameId instances, one for each stack frame. +frame_ids = [] + + +def print_frame_ids(): + for i in range(len(frame_ids)): + fid = frame_ids[i] + print("frame-id for frame #%s: {stack=0x%x,code=0x%x}" % (i, fid.sp, fid.pc)) class FrameId(object): @@ -49,16 +55,25 @@ class TestUnwinder(Unwinder): if stop_at_level is None or pending_frame.level() != stop_at_level: return None - if stack_adjust is None: - raise gdb.GdbError("invalid stack_adjust") + if len(frame_ids) < stop_at_level: + raise gdb.GdbError("not enough parsed frame-ids") if stop_at_level not in [1, 3, 5]: raise gdb.GdbError("invalid stop_at_level") - sp_desc = pending_frame.architecture().registers().find("sp") - sp = pending_frame.read_register(sp_desc) + stack_adjust - pc = (gdb.lookup_symbol("normal_func"))[0].value().address - unwinder = pending_frame.create_unwind_info(FrameId(sp, pc)) + # We're unwinding frame #n (n == pending_frame.level()), and are + # expected to return: + # - a frame ID for frame #n, and + # - the register values for frame #(n+1), as saved in frame #n + # + # Instead, we return the frame ID for frame #n, and the register + # values for frame #n. + # + # This will cause the backtrace stop at level #n, meaning: + # - the entry for frame #n will be printed. + # - the entry for frame #(n+1) will not be printed, instead + # "Backtrace stopped: " will be printed. + unwinder = pending_frame.create_unwind_info(frame_ids[stop_at_level]) for reg in pending_frame.architecture().registers("general"): val = pending_frame.read_register(reg) @@ -76,11 +91,18 @@ gdb.unwinder.register_unwinder(None, TestUnwinder(), True) # # main -> normal_func -> inline_func -> normal_func -> inline_func -> normal_func -> inline_func # -# Compute the stack frame size of normal_func, which has inline_func -# inlined within it. -f0 = gdb.newest_frame() -f1 = f0.older() -f2 = f1.older() -f0_sp = f0.read_register("sp") -f2_sp = f2.read_register("sp") -stack_adjust = f2_sp - f0_sp +# Iterate through frames 0 to 6, parse their frame-id and store it +# into the global FRAME_IDS list. +for i in range(7): + # Get the frame-id in a verbose text form. + output = gdb.execute("maint print frame-id %d" % i, to_string=True) + + # Parse the frame-id in OUTPUT, find the stack and code addresses. + match = re.search(r"stack=(0x[0-9a-fA-F]+).*?code=(0x[0-9a-fA-F]+)", output) + if not match: + raise gdb.GdbError("Could not parse frame-id for frame #%d" % i) + + # Create the FrameId object. + sp_addr = int(match.group(1), 16) + pc_addr = int(match.group(2), 16) + frame_ids.append(FrameId(sp_addr, pc_addr)) base-commit: 5606bf89ba974005089bb39bd23e944973fe60eb -- 2.51.0