From patchwork Wed Mar 11 12:10:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 45627 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 57A34214BF for ; Wed, 11 Mar 2015 12:10:32 +0000 (UTC) Received: by lbvp9 with SMTP id p9sf6363142lbv.0 for ; Wed, 11 Mar 2015 05:10:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:mailing-list :precedence:list-id:list-unsubscribe:list-subscribe:list-archive :list-post:list-help:sender:delivered-to:from:to:subject:date :message-id:x-original-sender:x-original-authentication-results; bh=t7Oqj7ppZ7/vmpPHThX2vIJ7HXW9VeLJY7tkeo0rehs=; b=FRhaK5nAoWspPmLAjLCf47dPqWYDr6MHXnJGHfK7jFO5Z5lb4djd8fuCY96J0i3Ydk z87IWA/fs8XIVRIecJKCVJole2F/mUea+DIw+Gnzr160vXO2ERl3a3KIJeAZhPI3Owzs c6+Vu62Z0QRvz1D6yy3UDVGec9p/Ue9O0+7H0+/m/q2y57mf4BzS54g1A9zhKJGQx0SB lMvBnaXZ6i1d1rFjXUZB+FcDEsHb39MxgMuNaMXQ0iTA+AtIaJPrh0c6cL8RJ2rInYwb mhYFsSYP/5bE+9qQEvyInd7GRiaTUZkKYWsEde75RTPtlkzQLnDvqi2zGAcsey9jgls8 yGEA== X-Gm-Message-State: ALoCoQmbtGFHI7TbikGnod+Rf4/S1mLe38iIWtSC5a3k3+BTx25Vgc/g4PSEOVtkEk7kGtudzzaB X-Received: by 10.112.9.65 with SMTP id x1mr5524546lba.16.1426075831219; Wed, 11 Mar 2015 05:10:31 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.137 with SMTP id z9ls136051laa.15.gmail; Wed, 11 Mar 2015 05:10:31 -0700 (PDT) X-Received: by 10.152.6.34 with SMTP id x2mr29034249lax.47.1426075831064; Wed, 11 Mar 2015 05:10:31 -0700 (PDT) Received: from mail-lb0-x230.google.com (mail-lb0-x230.google.com. [2a00:1450:4010:c04::230]) by mx.google.com with ESMTPS id 7si2183407lai.138.2015.03.11.05.10.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 05:10:30 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::230 as permitted sender) client-ip=2a00:1450:4010:c04::230; Received: by lbvn10 with SMTP id n10so8386442lbv.1 for ; Wed, 11 Mar 2015 05:10:30 -0700 (PDT) X-Received: by 10.112.212.106 with SMTP id nj10mr15753859lbc.36.1426075830615; Wed, 11 Mar 2015 05:10:30 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp2734208lbj; Wed, 11 Mar 2015 05:10:29 -0700 (PDT) X-Received: by 10.42.206.203 with SMTP id fv11mr39979952icb.72.1426075828751; Wed, 11 Mar 2015 05:10:28 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id ro12si4873629pab.108.2015.03.11.05.10.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 05:10:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-return-120617-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 4642 invoked by alias); 11 Mar 2015 12:10:19 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 4626 invoked by uid 89); 11 Mar 2015 12:10:16 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_FROM_URIBL_PCCC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-pa0-f53.google.com Received: from mail-pa0-f53.google.com (HELO mail-pa0-f53.google.com) (209.85.220.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 11 Mar 2015 12:10:14 +0000 Received: by padfb1 with SMTP id fb1so10973046pad.7 for ; Wed, 11 Mar 2015 05:10:12 -0700 (PDT) X-Received: by 10.70.129.10 with SMTP id ns10mr29396662pdb.87.1426075812564; Wed, 11 Mar 2015 05:10:12 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by mx.google.com with ESMTPSA id x4sm5820008pas.40.2015.03.11.05.10.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Mar 2015 05:10:11 -0700 (PDT) From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH] Support catch syscall on aarch64 linux Date: Wed, 11 Mar 2015 12:10:08 +0000 Message-Id: <1426075808-25289-1-git-send-email-qiyaoltc@gmail.com> X-IsSubscribed: yes X-Original-Sender: qiyaoltc@gmail.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::230 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com X-Google-Group-Id: 836684582541 From: Yao Qi Hi, This patch is to support catch syscall on aarch64 linux. We implement gdbarch method get_syscall_number for aarch64-linux, and add aarch64-linux.xml file, which looks straightforward, however the changes to test case doesn't. First of all, we enable catch-syscall.exp on aarch64-linux target, but skip the multi_arch testing on current stage. I plan to touch multi arch debugging on aarch64-linux later. Then, when I run catch-syscall.exp on aarch64-linux, gcc errors that SYS_pipe isn't defined. We find that aarch64 kernel only has pipe2 syscall and libc already convert pipe to pipe2. As a result, I change catch-syscall.c to use SYS_pipe if it is defined, otherwise use SYS_pipe2 instead. The vector all_syscalls in catch-syscall.exp can't be pre-determined, so I add a new proc setup_all_syscalls to fill it, according to the availability of SYS_pipe. Regression tested on {x86_64, aarch64}-linux x {native, gdbserver}. gdb: 2015-03-11 Yao Qi PR tdep/18107 * aarch64-linux-tdep.c: Include xml-syscall.h (aarch64_linux_get_syscall_number): New function. (aarch64_linux_init_abi): Call set_gdbarch_get_syscall_number. * syscalls/aarch64-linux.xml: New file. gdb/testsuite: 2015-03-11 Yao Qi PR tdep/18107 * gdb.base/catch-syscall.c [!SYS_pipe] (pipe2_syscall): New variable. * gdb.base/catch-syscall.exp: Don't skip it on aarch64*-*-linux* target. Remove elements in all_syscalls. (test_catch_syscall_multi_arch): Skip it on aarch64*-linux* target. (setup_all_syscalls): New proc. --- gdb/aarch64-linux-tdep.c | 27 +++ gdb/syscalls/aarch64-linux.xml | 271 +++++++++++++++++++++++++++++++ gdb/testsuite/gdb.base/catch-syscall.c | 4 + gdb/testsuite/gdb.base/catch-syscall.exp | 41 ++++- 4 files changed, 339 insertions(+), 4 deletions(-) create mode 100644 gdb/syscalls/aarch64-linux.xml diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 1e1ca36..0ee5ecb 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -39,6 +39,7 @@ #include "stap-probe.h" #include "parser-defs.h" #include "user-regs.h" +#include "xml-syscall.h" #include /* Signal frame handling. @@ -341,6 +342,28 @@ 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, + ptid_t ptid) +{ + struct regcache *regs = get_thread_regcache (ptid); + 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. */ + regcache_cooked_read (regs, AARCH64_DWARF_X0 + 8, buf); + + ret = extract_signed_integer (buf, X_REGISTER_SIZE, byte_order); + + return ret; +} + static void aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { @@ -385,6 +408,10 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_stap_is_single_operand (gdbarch, aarch64_stap_is_single_operand); set_gdbarch_stap_parse_special_token (gdbarch, aarch64_stap_parse_special_token); + + /* `catch syscall' */ + set_xml_syscall_file_name (gdbarch, "syscalls/aarch64-linux.xml"); + set_gdbarch_get_syscall_number (gdbarch, aarch64_linux_get_syscall_number); } /* Provide a prototype to silence -Wmissing-prototypes. */ diff --git a/gdb/syscalls/aarch64-linux.xml b/gdb/syscalls/aarch64-linux.xml new file mode 100644 index 0000000..537d789 --- /dev/null +++ b/gdb/syscalls/aarch64-linux.xml @@ -0,0 +1,271 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gdb/testsuite/gdb.base/catch-syscall.c b/gdb/testsuite/gdb.base/catch-syscall.c index ea33b93..4d0131c 100644 --- a/gdb/testsuite/gdb.base/catch-syscall.c +++ b/gdb/testsuite/gdb.base/catch-syscall.c @@ -21,7 +21,11 @@ int chroot_syscall = SYS_chroot; restart_syscall, which can't be called from userspace. However, the "read" syscall is zero on x86_64. */ int read_syscall = SYS_read; +#ifdef SYS_pipe int pipe_syscall = SYS_pipe; +#else +int pipe2_syscall = SYS_pipe2; +#endif int write_syscall = SYS_write; int exit_group_syscall = SYS_exit_group; diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp index 29e8109..df0004a 100644 --- a/gdb/testsuite/gdb.base/catch-syscall.exp +++ b/gdb/testsuite/gdb.base/catch-syscall.exp @@ -29,7 +29,7 @@ if { ![istarget "x86_64-*-linux*"] && ![istarget "i\[34567\]86-*-linux*"] && ![istarget "powerpc-*-linux*"] && ![istarget "powerpc64-*-linux*"] && ![istarget "sparc-*-linux*"] && ![istarget "sparc64-*-linux*"] && ![istarget "mips*-linux*"] && ![istarget "arm*-linux*"] - && ![istarget "s390*-linux*"] } { + && ![istarget "s390*-linux*"] && ![istarget "aarch64*-*-linux*"] } { continue } @@ -40,9 +40,9 @@ if { [prepare_for_testing ${testfile}.exp $testfile ${testfile}.c] } { return -1 } -# All (but the last) syscalls from the example code -# They are ordered according to the file, so do not change this. -set all_syscalls { "close" "chroot" "pipe" "write" "read" } +# All (but the last) syscalls from the example code. It is filled in +# proc setup_all_syscalls. +set all_syscalls { } set all_syscalls_numbers { } # The last syscall (exit()) does not return, so @@ -402,6 +402,9 @@ proc test_catch_syscall_multi_arch {} { # catch syscall supports only 32-bit ARM for now. verbose "Not testing ARM for multi-arch syscall support" return + } elseif { [istarget "aarch64*-linux*"] } { + verbose "Not testing AARCH64 for multi-arch syscall support" + return } elseif { [istarget "s390*-linux*"] } { set arch1 "s390:31-bit" set arch2 "s390:64-bit" @@ -469,6 +472,36 @@ proc fill_all_syscalls_numbers {} { set last_syscall_number [get_integer_valueof "exit_group_syscall" -1] } +# Set up the vector all_syscalls. + +proc setup_all_syscalls {} { + global all_syscalls + global gdb_prompt + + # They are ordered according to the file, so do not change this. + lappend all_syscalls "close" + lappend all_syscalls "chroot" + + # SYS_pipe doesn't exist on aarch64 kernel. + set test "check SYS_pipe" + gdb_test_multiple "p pipe_syscall" $test { + -re " = .*$gdb_prompt $" { + pass $test + lappend all_syscalls "pipe" + } + -re "No symbol .*$gdb_prompt $" { + pass $test + # SYS_pipe isn't defined, use SYS_pipe2 instead. + lappend all_syscalls "pipe2" + } + } + + lappend all_syscalls "write" + lappend all_syscalls "read" +} + +setup_all_syscalls + # Fill all the syscalls numbers before starting anything. fill_all_syscalls_numbers