diff mbox

Support catch syscall on aarch64 linux

Message ID 1426075808-25289-1-git-send-email-qiyaoltc@gmail.com
State New
Headers show

Commit Message

Yao Qi March 11, 2015, 12:10 p.m. UTC
From: Yao Qi <yao.qi@linaro.org>

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  <yao.qi@linaro.org>

	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  <yao.qi@linaro.org>

	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 mbox

Patch

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 <ctype.h>
 
 /* 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 @@ 
+<?xml version="1.0"?>
+<!-- Copyright (C) 2015 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  This file is offered as-is,
+     without any warranty. -->
+
+<!DOCTYPE feature SYSTEM "gdb-syscalls.dtd">
+
+<syscalls_info>
+  <syscall name="io_setup" number="0"/>
+  <syscall name="io_destroy" number="1"/>
+  <syscall name="io_submit" number="2"/>
+  <syscall name="io_cancel" number="3"/>
+  <syscall name="io_getevents" number="4"/>
+  <syscall name="setxattr" number="5"/>
+  <syscall name="lsetxattr" number="6"/>
+  <syscall name="fsetxattr" number="7"/>
+  <syscall name="getxattr" number="8"/>
+  <syscall name="lgetxattr" number="9"/>
+  <syscall name="fgetxattr" number="10"/>
+  <syscall name="listxattr" number="11"/>
+  <syscall name="llistxattr" number="12"/>
+  <syscall name="flistxattr" number="13"/>
+  <syscall name="removexattr" number="14"/>
+  <syscall name="lremovexattr" number="15"/>
+  <syscall name="fremovexattr" number="16"/>
+  <syscall name="getcwd" number="17"/>
+  <syscall name="lookup_dcookie" number="18"/>
+  <syscall name="eventfd2" number="19"/>
+  <syscall name="epoll_create1" number="20"/>
+  <syscall name="epoll_ctl" number="21"/>
+  <syscall name="epoll_pwait" number="22"/>
+  <syscall name="dup" number="23"/>
+  <syscall name="dup3" number="24"/>
+  <syscall name="fcntl" number="25"/>
+  <syscall name="inotify_init1" number="26"/>
+  <syscall name="inotify_add_watch" number="27"/>
+  <syscall name="inotify_rm_watch" number="28"/>
+  <syscall name="ioctl" number="29"/>
+  <syscall name="ioprio_set" number="30"/>
+  <syscall name="ioprio_get" number="31"/>
+  <syscall name="flock" number="32"/>
+  <syscall name="mknodat" number="33"/>
+  <syscall name="mkdirat" number="34"/>
+  <syscall name="unlinkat" number="35"/>
+  <syscall name="symlinkat" number="36"/>
+  <syscall name="linkat" number="37"/>
+  <syscall name="renameat" number="38"/>
+  <syscall name="umount2" number="39"/>
+  <syscall name="mount" number="40"/>
+  <syscall name="pivot_root" number="41"/>
+  <syscall name="nfsservctl" number="42"/>
+  <syscall name="statfs" number="43"/>
+  <syscall name="fstatfs" number="44"/>
+  <syscall name="truncate" number="45"/>
+  <syscall name="ftruncate" number="46"/>
+  <syscall name="fallocate" number="47"/>
+  <syscall name="faccessat" number="48"/>
+  <syscall name="chdir" number="49"/>
+  <syscall name="fchdir" number="50"/>
+  <syscall name="chroot" number="51"/>
+  <syscall name="fchmod" number="52"/>
+  <syscall name="fchmodat" number="53"/>
+  <syscall name="fchownat" number="54"/>
+  <syscall name="fchown" number="55"/>
+  <syscall name="openat" number="56"/>
+  <syscall name="close" number="57"/>
+  <syscall name="vhangup" number="58"/>
+  <syscall name="pipe2" number="59"/>
+  <syscall name="quotactl" number="60"/>
+  <syscall name="getdents64" number="61"/>
+  <syscall name="lseek" number="62"/>
+  <syscall name="read" number="63"/>
+  <syscall name="write" number="64"/>
+  <syscall name="readv" number="65"/>
+  <syscall name="writev" number="66"/>
+  <syscall name="pread64" number="67"/>
+  <syscall name="pwrite64" number="68"/>
+  <syscall name="preadv" number="69"/>
+  <syscall name="pwritev" number="70"/>
+  <syscall name="sendfile" number="71"/>
+  <syscall name="pselect6" number="72"/>
+  <syscall name="ppoll" number="73"/>
+  <syscall name="signalfd4" number="74"/>
+  <syscall name="vmsplice" number="75"/>
+  <syscall name="splice" number="76"/>
+  <syscall name="tee" number="77"/>
+  <syscall name="readlinkat" number="78"/>
+  <syscall name="newfstatat" number="79"/>
+  <syscall name="fstat" number="80"/>
+  <syscall name="sync" number="81"/>
+  <syscall name="fsync" number="82"/>
+  <syscall name="fdatasync" number="83"/>
+  <syscall name="sync_file_range" number="84"/>
+  <syscall name="timerfd_create" number="85"/>
+  <syscall name="timerfd_settime" number="86"/>
+  <syscall name="timerfd_gettime" number="87"/>
+  <syscall name="utimensat" number="88"/>
+  <syscall name="acct" number="89"/>
+  <syscall name="capget" number="90"/>
+  <syscall name="capset" number="91"/>
+  <syscall name="personality" number="92"/>
+  <syscall name="exit" number="93"/>
+  <syscall name="exit_group" number="94"/>
+  <syscall name="waitid" number="95"/>
+  <syscall name="set_tid_address" number="96"/>
+  <syscall name="unshare" number="97"/>
+  <syscall name="futex" number="98"/>
+  <syscall name="set_robust_list" number="99"/>
+  <syscall name="get_robust_list" number="100"/>
+  <syscall name="nanosleep" number="101"/>
+  <syscall name="getitimer" number="102"/>
+  <syscall name="setitimer" number="103"/>
+  <syscall name="kexec_load" number="104"/>
+  <syscall name="init_module" number="105"/>
+  <syscall name="delete_module" number="106"/>
+  <syscall name="timer_create" number="107"/>
+  <syscall name="timer_gettime" number="108"/>
+  <syscall name="timer_getoverrun" number="109"/>
+  <syscall name="timer_settime" number="110"/>
+  <syscall name="timer_delete" number="111"/>
+  <syscall name="clock_settime" number="112"/>
+  <syscall name="clock_gettime" number="113"/>
+  <syscall name="clock_getres" number="114"/>
+  <syscall name="clock_nanosleep" number="115"/>
+  <syscall name="syslog" number="116"/>
+  <syscall name="ptrace" number="117"/>
+  <syscall name="sched_setparam" number="118"/>
+  <syscall name="sched_setscheduler" number="119"/>
+  <syscall name="sched_getscheduler" number="120"/>
+  <syscall name="sched_getparam" number="121"/>
+  <syscall name="sched_setaffinity" number="122"/>
+  <syscall name="sched_getaffinity" number="123"/>
+  <syscall name="sched_yield" number="124"/>
+  <syscall name="sched_get_priority_max" number="125"/>
+  <syscall name="sched_get_priority_min" number="126"/>
+  <syscall name="sched_rr_get_interval" number="127"/>
+  <syscall name="restart_syscall" number="128"/>
+  <syscall name="kill" number="129"/>
+  <syscall name="tkill" number="130"/>
+  <syscall name="tgkill" number="131"/>
+  <syscall name="sigaltstack" number="132"/>
+  <syscall name="rt_sigsuspend" number="133"/>
+  <syscall name="rt_sigaction" number="134"/>
+  <syscall name="rt_sigprocmask" number="135"/>
+  <syscall name="rt_sigpending" number="136"/>
+  <syscall name="rt_sigtimedwait" number="137"/>
+  <syscall name="rt_sigqueueinfo" number="138"/>
+  <syscall name="rt_sigreturn" number="139"/>
+  <syscall name="setpriority" number="140"/>
+  <syscall name="getpriority" number="141"/>
+  <syscall name="reboot" number="142"/>
+  <syscall name="setregid" number="143"/>
+  <syscall name="setgid" number="144"/>
+  <syscall name="setreuid" number="145"/>
+  <syscall name="setuid" number="146"/>
+  <syscall name="setresuid" number="147"/>
+  <syscall name="getresuid" number="148"/>
+  <syscall name="setresgid" number="149"/>
+  <syscall name="getresgid" number="150"/>
+  <syscall name="setfsuid" number="151"/>
+  <syscall name="setfsgid" number="152"/>
+  <syscall name="times" number="153"/>
+  <syscall name="setpgid" number="154"/>
+  <syscall name="getpgid" number="155"/>
+  <syscall name="getsid" number="156"/>
+  <syscall name="setsid" number="157"/>
+  <syscall name="getgroups" number="158"/>
+  <syscall name="setgroups" number="159"/>
+  <syscall name="uname" number="160"/>
+  <syscall name="sethostname" number="161"/>
+  <syscall name="setdomainname" number="162"/>
+  <syscall name="getrlimit" number="163"/>
+  <syscall name="setrlimit" number="164"/>
+  <syscall name="getrusage" number="165"/>
+  <syscall name="umask" number="166"/>
+  <syscall name="prctl" number="167"/>
+  <syscall name="getcpu" number="168"/>
+  <syscall name="gettimeofday" number="169"/>
+  <syscall name="settimeofday" number="170"/>
+  <syscall name="adjtimex" number="171"/>
+  <syscall name="getpid" number="172"/>
+  <syscall name="getppid" number="173"/>
+  <syscall name="getuid" number="174"/>
+  <syscall name="geteuid" number="175"/>
+  <syscall name="getgid" number="176"/>
+  <syscall name="getegid" number="177"/>
+  <syscall name="gettid" number="178"/>
+  <syscall name="sysinfo" number="179"/>
+  <syscall name="mq_open" number="180"/>
+  <syscall name="mq_unlink" number="181"/>
+  <syscall name="mq_timedsend" number="182"/>
+  <syscall name="mq_timedreceive" number="183"/>
+  <syscall name="mq_notify" number="184"/>
+  <syscall name="mq_getsetattr" number="185"/>
+  <syscall name="msgget" number="186"/>
+  <syscall name="msgctl" number="187"/>
+  <syscall name="msgrcv" number="188"/>
+  <syscall name="msgsnd" number="189"/>
+  <syscall name="semget" number="190"/>
+  <syscall name="semctl" number="191"/>
+  <syscall name="semtimedop" number="192"/>
+  <syscall name="semop" number="193"/>
+  <syscall name="shmget" number="194"/>
+  <syscall name="shmctl" number="195"/>
+  <syscall name="shmat" number="196"/>
+  <syscall name="shmdt" number="197"/>
+  <syscall name="socket" number="198"/>
+  <syscall name="socketpair" number="199"/>
+  <syscall name="bind" number="200"/>
+  <syscall name="listen" number="201"/>
+  <syscall name="accept" number="202"/>
+  <syscall name="connect" number="203"/>
+  <syscall name="getsockname" number="204"/>
+  <syscall name="getpeername" number="205"/>
+  <syscall name="sendto" number="206"/>
+  <syscall name="recvfrom" number="207"/>
+  <syscall name="setsockopt" number="208"/>
+  <syscall name="getsockopt" number="209"/>
+  <syscall name="shutdown" number="210"/>
+  <syscall name="sendmsg" number="211"/>
+  <syscall name="recvmsg" number="212"/>
+  <syscall name="readahead" number="213"/>
+  <syscall name="brk" number="214"/>
+  <syscall name="munmap" number="215"/>
+  <syscall name="mremap" number="216"/>
+  <syscall name="add_key" number="217"/>
+  <syscall name="request_key" number="218"/>
+  <syscall name="keyctl" number="219"/>
+  <syscall name="clone" number="220"/>
+  <syscall name="execve" number="221"/>
+  <syscall name="mmap" number="222"/>
+  <syscall name="fadvise64" number="223"/>
+  <syscall name="swapon" number="224"/>
+  <syscall name="swapoff" number="225"/>
+  <syscall name="mprotect" number="226"/>
+  <syscall name="msync" number="227"/>
+  <syscall name="mlock" number="228"/>
+  <syscall name="munlock" number="229"/>
+  <syscall name="mlockall" number="230"/>
+  <syscall name="munlockall" number="231"/>
+  <syscall name="mincore" number="232"/>
+  <syscall name="madvise" number="233"/>
+  <syscall name="remap_file_pages" number="234"/>
+  <syscall name="mbind" number="235"/>
+  <syscall name="get_mempolicy" number="236"/>
+  <syscall name="set_mempolicy" number="237"/>
+  <syscall name="migrate_pages" number="238"/>
+  <syscall name="move_pages" number="239"/>
+  <syscall name="rt_tgsigqueueinfo" number="240"/>
+  <syscall name="perf_event_open" number="241"/>
+  <syscall name="accept4" number="242"/>
+  <syscall name="recvmmsg" number="243"/>
+  <syscall name="arch_specific_syscall" number="244"/>
+  <syscall name="wait4" number="260"/>
+  <syscall name="prlimit64" number="261"/>
+  <syscall name="fanotify_init" number="262"/>
+  <syscall name="fanotify_mark" number="263"/>
+  <syscall name="name_to_handle_at" number="264"/>
+  <syscall name="open_by_handle_at" number="265"/>
+  <syscall name="clock_adjtime" number="266"/>
+  <syscall name="syncfs" number="267"/>
+  <syscall name="setns" number="268"/>
+  <syscall name="sendmmsg" number="269"/>
+  <syscall name="process_vm_readv" number="270"/>
+  <syscall name="process_vm_writev" number="271"/>
+  <syscall name="kcmp" number="272"/>
+  <syscall name="syscalls" number="273"/>
+</syscalls_info>
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