From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KujZKZ2of2eUJAgAWB0awg (envelope-from ) for ; Thu, 09 Jan 2025 05:44:45 -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=cQtXRSgO; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=3HFjhB3H; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=cQtXRSgO; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=3HFjhB3H; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9C48E1E0C0; Thu, 9 Jan 2025 05:44:45 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) 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.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 8FB681E091 for ; Thu, 9 Jan 2025 05:44:44 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2DC15385828E for ; Thu, 9 Jan 2025 10:44:44 +0000 (GMT) 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 8A5C73858D29 for ; Thu, 9 Jan 2025 10:44:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A5C73858D29 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 8A5C73858D29 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=1736419462; cv=none; b=sOo4SwlrpR61EOePMKTkIuTYci1EX6AyUsqGLx9ZDFu2kvFQaf0n52AZvuofRN0oA5eCZe6TwgsbXgGdXc/FiY/Lg3Ai/8sGDsRdZ2wQvz+c8x7vo3qoPt2aSvZDu4S3/UhYFy+NqZEspuFMTt/BmE496hUCT3+ACJY0hYiZlTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736419462; c=relaxed/simple; bh=4y6o1za3GNzneluTxEkdDd38Sc1B+T5601N2UD/7vzU=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=ujiJrTnehAbs3DcTJJk6NWfHa01+LYotJo4x83Td05s6FvweJpoPuPG4aSId4C36Yfc+io30LnmASWQ+Ayn2ZIkLcrAy5Mh0VGUAiTyWcOzMZnAVpwKEupikpIJ9ht/DDpfWRzIoxI8OfgDqq3o6W5wHH3tr9FE0j2U49XKYxO4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A5C73858D29 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=cQtXRSgO; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=3HFjhB3H; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=cQtXRSgO; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=3HFjhB3H 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 330DD2115A for ; Thu, 9 Jan 2025 10:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1736419461; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=teXhAt5iGBfFHl/e5ItWF9qyg8nKId8J1T8vRZSBYsI=; b=cQtXRSgOXIWTPWGnSEBc9GA+x1pWsN34RtYilPTMHwiVbJUhLgmn0Q5fMg6Mk34cyMvrc/ +vVIlVzjoc5UEpuHcHobc5+DYX/CZOU8bXTXlbK50pszt+c8enZRW5a1nkWIQP7Knk42c8 FWcl215V1b+7VEZLfMSI2JKht38Rze0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1736419461; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=teXhAt5iGBfFHl/e5ItWF9qyg8nKId8J1T8vRZSBYsI=; b=3HFjhB3HEJ4WLiawy23kqJNBFmS8rB5k2bycnZT0iSvC766XE4mVRWLOot5+mordt9RqNP yiAS/nWXowdIhkAQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1736419461; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=teXhAt5iGBfFHl/e5ItWF9qyg8nKId8J1T8vRZSBYsI=; b=cQtXRSgOXIWTPWGnSEBc9GA+x1pWsN34RtYilPTMHwiVbJUhLgmn0Q5fMg6Mk34cyMvrc/ +vVIlVzjoc5UEpuHcHobc5+DYX/CZOU8bXTXlbK50pszt+c8enZRW5a1nkWIQP7Knk42c8 FWcl215V1b+7VEZLfMSI2JKht38Rze0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1736419461; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=teXhAt5iGBfFHl/e5ItWF9qyg8nKId8J1T8vRZSBYsI=; b=3HFjhB3HEJ4WLiawy23kqJNBFmS8rB5k2bycnZT0iSvC766XE4mVRWLOot5+mordt9RqNP yiAS/nWXowdIhkAQ== 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 1A26113A8B for ; Thu, 9 Jan 2025 10:44:21 +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 gJsRBYWof2ewFwAAD6G6ig (envelope-from ) for ; Thu, 09 Jan 2025 10:44:21 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 2/2] [gdb/tdep] Fix gdb.base/readnever.exp on s390x Date: Thu, 9 Jan 2025 11:44:06 +0100 Message-ID: <20250109104406.30675-2-tdevries@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250109104406.30675-1-tdevries@suse.de> References: <20250109104406.30675-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(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,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 On s390x-linux, I run into: ... (gdb) backtrace #0 0x000000000100061a in fun_three () #1 0x000000000100067a in fun_two () #2 0x000003fffdfa9470 in ?? () Backtrace stopped: frame did not save the PC (gdb) FAIL: gdb.base/readnever.exp: backtrace ... This is really due to a problem handling the fun_three frame. When generating a backtrace from fun_two, everying looks ok: ... $ gdb -readnever -q -batch outputs/gdb.base/readnever/readnever \ -ex "b fun_two" \ -ex run \ -ex bt ... #0 0x0000000001000650 in fun_two () #1 0x00000000010006b6 in fun_one () #2 0x00000000010006ee in main () ... For reference the frame info with debug info (without -readnever) looks like this: ... $ gdb -q -batch outputs/gdb.base/readnever/readnever \ -ex "b fun_three" \ -ex run \ -ex "info frame" ... Stack level 0, frame at 0x3fffffff140: pc = 0x1000632 in fun_three (readnever.c:20); saved pc = 0x100067a called by frame at 0x3fffffff1f0 source language c. Arglist at 0x3fffffff140, args: a=10, b=49 '1', c=0x3fffffff29c Locals at 0x3fffffff140, Previous frame's sp in v0 ... But with -readnever, like this instead: ... Stack level 0, frame at 0x0: pc = 0x100061a in fun_three; saved pc = 0x100067a called by frame at 0x3fffffff140 Arglist at 0xffffffffffffffff, args: Locals at 0xffffffffffffffff, Previous frame's sp in r15 ... An obvious difference is the "Previous frame's sp in" v0 vs. r15. Looking at the code: ... 0000000001000608 : 1000608: b3 c1 00 2b ldgr %f2,%r11 100060c: b3 c1 00 0f ldgr %f0,%r15 1000610: e3 f0 ff 50 ff 71 lay %r15,-176(%r15) 1000616: b9 04 00 bf lgr %r11,%r15 ... it becomes clear what is going on. This is an unusual prologue. Rather than saving r11 (frame pointer) and r15 (stack pointer) to stack, instead they're saved into call-clobbered floating point registers. [ For reference, this is the prologue of fun_two: ... 0000000001000640 : 1000640: eb bf f0 58 00 24 stmg %r11,%r15,88(%r15) 1000646: e3 f0 ff 50 ff 71 lay %r15,-176(%r15) 100064c: b9 04 00 bf lgr %r11,%r15 ... where the first instruction stores registers r11 to r15 to stack. ] Gdb fails to properly analyze the prologue, which causes the problems getting the frame info. Fix this by: - adding handling of the ldgr insn [1] in s390_analyze_prologue, and - recognizing the insn as saving a register in s390_prologue_frame_unwind_cache. This gets us instead: ... Stack level 0, frame at 0x0: pc = 0x100061a in fun_three; saved pc = 0x100067a called by frame at 0x3fffffff1f0 Arglist at 0xffffffffffffffff, args: Locals at 0xffffffffffffffff, Previous frame's sp in f0 ... and: ... (gdb) backtrace^M #0 0x000000000100061a in fun_three ()^M #1 0x000000000100067a in fun_two ()^M #2 0x00000000010006b6 in fun_one ()^M #3 0x00000000010006ee in main ()^M (gdb) PASS: gdb.base/readnever.exp: backtrace ... Tested on s390x-linux. PR tdep/32417 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32417 [1] https://www.ibm.com/support/pages/sites/default/files/2021-05/SA22-7871-10.pdf --- gdb/s390-tdep.c | 39 +++++++++++++++++++++++++++++++++++++++ gdb/s390-tdep.h | 1 + 2 files changed, 40 insertions(+) diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c index 70affc914c2..36a70d8642c 100644 --- a/gdb/s390-tdep.c +++ b/gdb/s390-tdep.c @@ -855,6 +855,11 @@ s390_analyze_prologue (struct gdbarch *gdbarch, || is_rre (insn64, op_lgr, &r1, &r2)) data->gpr[r1] = data->gpr[r2]; + /* LDGR r1, r2 --- load from register to floating-point register + (64-bit version). */ + else if (is_rre (insn64, op_ldgr, &r1, &r2)) + data->fpr[r1] = data->gpr[r2]; + /* L r1, d2(x2, b2) --- load. */ /* LY r1, d2(x2, b2) --- load (long-displacement version). */ /* LG r1, d2(x2, b2) --- load (64-bit version). */ @@ -2542,6 +2547,40 @@ s390_prologue_frame_unwind_cache (const frame_info_ptr &this_frame, && data.fpr_slot[i] != 0) info->saved_regs[S390_F0_REGNUM + i].set_addr (cfa - data.fpr_slot[i]); + /* Handle this type of prologue: + ldgr %f2,%r11 + ldgr %f0,%r15 + where call-clobbered floating point registers are used as register save + slots. */ + for (i = 0; i < S390_NUM_FPRS; i++) + { + int fpr = S390_F0_REGNUM + i; + + /* Check that fpr is a call-clobbered register. */ + if (s390_register_call_saved (gdbarch, fpr)) + continue; + + /* Check that fpr contains the value of a register at function + entry. */ + if (data.fpr[i].kind != pvk_register) + continue; + + int entry_val_reg = data.fpr[i].reg; + + /* Check that entry_val_reg is a call-saved register. */ + if (!s390_register_call_saved (gdbarch, entry_val_reg)) + continue; + + /* In the prologue, we've copied: + - the value of a call-saved register (entry_val_reg) at function + entry, to + - a call-clobbered floating point register (fpr). + + Heuristic: assume that makes the floating point register a register + save slot, leaving the value constant throughout the function. */ + info->saved_regs[entry_val_reg].set_realreg (fpr); + } + /* Function return will set PC to %r14. */ info->saved_regs[S390_PSWA_REGNUM] = info->saved_regs[S390_RETADDR_REGNUM]; diff --git a/gdb/s390-tdep.h b/gdb/s390-tdep.h index bfcb8f17c56..d8f5fd5e185 100644 --- a/gdb/s390-tdep.h +++ b/gdb/s390-tdep.h @@ -82,6 +82,7 @@ enum op1_lgfi = 0xc0, op2_lgfi = 0x01, op_lr = 0x18, op_lgr = 0xb904, + op_ldgr = 0xb3c1, op_l = 0x58, op1_ly = 0xe3, op2_ly = 0x58, op1_lg = 0xe3, op2_lg = 0x04, -- 2.43.0