From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id pvEOGBGYEWB6SwAAWB0awg (envelope-from ) for ; Wed, 27 Jan 2021 11:42:57 -0500 Received: by simark.ca (Postfix, from userid 112) id 59A131EF80; Wed, 27 Jan 2021 11:42:57 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,RDNS_NONE, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9FB811E945 for ; Wed, 27 Jan 2021 11:42:56 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F32923973039; Wed, 27 Jan 2021 16:42:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F32923973039 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611765776; bh=Ki9Mn7jPnnmWe9dlQU1ct5nQf5+tVBNPKa9jCIOOMBw=; h=To:References:In-Reply-To:Subject:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=PDulHorIRXDZGkumFQT0KoCuzAOfeshCqQHrC6MN8AdtPaWzxDKSttVGPDYGI2O4t PS/Weu9mn5aymE0qbW3YNNBL58LQ7jvaC8LebJfqHW055KLEb0NYE7wCcAkAyKs2wo N0Izc/sWHE7NaS0iQtgqp34vKCggs94ik4YzrV0U= Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50052.outbound.protection.outlook.com [40.107.5.52]) by sourceware.org (Postfix) with ESMTPS id 6BA3A3896809 for ; Wed, 27 Jan 2021 16:42:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6BA3A3896809 Received: from AM6P192CA0004.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::17) by HE1PR0802MB2459.eurprd08.prod.outlook.com (2603:10a6:3:e1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.17; Wed, 27 Jan 2021 16:42:49 +0000 Received: from AM5EUR03FT042.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:83:cafe::f2) by AM6P192CA0004.outlook.office365.com (2603:10a6:209:83::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.16 via Frontend Transport; Wed, 27 Jan 2021 16:42:49 +0000 X-MS-Exchange-Authentication-Results: spf=temperror (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.org; dmarc=temperror action=none header.from=arm.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT042.mail.protection.outlook.com (10.152.17.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Wed, 27 Jan 2021 16:42:46 +0000 Received: ("Tessian outbound e989e14f9207:v71"); Wed, 27 Jan 2021 16:42:46 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 4ad0877cb24e9156 X-CR-MTA-TID: 64aa7808 Received: from 873694367653.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id EE47BD8A-6C26-4DE6-A95B-9423D8DF06FA.1; Wed, 27 Jan 2021 16:42:39 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 873694367653.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 27 Jan 2021 16:42:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hGAbHYajr6MsIlX1cjWL7PhXGCQWXmLKVKVeUUw2TCMLAY2DIOJXJkKx7EJxnMySsdPc5ty+xJBe7oTCjcu0ZMqVYzjaHiu36Rw/SAneCRKxx0Xtf6m/3RS3gR5Q7PEQlakdQ2pRdJCP8iFKpKmNfODSjvwm6QGuujmA5QAIxUdcX3Ooz2mi63b1afC/lhcxeDlYiKc3vui4/s0HSbGVKjOGqKEL5D9YXhzKoSkJVukKbthPOrmZKptj5BhAI5FoVePspXRid+IPy4qLcEHxNR1rpo7hM/jWZJ2LlNhvnwOuj9/jIjV7dFqbaG8yvl2RJG4m3otBllZgoTPjl1/Dzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ki9Mn7jPnnmWe9dlQU1ct5nQf5+tVBNPKa9jCIOOMBw=; b=RQrXSeWQWd3C7RINlxUGftZiEFFvDWzuyIW1PGTAS/kI2pc9zyFH3W/L59XQO022zCP3qGx/oi/VnWhdkJCqgnkKBj2oX0dBvaLWaptZuMSh1uR6uir2pXSYpq/ajpows1XTHlrDHH29uP29Ebg+errUDbRVeuLEC1EXojONCLZaUqzkY0VhbdvJ8wWa3yA30z25GDlAYD+YvcF6EKllRSXGAAoJNMiPNdbDjuG4mN9hurTEOdmY/YG6OdlpwCDCnQTJqdynYH/ALHaFtTO8yQ5Lo+I88uu/CIFONDcT6k1T/fIp2qBOPhybdubWZT0qRaO7EBzrGtDElk+RjgQ03g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3157.eurprd08.prod.outlook.com (2603:10a6:209:48::24) by AM6PR08MB4722.eurprd08.prod.outlook.com (2603:10a6:20b:c5::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.13; Wed, 27 Jan 2021 16:42:38 +0000 Received: from AM6PR08MB3157.eurprd08.prod.outlook.com ([fe80::4847:9e54:1f0a:b6cb]) by AM6PR08MB3157.eurprd08.prod.outlook.com ([fe80::4847:9e54:1f0a:b6cb%7]) with mapi id 15.20.3784.017; Wed, 27 Jan 2021 16:42:38 +0000 Content-Type: multipart/mixed; boundary="===============7089555208039546337==" To: Luis Machado References: <9226b8ae-aaea-65c3-3e86-f607b11fd375@linaro.org> <9EACDC38-BB8D-4804-AD19-057E3309819A@arm.com> <3d86bcb9-dedd-6eb2-7cff-e8349d4b20da@palves.net> <9efc84c3-d4fb-03d6-8612-600cc2f74e65@linaro.org> <4e5f7899-6a44-c18b-45ae-31228a6f5c20@arm.com> In-Reply-To: Subject: [Patch] GDB: aarch64: Add ability to displaced step over a BR/BLR instruction Date: Wed, 27 Jan 2021 16:42:30 +0000 X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: SA0PR11CA0055.namprd11.prod.outlook.com (2603:10b6:806:d0::30) To AM6PR08MB3157.eurprd08.prod.outlook.com (2603:10a6:209:48::24) Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from e120487-lin.cambridge.arm.com (217.140.106.55) by SA0PR11CA0055.namprd11.prod.outlook.com (2603:10b6:806:d0::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17 via Frontend Transport; Wed, 27 Jan 2021 16:42:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1feded86-4f48-414b-b8b4-08d8c2e293bf X-MS-TrafficTypeDiagnostic: AM6PR08MB4722:|HE1PR0802MB2459: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: rrwJFPi9S54LEfjcUFt7DViRCQNCZVc8c/BwKT5nByJuH9KM1jvS05LKRnnZiF+YC7VYqXVKyacvHzNHIuYJ8Z/vw+0BEM0nfx/REIPuAg36ONSR8KznP/a/ODQjzyZodO7zM4f48RJ3yosIaPPZLL02Z4AaXKd3kxbB+nG4QHojeP0GYUtWlMT28758qdF2Afw1e8bRiJTDc3lUH2H23/BfjsNSCuXSyE8OHFe4fno9DjqctFngdohrsrWPpi3cd1mOAPJS0M+wkE5K+3D517KVWz8Ny3E0wqAbD1/BeD1MjIE33ni6eSFcygjWCs6yyAHfsZcJgoZlUYVCTF0BEuMj6yvgAiXIBo0isF2hUKxJeTxeWKqnaINm5GOWsiJEuhYYZisiEZbD0ZECSH2XE4Ke8E4lSZ9eVa1vvjgRRVriPA1N/yDebCpAvhhkFWm01Zp+FFUcyd9JUtajM8CqJFOPL2pEHn+5ldGxltikJKVX3Tp8mxMPfd26GeOoxFbvCg2WQVuqNI6Wb7qOczC6LA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3157.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(396003)(346002)(39860400002)(136003)(26005)(52116002)(8676002)(83380400001)(956004)(6512007)(44832011)(66556008)(66616009)(66476007)(186003)(6666004)(316002)(66946007)(6916009)(5660300002)(235185007)(9686003)(54906003)(2906002)(33656002)(4326008)(52536014)(8936002)(478600001)(33964004)(16526019)(6486002)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?j9qy7saAtNS2QT+0pqGtrp5H0D65K9OwhI+kP1TiQXQhYU26d9882kVYIlA/?= =?us-ascii?Q?RGBAkZ6vw5XUlG9SNfvP5H5VwbYWvpuc1s2eZZ6FqXLIkxLEDijkkkCLFr9R?= =?us-ascii?Q?FBXaEpNXyTvlpasJHk92CZWhelpdKz9BElf6LcEEQJXPi/xelVFijzJJJIlM?= =?us-ascii?Q?pwsZR/o2yNYHnFa2FhwmZq0iyljP+IFiY2qrBFcsrRHLkqJdOTvxH1J+pyfi?= =?us-ascii?Q?EvBllO1TU0DVazSYiG2GIpgU1hu1dR4AWY2vFcWPYOJg5RMga7pqyHHrq0R4?= =?us-ascii?Q?+Df6j4uxvjCfLya6h1cHp8Cy3QypiyHUTEmN5hByTtYoaJ7nmPl4Pz1SrbVP?= =?us-ascii?Q?HltnjHGEYW5qRZVz5PWavx3AD9U4sbiWcAFEJDHb2Z9eUNemECU9k/NcN/bk?= =?us-ascii?Q?2md5aj9glaUgAgHv2Y/HE8vzkNOzaj757d8OmIOnroMpaY+0A4FR5OAk4Hbq?= =?us-ascii?Q?C6y0v7pqmd6DK0CsFYNcugYkBnXptkv4TpC0ShMIgcn5viXQXotOtQvVxq6Y?= =?us-ascii?Q?4DCT6eThV7HqJu386HyPOCERCu8dTzvEhhqx2VrsqezJbgzuX0lU22ozUapg?= =?us-ascii?Q?RGTAqz7QlLwrtXw/sI4JjmHkpsNO5pgikTayrD/qr630ykrqvbJFPrNkWdvK?= =?us-ascii?Q?Yc/VfLQsovudr6E9CtoYoreMslWLk/PE0TZyXob1FcITIIjHZpqezjRnLtDu?= =?us-ascii?Q?+zWZRLtSuztJoC5riNZ/7k2VfmuDBU+3YOfMZnkyJLik630oBlDfTPMutfwb?= =?us-ascii?Q?Jf2uE5FTfswvLnHqEgUULKytALNeeI3zYE3/jf+Ja5zjUb/oLlZd7aEBHk51?= =?us-ascii?Q?NEhLZxm7v+HRXCRGtNzNSiuG5H/7IochTDtIEknYq0CPDOj8exloq1bFgprn?= =?us-ascii?Q?WpvVCJ1LHy40agxSExT6CIlD7tEhKoLSMwaldHqxL6YgkfefTPTsXtxA6rjo?= =?us-ascii?Q?OpK80Avc5SJa/VFlvTgepYULmpqbK8C8zYt3+DZkC2ZOEUsE8MBgCWV6y1tn?= =?us-ascii?Q?tlNB2XgoPQ7StDh+HvgwSy3vOrzP9KSxQafRCUHSXbmze51YU4wh8EakAcL4?= =?us-ascii?Q?nPiUziVB?= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4722 Original-Authentication-Results: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT042.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: ad18bb97-4ea9-4992-ced4-08d8c2e28de7 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RqU/ZRFmyVM1TgBA5ziua4JK1mstJu/NcOAgR9UdvWeG80J5xzYqE6dcgMj2TDJG7l2rUYp/Yv/o1lti2MX1w3OL7Uu0XzA+Awy5mxVjisq5LGfwWIbMukvUJvdMqgt4+JBdwSkhRf2459JoBbrANQiIsW+RWZEKVIqFcgsW51XsrXZps7oVhvWQgNBLURx7yScHs4nD8HpwmabWAgfSurAw7vbfPFcSSGrmAXfMxmp73YFTJE7CPoF2XwL6N+pZws6zqFiZBB1rVciSTp5qYb7/oXAn34/gvVL9ZLX4sHf8a1W8IBIf1SPd7hpIlH4mAH6F7Y+jZhrsrfXMlSNh9g7bB0w6jEFnhzP1CASXuj70ddTy+qVbZ8AsseCNMg2qf52xLHNHYZGJm4VQh3s+BVxEIsqGRl6nKk6RhnHwuobUETbt97ynLN5Ax7PgBRYj0NztOCCSV8yPByZZ6ZiGbg== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(136003)(376002)(346002)(396003)(39860400002)(46966006)(6486002)(5660300002)(8936002)(86362001)(6512007)(44832011)(6862004)(478600001)(235185007)(4326008)(6666004)(47076005)(82310400003)(9686003)(8676002)(66616009)(81166007)(356005)(83380400001)(82740400003)(956004)(33964004)(26005)(316002)(63350400001)(16526019)(2906002)(186003)(70586007)(54906003)(336012)(63370400001)(70206006)(33656002)(52536014); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2021 16:42:46.9424 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1feded86-4f48-414b-b8b4-08d8c2e293bf X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT042.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2459 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Matthew Malcomson via Gdb-patches Reply-To: Matthew Malcomson Cc: nd , gdb-patches Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" --===============7089555208039546337== Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi Luis, Thanks for the catch on those linker errors. I managed to reproduce those errors using `-pie', and that seems to explain the error messages quite well. I've used the testcase in the updated patch attached and it seems to work for RUNTESTFLAGS="--target_board=native-gdbserver", RUNTESTFLAGS="--target_board=unix/-pie", and without a provided RUNTESTFLAGS on Ubuntu 16.04 (where no provided RUNTESTFLAGS compiles without PIE). Hopefully that testcase will be a bit more robust. Thanks, Matthew. ------ PROPOSED COMMIT MESSAGE Enable displaced stepping over a BR/BLR instruction Displaced stepping over an instruction executes a instruction in a scratch area and then manually fixes up the PC address to leave execution where it would have been if the instruction were in its original location. The BR instruction does not need modification in order to run correctly at a different address, but the displaced step fixup method should not manually adjust the PC since the BR instruction sets that value already. The BLR instruction should also avoid such a fixup, but must also have the link register modified to point to just after the original code location rather than back to the scratch location. This patch adds the above functionality. We add this functionality by modifying aarch64_displaced_step_others rather than by adding a new visitor method to aarch64_insn_visitor. We choose this since it seems that visitor approach is designed specifically for PC relative instructions (which must always be modified when executed in a different location). It seems that the BR and BLR instructions are more like the RET instruction which is already handled specially in aarch64_displaced_step_others. This also means the gdbserver code to relocate an instruction when creating a fast tracepoint does not need to be modified, since nothing special is needed for the BR and BLR instructions there. Regression tests showed nothing untoward on native aarch64 (though it took a while for me to get the testcase to account for PIE). ------##### Original observed (mis)behaviour before was that displaced stepping over a BR or BLR instruction would not execute the function they called. Most easily seen by putting a breakpoint with a condition on such an instruction and a print statement in the functions they called. When run with the breakpoint enabled the function is not called and "numargs called" is not printed. When run with the breakpoint disabled the function is called and the message is printed. --- GDB Session ~ [15:57:14] % gdb ../using-blr Reading symbols from ../using-blr...done. (gdb) disassemble blr_call_value Dump of assembler code for function blr_call_value: ... 0x0000000000400560 <+28>: blr x2 ... 0x00000000004005b8 <+116>: ret End of assembler dump. (gdb) break *0x0000000000400560 Breakpoint 1 at 0x400560: file ../using-blr.c, line 22. (gdb) condition 1 10 == 0 (gdb) run Starting program: /home/matmal01/using-blr [Inferior 1 (process 33279) exited with code 012] (gdb) disable 1 (gdb) run Starting program: /home/matmal01/using-blr numargs called [Inferior 1 (process 33289) exited with code 012] (gdb) Test program: ---- using-blr ---- \#include typedef int (foo) (int, int); typedef void (bar) (int, int); struct sls_testclass { foo *x; bar *y; int left; int right; }; __attribute__ ((noinline)) int blr_call_value (struct sls_testclass x) { int retval = x.x(x.left, x.right); if (retval % 10) return 100; return 9; } __attribute__ ((noinline)) int blr_call (struct sls_testclass x) { x.y(x.left, x.right); if (x.left % 10) return 100; return 9; } int numargs (__attribute__ ((unused)) int left, __attribute__ ((unused)) int right) { printf("numargs called\n"); return 10; } void altfunc (__attribute__ ((unused)) int left, __attribute__ ((unused)) int right) { printf("altfunc called\n"); } int main(int argc, char **argv) { struct sls_testclass x = { .x = numargs, .y = altfunc, .left = 1, .right = 2 }; if (argc > 2) { blr_call (x); } else blr_call_value (x); return 10; } ------ gdb/ChangeLog: 2020-08-19 Matthew Malcomson * aarch64-tdep.c (aarch64_displaced_step_others): Account for BLR and BR instructions. * arch/aarch64-insn.h (enum aarch64_opcodes): Add BR opcode. (enum aarch64_masks): New. gdb/testsuite/ChangeLog: 2020-08-19 Matthew Malcomson * gdb.arch/insn-reloc.c: Add tests for BR and BLR. ############### Attachment also inlined for ease of reply ############### diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index d1e15497a46ca250d606f4da77ad653fecc41e1c..3ac0564dd9a1bf01a7df60059b3a7b353e3b042f 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -3099,15 +3099,22 @@ aarch64_displaced_step_others (const uint32_t insn, struct aarch64_displaced_step_data *dsd = (struct aarch64_displaced_step_data *) data; - aarch64_emit_insn (dsd->insn_buf, insn); - dsd->insn_count = 1; - - if ((insn & 0xfffffc1f) == 0xd65f0000) + uint32_t masked_insn = (insn & CLEAR_Rn_MASK); + if (masked_insn == BLR) { - /* RET */ - dsd->dsc->pc_adjust = 0; + /* Emit a BR to the same register and then update LR to the original + address (similar to aarch64_displaced_step_b). */ + aarch64_emit_insn (dsd->insn_buf, insn & 0xffdfffff); + regcache_cooked_write_unsigned (dsd->regs, AARCH64_LR_REGNUM, + data->insn_addr + 4); } else + aarch64_emit_insn (dsd->insn_buf, insn); + dsd->insn_count = 1; + + if (masked_insn == RET || masked_insn == BR || masked_insn == BLR) + dsd->dsc->pc_adjust = 0; + else dsd->dsc->pc_adjust = 4; } diff --git a/gdb/arch/aarch64-insn.h b/gdb/arch/aarch64-insn.h index 1e8c5eac940ee017f4b6d2685bbcbaeed0617e3a..87e2f5875a133a347c4be48b255a04282647be12 100644 --- a/gdb/arch/aarch64-insn.h +++ b/gdb/arch/aarch64-insn.h @@ -61,7 +61,9 @@ enum aarch64_opcodes CBNZ = 0x21000000 | B, TBZ = 0x36000000 | B, TBNZ = 0x37000000 | B, + /* BR 1101 0110 0001 1111 0000 00rr rrr0 0000 */ /* BLR 1101 0110 0011 1111 0000 00rr rrr0 0000 */ + BR = 0xd61f0000, BLR = 0xd63f0000, /* RET 1101 0110 0101 1111 0000 00rr rrr0 0000 */ RET = 0xd65f0000, @@ -128,6 +130,14 @@ enum aarch64_opcodes NOP = (0 << 5) | HINT, }; +/* List of useful masks. */ +enum aarch64_masks +{ + /* Used for masking out an Rn argument from an opcode. */ + CLEAR_Rn_MASK = 0xfffffc1f, +}; + + /* Representation of a general purpose register of the form xN or wN. This type is used by emitting functions that take registers as operands. */ diff --git a/gdb/testsuite/gdb.arch/insn-reloc.c b/gdb/testsuite/gdb.arch/insn-reloc.c index bfbb3161b3aa3dcf8a5ff00e4341c4d68e473f26..62f13a9275439c8e2abdedd5cfbd88d06d863d03 100644 --- a/gdb/testsuite/gdb.arch/insn-reloc.c +++ b/gdb/testsuite/gdb.arch/insn-reloc.c @@ -512,6 +512,84 @@ can_relocate_bl (void) : : : "x30"); /* Test that LR is updated correctly. */ } +/* Make sure we can relocate a BR instruction. + + ... Set x0 to target + set_point12: + BR x0 ; jump to target (tracepoint here). + fail() + return + target: + pass() + end + + */ + +static void +can_relocate_br (void) +{ + int ok = 0; + + asm goto (" adr x0, %l0\n" + "set_point12:\n" + " br x0\n" + : + : + : "x0" + : madejump); + + fail (); + return; +madejump: + pass (); +} + +/* Make sure we can relocate a BLR instruction. + + We use two different functions since the test runner expects one breakpoint + per function and we want to test two different things. + For BLR we want to test that the BLR actually jumps to the relevant + function, *and* that it sets the LR register correctly. + + Hence we create one testcase that jumps to `pass` using BLR, and one + testcase that jumps to `pass` if BLR has set the LR correctly. + + -- can_relocate_blr_jumps + ... Set x0 to pass + set_point13: + BLR x0 ; jump to pass (tracepoint here). + + -- can_relocate_blr_sets_lr + ... Set x0 to foo + set_point14: + BLR x0 ; jumps somewhere else (tracepoint here). + BL pass ; ensures the LR was set correctly by the BLR. + + */ + +static void +can_relocate_blr_jumps (void) +{ + int ok = 0; + + /* Test BLR indeed jumps to the target. */ + asm ("set_point13:\n" + " blr %[address]\n" + : : [address] "r" (&pass) : "x30"); +} + +static void +can_relocate_blr_sets_lr (void) +{ + int ok = 0; + + /* Test BLR sets the LR correctly. */ + asm ("set_point14:\n" + " blr %[address]\n" + " bl pass\n" + : : [address] "r" (&foo) : "x30"); +} + #endif /* Functions testing relocations need to be placed here. GDB will read @@ -536,6 +614,9 @@ static testcase_ftype testcases[] = { can_relocate_ldr, can_relocate_bcond_false, can_relocate_bl, + can_relocate_br, + can_relocate_blr_jumps, + can_relocate_blr_sets_lr, #endif }; --===============7089555208039546337== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="blr-pie-able-testcase.patch" ZGlmZiAtLWdpdCBhL2dkYi9hYXJjaDY0LXRkZXAuYyBiL2dkYi9hYXJjaDY0LXRkZXAuYwppbmRl eCBkMWUxNTQ5N2E0NmNhMjUwZDYwNmY0ZGE3N2FkNjUzZmVjYzQxZTFjLi4zYWMwNTY0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IFRlc3QgdGhhdCBMUiBpcyB1cGRhdGVkIGNvcnJlY3RseS4g ICovCiB9CiAKKy8qIE1ha2Ugc3VyZSB3ZSBjYW4gcmVsb2NhdGUgYSBCUiBpbnN0cnVjdGlvbi4K KworICAgICAuLi4gU2V0IHgwIHRvIHRhcmdldAorICAgc2V0X3BvaW50MTI6CisgICAgIEJSIHgw IDsganVtcCB0byB0YXJnZXQgKHRyYWNlcG9pbnQgaGVyZSkuCisgICAgIGZhaWwoKQorICAgICBy ZXR1cm4KKyAgIHRhcmdldDoKKyAgICAgcGFzcygpCisgICBlbmQKKworICAgKi8KKworc3RhdGlj IHZvaWQKK2Nhbl9yZWxvY2F0ZV9iciAodm9pZCkKK3sKKyAgaW50IG9rID0gMDsKKworICBhc20g Z290byAoIiAgYWRyIHgwLCAlbDBcbiIKKyAgICAgICAgICAgICJzZXRfcG9pbnQxMjpcbiIKKyAg ICAgICAgICAgICIgIGJyIHgwXG4iCisgICAgICAgICAgICA6CisgICAgICAgICAgICA6CisgICAg ICAgICAgICA6ICJ4MCIKKyAgICAgICAgICAgIDogbWFkZWp1bXApOworCisgIGZhaWwgKCk7Cisg IHJldHVybjsKK21hZGVqdW1wOgorICBwYXNzICgpOworfQorCisvKiBNYWtlIHN1cmUgd2UgY2Fu IHJlbG9jYXRlIGEgQkxSIGluc3RydWN0aW9uLgorCisgICBXZSB1c2UgdHdvIGRpZmZlcmVudCBm dW5jdGlvbnMgc2luY2UgdGhlIHRlc3QgcnVubmVyIGV4cGVjdHMgb25lIGJyZWFrcG9pbnQKKyAg IHBlciBmdW5jdGlvbiBhbmQgd2Ugd2FudCB0byB0ZXN0IHR3byBkaWZmZXJlbnQgdGhpbmdzLgor ICAgRm9yIEJMUiB3ZSB3YW50IHRvIHRlc3QgdGhhdCB0aGUgQkxSIGFjdHVhbGx5IGp1bXBzIHRv IHRoZSByZWxldmFudAorICAgZnVuY3Rpb24sICphbmQqIHRoYXQgaXQgc2V0cyB0aGUgTFIgcmVn aXN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V0X3BvaW50MTQ6XG4iCisgICAgICAg IiAgYmxyICVbYWRkcmVzc11cbiIKKyAgICAgICAiICBibCBwYXNzXG4iCisgICAgICAgOiA6IFth ZGRyZXNzXSAiciIgKCZmb28pIDogIngzMCIpOworfQorCiAjZW5kaWYKIAogLyogRnVuY3Rpb25z IHRlc3RpbmcgcmVsb2NhdGlvbnMgbmVlZCB0byBiZSBwbGFjZWQgaGVyZS4gIEdEQiB3aWxsIHJl YWQKQEAgLTUzNiw2ICs2MTQsOSBAQCBzdGF0aWMgdGVzdGNhc2VfZnR5cGUgdGVzdGNhc2VzW10g PSB7CiAgIGNhbl9yZWxvY2F0ZV9sZHIsCiAgIGNhbl9yZWxvY2F0ZV9iY29uZF9mYWxzZSwKICAg Y2FuX3JlbG9jYXRlX2JsLAorICBjYW5fcmVsb2NhdGVfYnIsCisgIGNhbl9yZWxvY2F0ZV9ibHJf anVtcHMsCisgIGNhbl9yZWxvY2F0ZV9ibHJfc2V0c19sciwKICNlbmRpZgogfTsKIAoK --===============7089555208039546337==--