From patchwork Tue Jan 22 11:15:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 31161 Received: (qmail 86019 invoked by alias); 22 Jan 2019 11:15:39 -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 85828 invoked by uid 89); 22 Jan 2019 11:15:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=retrieve X-HELO: EUR01-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr140054.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (40.107.14.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Jan 2019 11:15:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=olKVuZ6qHslsc/WN/NIOi4sfsUWqY79rCuU72ojHJhE=; b=d6E2OcaHOQ3XBbthwgEAyHzN+fD9ZqJjN/n89Afgm+6mfpoDyIxABvePWfrrS8GGiVxdn8YT8F3x6RfjrYDc4Ef1zeqEZZZQ97Mo1Gg6W3CosN9r8I5Wd9rtLuROxRNQdiTenaAgt4ivZecB7hPpnmwa22GeJyK4sRfpx3DdUGg= Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com (10.172.227.22) by DB6PR0802MB2325.eurprd08.prod.outlook.com (10.172.227.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1537.27; Tue, 22 Jan 2019 11:15:05 +0000 Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::acd7:a958:2aaa:562e]) by DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::acd7:a958:2aaa:562e%5]) with mapi id 15.20.1537.031; Tue, 22 Jan 2019 11:15:05 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd , Alan Hayward Subject: [PATCH] AArch64: Detect exit from execve syscall Date: Tue, 22 Jan 2019 11:15:05 +0000 Message-ID: <20190122111457.6589-1-alan.hayward@arm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 MIME-Version: 1.0 X-IsSubscribed: yes Checking the syscall number when stopped on entry/exit relies on checking the value in register X8. However, on exit from an execve syscall, the registers will all be cleared. Given this is only checked on syscall entry/exit, then a cleared register state either means execve exit or syscall 0 (io_setup) entry with invalid parameters and an invalid FR and LR, which in reality should never happen. Use this to detect execve exit. Move function to allow use of aarch64_sys_execve enum, and use newer regcache functions. Fixes gdb.base/catch-syscall.exp on Aarch64. gdb/ChangeLog: 2019-01-22 Alan Hayward * aarch64-linux-tdep.c (aarch64_linux_get_syscall_number): Check for execve. --- gdb/aarch64-linux-tdep.c | 56 ++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 62cfc76c82..39e607658f 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -757,28 +757,6 @@ aarch64_stap_parse_special_token (struct gdbarch *gdbarch, return 1; } -/* Implement the "get_syscall_number" gdbarch method. */ - -static LONGEST -aarch64_linux_get_syscall_number (struct gdbarch *gdbarch, - thread_info *thread) -{ - struct regcache *regs = get_thread_regcache (thread); - enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - - /* The content of register x8. */ - gdb_byte buf[X_REGISTER_SIZE]; - /* The result. */ - LONGEST ret; - - /* Getting the system call number from the register x8. */ - regs->cooked_read (AARCH64_DWARF_X0 + 8, buf); - - ret = extract_signed_integer (buf, X_REGISTER_SIZE, byte_order); - - return ret; -} - /* AArch64 process record-replay constructs: syscall, signal etc. */ struct linux_record_tdep aarch64_linux_record_tdep; @@ -1334,6 +1312,40 @@ aarch64_canonicalize_syscall (enum aarch64_syscall syscall_number) } } +/* Retrieve the syscall number at a ptrace syscall-stop, either on syscall entry + or exit. Return -1 upon error. */ + +static LONGEST +aarch64_linux_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread) +{ + struct regcache *regs = get_thread_regcache (thread); + LONGEST ret; + + /* Get the system call number from register x8. */ + regs->cooked_read (AARCH64_X0_REGNUM + 8, &ret); + + /* On exit from a successful execve, we will be in a new process and all the + registers will be cleared - x0 to x30 will be 0, except for a 1 in x7. + This function will only ever get called when stopped at the entry or exit + of a syscall, so by checking for 0 in x0 (arg0/retval), x1 (arg1), x8 + (syscall), x29 (FP) and x30 (LR) we can infer: + 1) Either inferior is at exit from sucessful execve. + 2) Or inferior is at entry to a call to io_setup with invalid arguments and + a corrupted FP and LR. + It should be safe enough to assume case 1. */ + if (ret == 0) + { + LONGEST x1 = -1, fp = -1, lr = -1; + regs->cooked_read (AARCH64_X0_REGNUM + 1, &x1); + regs->cooked_read (AARCH64_FP_REGNUM, &fp); + regs->cooked_read (AARCH64_LR_REGNUM, &lr); + if (x1 == 0 && fp ==0 && lr == 0) + return aarch64_sys_execve; + } + + return ret; +} + /* Record all registers but PC register for process-record. */ static int