From patchwork Fri Oct 27 00:51:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 78603 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2492385C6C4 for ; Fri, 27 Oct 2023 00:54:59 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 9EAC73858404 for ; Fri, 27 Oct 2023 00:54:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9EAC73858404 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9EAC73858404 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698368085; cv=none; b=nAAg3gZkh+ET6ldXkR/4RO9MZrm6Z+Sie4bfuFtL0O8wIRa8LhDbe04XdsWrR7e2xl1gmWg0x7Kho1/4JT2CAZ3jOqbXVDQiAg4WqKbB8k14VwgaHj8Da5hWexrSTXqf1iaFAVZwhRawRjcrJTDc7a7fXGLYfnn+EWKd8FBFAW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698368085; c=relaxed/simple; bh=EjFjB+zSK7hRqNwlNK1CKtzoyrWxC2Ubge1cThIqtZQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FIEi3sbv+x5bhcK7H7LsyLo4VM72jCog/LCC8g554dy+xTzeqac6UXwatoggBX1ZGTRYZqX4QGsMzRBorm8pSv1bBcrZBhGn62X8+jc7RAkm2/ooVrAl1d6H07MYgb8QAzhAHUu47enCa/06lB2Arb/JtLCY/ClM3nL9AQfCzA8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39R0ML71019344 for ; Fri, 27 Oct 2023 00:54:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=1bE9Bg/ag/kecTioB3vHe/urVHyOwJZgPm+zIi8K3nY=; b=EQnVQ9HsxdfYiMNolePoC6vmjwukwza0OLpQ8NaaTUpNCptNPvMT6peP5qNAsby2kGv5 MWBpXJEvGwieLf7hHSb9c+75VPLtkr45z1zTQhxbnEOSPuujv48FgfUEkkxvZFw1sBFm pIgR0UMzAI14SsJSykWrakhohALnwqH7x4hpQMuxfVA+JOA3xLryuH07BDPubPDdnceP kBMiCqgK3qSc9CFo1Qt5w7nevf5ZkBk8i6J27crD4neGopWjUuUesWKPNiBBpdkDQf4C ACkotKvG0Gc3b0sKCYGI7m7BM1gcbaXyKGlLo0EMnLKyUiqzrFpW1DGzxvRk/N8FdEqV HA== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u02kus0js-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 27 Oct 2023 00:54:42 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 39QLqGmE011409 for ; Fri, 27 Oct 2023 00:54:40 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3tywqr1pgw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 27 Oct 2023 00:54:40 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 39R0sbnr20644606 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Oct 2023 00:54:37 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 59C6520040; Fri, 27 Oct 2023 00:54:37 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 218C22004B; Fri, 27 Oct 2023 00:54:37 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.179.7.54]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 27 Oct 2023 00:54:37 +0000 (GMT) From: Ilya Leoshkevich To: Andreas Arnez Cc: gdb-patches@sourceware.org, Ilya Leoshkevich Subject: [PATCH] gdb/s390: Add packed-stack support to the backchain unwinder Date: Fri, 27 Oct 2023 02:51:32 +0200 Message-ID: <20231027005434.991682-1-iii@linux.ibm.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: FVGfgwr8zgWiZsmCwd0G6oZUbGEW3Zet X-Proofpoint-GUID: FVGfgwr8zgWiZsmCwd0G6oZUbGEW3Zet X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-26_22,2023-10-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 spamscore=0 impostorscore=0 clxscore=1011 suspectscore=0 lowpriorityscore=0 mlxlogscore=841 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310240000 definitions=main-2310270006 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org Currently it's not possible to unwind s390 kernel stacks past eBPF progs. There is no DWARF debug info or symbols for eBPF progs, therefore doing so requires using the backchain unwinder. The kernel uses the packed-stack ABI, which the backchain unwinder does not support. As far as unwinding is concerned, the difference between the "regular" ABI and the packed-stack ABI are frame offsets for backchain, stack pointer and program counter. Parameterize the existing code that does backchain unwinding by these three values; try the "regular" ones first, and the packed-stack ones as a fallback. Reviewed-by: Keith Seitz --- Regtested on s390x-redhat-linux. Ok for master? gdb/s390-tdep.c | 72 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c index 54b5c89e5e3..2d5c3f99dd8 100644 --- a/gdb/s390-tdep.c +++ b/gdb/s390-tdep.c @@ -2520,32 +2520,24 @@ s390_prologue_frame_unwind_cache (frame_info_ptr this_frame, return 1; } -/* Unwind THIS_FRAME and write the information into unwind cache INFO using - back chain unwinding. Helper for s390_frame_unwind_cache. */ +/* Unwind THIS_FRAME using back chain unwinding for the ABI described by + WORD_SIZE, BYTE_ORDER, BACKCHAIN_IDX, SP_IDX and PC_IDX. If successful, + write the information into unwind cache INFO and return true, otherwise + return false. Helper for s390_backchain_frame_unwind_cache. */ -static void -s390_backchain_frame_unwind_cache (frame_info_ptr this_frame, - struct s390_unwind_cache *info) +static bool +try_backchain (frame_info_ptr this_frame, struct s390_unwind_cache *info, + int word_size, enum bfd_endian byte_order, int backchain_idx, + int sp_idx, int pc_idx) { - struct gdbarch *gdbarch = get_frame_arch (this_frame); - int word_size = gdbarch_ptr_bit (gdbarch) / 8; - enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); CORE_ADDR backchain; - ULONGEST reg; LONGEST sp, tmp; - int i; - - /* Set up ABI call-saved/call-clobbered registers. */ - for (i = 0; i < S390_NUM_REGS; i++) - if (!s390_register_call_saved (gdbarch, i)) - info->saved_regs[i].set_unknown (); - - /* CC is always call-clobbered. */ - info->saved_regs[S390_PSWM_REGNUM].set_unknown (); + ULONGEST reg; /* Get the backchain. */ reg = get_frame_register_unsigned (this_frame, S390_SP_REGNUM); - if (!safe_read_memory_integer (reg, word_size, byte_order, &tmp)) + if (!safe_read_memory_integer (reg + backchain_idx * word_size, word_size, + byte_order, &tmp)) tmp = 0; backchain = (CORE_ADDR) tmp; @@ -2554,15 +2546,17 @@ s390_backchain_frame_unwind_cache (frame_info_ptr this_frame, save area pointed to by the backchain in fact links back to the save area. */ if (backchain != 0 - && safe_read_memory_integer (backchain + 15*word_size, - word_size, byte_order, &sp) + && safe_read_memory_integer (backchain + sp_idx * word_size, word_size, + byte_order, &sp) && (CORE_ADDR)sp == backchain) { /* We don't know which registers were saved, but it will have to be at least %r14 and %r15. This will allow us to continue unwinding, but other prev-frame registers may be incorrect ... */ - info->saved_regs[S390_SP_REGNUM].set_addr (backchain + 15*word_size); - info->saved_regs[S390_RETADDR_REGNUM].set_addr (backchain + 14*word_size); + info->saved_regs[S390_SP_REGNUM].set_addr (backchain + + sp_idx * word_size); + info->saved_regs[S390_RETADDR_REGNUM].set_addr (backchain + + pc_idx * word_size); /* Function return will set PC to %r14. */ info->saved_regs[S390_PSWA_REGNUM] @@ -2570,10 +2564,40 @@ s390_backchain_frame_unwind_cache (frame_info_ptr this_frame, /* We use the current value of the frame register as local_base, and the top of the register save area as frame_base. */ - info->frame_base = backchain + 16*word_size + 32; + info->frame_base = backchain + 16 * word_size + 32; info->local_base = reg; + + return true; } + return false; +} + +/* Unwind THIS_FRAME and write the information into unwind cache INFO using + back chain unwinding. Helper for s390_frame_unwind_cache. */ + +static void +s390_backchain_frame_unwind_cache (frame_info_ptr this_frame, + struct s390_unwind_cache *info) +{ + struct gdbarch *gdbarch = get_frame_arch (this_frame); + int word_size = gdbarch_ptr_bit (gdbarch) / 8; + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + int i; + + /* Set up ABI call-saved/call-clobbered registers. */ + for (i = 0; i < S390_NUM_REGS; i++) + if (!s390_register_call_saved (gdbarch, i)) + info->saved_regs[i].set_unknown (); + + /* CC is always call-clobbered. */ + info->saved_regs[S390_PSWM_REGNUM].set_unknown (); + + /* Try the regular ABI. */ + if (!try_backchain (this_frame, info, word_size, byte_order, 0, 15, 14)) + /* Try the packed stack ABI. */ + try_backchain (this_frame, info, word_size, byte_order, 19, 18, 17); + info->func = get_frame_pc (this_frame); }