From patchwork Mon Mar 20 16:36:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 19659 Received: (qmail 80467 invoked by alias); 20 Mar 2017 16:36:37 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 79925 invoked by uid 89); 20 Mar 2017 16:36:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=H*Ad:U*uweigand, HCc:U*uweigand X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Mar 2017 16:36:35 +0000 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2KGXvGh128428 for ; Mon, 20 Mar 2017 12:36:34 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 29ahvyu5nx-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 20 Mar 2017 12:36:34 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 20 Mar 2017 16:36:31 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 20 Mar 2017 16:36:28 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2KGaSUH38404322; Mon, 20 Mar 2017 16:36:28 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 634A6AE057; Mon, 20 Mar 2017 16:36:02 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3B1EFAE045; Mon, 20 Mar 2017 16:36:02 +0000 (GMT) Received: from oc1027705133.ibm.com (unknown [9.152.212.162]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 20 Mar 2017 16:36:02 +0000 (GMT) From: Andreas Arnez To: gdb-patches@sourceware.org Cc: Ulrich Weigand Subject: [pushed] s390: Fix displaced-stepping certain relative branch insns User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Date: Mon, 20 Mar 2017 17:36:25 +0100 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17032016-0008-0000-0000-00000408052D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17032016-0009-0000-0000-00001CE73EE7 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-20_13:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703200144 X-IsSubscribed: yes On s390x targets GDB can not handle displaced stepping correctly for some relative branch instructions, such as cij (compare immediate and branch relative). When setting a breakpoint on such an instruction and single-stepping over it, the branch is never taken. This is because the check in s390_displaced_step_fixup for relative branch instructions is incomplete. Instead of completing the list of relative branch instructions to check against, this patch just treats relative branches and non-branching instructions in the same way and adjusts the PC with the negated displacement in both cases. gdb/ChangeLog: * s390-linux-tdep.c (is_rsi, is_rie): Remove functions. (s390_displaced_step_fixup): Cover relative branches with the default fixup handling. This fixes lack of support for some relative branch instructions. --- gdb/s390-linux-tdep.c | 55 ++++----------------------------------------------- 1 file changed, 4 insertions(+), 51 deletions(-) diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c index abc9438..2af2c7a 100644 --- a/gdb/s390-linux-tdep.c +++ b/gdb/s390-linux-tdep.c @@ -1212,41 +1212,6 @@ is_rsy (bfd_byte *insn, int op1, int op2, static int -is_rsi (bfd_byte *insn, int op, - unsigned int *r1, unsigned int *r3, int *i2) -{ - if (insn[0] == op) - { - *r1 = (insn[1] >> 4) & 0xf; - *r3 = insn[1] & 0xf; - /* i2 is a 16-bit signed quantity. */ - *i2 = (((insn[2] << 8) | insn[3]) ^ 0x8000) - 0x8000; - return 1; - } - else - return 0; -} - - -static int -is_rie (bfd_byte *insn, int op1, int op2, - unsigned int *r1, unsigned int *r3, int *i2) -{ - if (insn[0] == op1 - && insn[5] == op2) - { - *r1 = (insn[1] >> 4) & 0xf; - *r3 = insn[1] & 0xf; - /* i2 is a 16-bit signed quantity. */ - *i2 = (((insn[2] << 8) | insn[3]) ^ 0x8000) - 0x8000; - return 1; - } - else - return 0; -} - - -static int is_rx (bfd_byte *insn, int op, unsigned int *r1, int *d2, unsigned int *x2, unsigned int *b2) { @@ -1976,20 +1941,6 @@ s390_displaced_step_fixup (struct gdbarch *gdbarch, amode | (from + insnlen)); } - /* Handle PC-relative branch instructions. */ - else if (is_ri (insn, op1_brc, op2_brc, &r1, &i2) - || is_ril (insn, op1_brcl, op2_brcl, &r1, &i2) - || is_ri (insn, op1_brct, op2_brct, &r1, &i2) - || is_ri (insn, op1_brctg, op2_brctg, &r1, &i2) - || is_rsi (insn, op_brxh, &r1, &r3, &i2) - || is_rie (insn, op1_brxhg, op2_brxhg, &r1, &r3, &i2) - || is_rsi (insn, op_brxle, &r1, &r3, &i2) - || is_rie (insn, op1_brxlg, op2_brxlg, &r1, &r3, &i2)) - { - /* Update PC. */ - regcache_write_pc (regs, pc - to + from); - } - /* Handle LOAD ADDRESS RELATIVE LONG. */ else if (is_ril (insn, op1_larl, op2_larl, &r1, &i2)) { @@ -2004,9 +1955,11 @@ s390_displaced_step_fixup (struct gdbarch *gdbarch, else if (insn[0] == 0x0 && insn[1] == 0x1) regcache_write_pc (regs, from); - /* For any other insn, PC points right after the original instruction. */ + /* For any other insn, adjust PC by negated displacement. PC then + points right after the original instruction, except for PC-relative + branches, where it points to the adjusted branch target. */ else - regcache_write_pc (regs, from + insnlen); + regcache_write_pc (regs, pc - to + from); if (debug_displaced) fprintf_unfiltered (gdb_stdlog,