This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] ARM Linux support for `catch syscall'


This works alright except for the incomplete syscalls/arm-linux.xml,
for which I am waiting on a copy of sergiodj's scripts.

(It only fails one test in catch-syscall.exp, and that's because of a
syscall missing from the XML file, but I decided that adding just that
syscall to the XML file would be cheating.)

gdb/
2013-08-02  Samuel Bronson  <naesten@gmail.com>

	ARM Linux support for`catch syscall'.
	* syscalls/arm-linux.xml: New (stub) syscall file for ARM Linux.
	* arm-linux-tdep.c (arm_linux_get_syscall_number): New function.
	(arm_linux_init_abi): Register the new function and syscall file.
	* data-directory/Makefile.in: Install the new syscall file.

gdb/testsuite/
2013-08-02  Samuel Bronson  <naesten@gmail.com>

	ARM Linux support for`catch syscall'.
	* gdb.base/catch-syscall.exp: Test this on ARM now.
	(fill_all_syscalls_numbers): ARM has close/chroot on 6/61, too.
---
 gdb/arm-linux-tdep.c                     |  56 ++++++++++
 gdb/data-directory/Makefile.in           |   1 +
 gdb/syscalls/arm-linux.xml               | 181 +++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.base/catch-syscall.exp |   9 +-
 4 files changed, 243 insertions(+), 4 deletions(-)
 create mode 100644 gdb/syscalls/arm-linux.xml

diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index 1502bdc..9d8238f 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -33,6 +33,7 @@
 #include "tramp-frame.h"
 #include "breakpoint.h"
 #include "auxv.h"
+#include "xml-syscall.h"
 
 #include "arm-tdep.h"
 #include "arm-linux-tdep.h"
@@ -794,6 +795,57 @@ arm_linux_sigreturn_return_addr (struct frame_info *frame,
   return 0;
 }
 
+/* At a ptrace syscall-stop, return the syscall number.  This either
+   comes from the SVC instruction (OABI) or from r7 (EABI).
+
+   When the function fails, it should return -1.  */
+
+static LONGEST
+arm_linux_get_syscall_number (struct gdbarch *gdbarch,
+			      ptid_t ptid)
+{
+  struct regcache *regs = get_thread_regcache (ptid);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  ULONGEST pc;
+  ULONGEST cpsr;
+  ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
+  int is_thumb;
+  ULONGEST svc_number = -1;
+
+  regcache_cooked_read_unsigned (regs, ARM_PC_REGNUM, &pc);
+  regcache_cooked_read_unsigned (regs, ARM_PS_REGNUM, &cpsr);
+  is_thumb = (cpsr & t_bit) != 0;
+
+  if (is_thumb)
+    {
+      regcache_cooked_read_unsigned (regs, 7, &svc_number);
+    }
+  else
+    {
+      enum bfd_endian byte_order_for_code = 
+	gdbarch_byte_order_for_code (gdbarch);
+
+      /* PC gets incremented before the syscall-stop, so read the
+	 previous instruction.  */
+      unsigned long this_instr = 
+	read_memory_unsigned_integer (pc - 4, 4, byte_order_for_code);
+
+      unsigned long svc_operand = (0x00ffffff & this_instr);
+
+      if (svc_operand)  /* OABI.  */
+	{
+	  svc_number = svc_operand - 0x900000;
+	}
+      else /* EABI.  */
+	{
+	  regcache_cooked_read_unsigned (regs, 7, &svc_number);
+	}
+    }
+
+  return svc_number;
+}
+
 /* When FRAME is at a syscall instruction, return the PC of the next
    instruction to be executed.  */
 
@@ -1294,6 +1346,10 @@ arm_linux_init_abi (struct gdbarch_info info,
 
   tdep->syscall_next_pc = arm_linux_syscall_next_pc;
 
+  /* `catch syscall' */
+  set_xml_syscall_file_name ("syscalls/arm-linux.xml");
+  set_gdbarch_get_syscall_number (gdbarch, arm_linux_get_syscall_number);
+
   /* Syscall record.  */
   tdep->arm_swi_record = NULL;
 }
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
index dec6207..3d05213 100644
--- a/gdb/data-directory/Makefile.in
+++ b/gdb/data-directory/Makefile.in
@@ -45,6 +45,7 @@ SYSCALLS_DIR = syscalls
 SYSCALLS_INSTALL_DIR = $(DESTDIR)$(GDB_DATADIR)/$(SYSCALLS_DIR)
 SYSCALLS_FILES = \
 	gdb-syscalls.dtd \
+	arm-linux.xml \
 	ppc-linux.xml ppc64-linux.xml \
 	i386-linux.xml amd64-linux.xml \
 	sparc-linux.xml sparc64-linux.xml \
diff --git a/gdb/syscalls/arm-linux.xml b/gdb/syscalls/arm-linux.xml
new file mode 100644
index 0000000..28e1b9d
--- /dev/null
+++ b/gdb/syscalls/arm-linux.xml
@@ -0,0 +1,181 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2009-2013 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.  -->
+
+<!DOCTYPE feature SYSTEM "gdb-syscalls.dtd">
+
+<!-- This file was copied from ppc-linux.xml because *somebody* didn't
+     provide his generation script.  (It has been truncated where the
+     syscall numbers diverge.) -->
+
+<syscalls_info>
+  <syscall name="restart_syscall" number="0"/>
+  <syscall name="exit" number="1"/>
+  <syscall name="fork" number="2"/>
+  <syscall name="read" number="3"/>
+  <syscall name="write" number="4"/>
+  <syscall name="open" number="5"/>
+  <syscall name="close" number="6"/>
+  <syscall name="waitpid" number="7"/>
+  <syscall name="creat" number="8"/>
+  <syscall name="link" number="9"/>
+  <syscall name="unlink" number="10"/>
+  <syscall name="execve" number="11"/>
+  <syscall name="chdir" number="12"/>
+  <syscall name="time" number="13"/>
+  <syscall name="mknod" number="14"/>
+  <syscall name="chmod" number="15"/>
+  <syscall name="lchown" number="16"/>
+  <syscall name="break" number="17"/>
+  <syscall name="oldstat" number="18"/>
+  <syscall name="lseek" number="19"/>
+  <syscall name="getpid" number="20"/>
+  <syscall name="mount" number="21"/>
+  <syscall name="umount" number="22"/>
+  <syscall name="setuid" number="23"/>
+  <syscall name="getuid" number="24"/>
+  <syscall name="stime" number="25"/>
+  <syscall name="ptrace" number="26"/>
+  <syscall name="alarm" number="27"/>
+  <syscall name="oldfstat" number="28"/>
+  <syscall name="pause" number="29"/>
+  <syscall name="utime" number="30"/>
+  <syscall name="stty" number="31"/>
+  <syscall name="gtty" number="32"/>
+  <syscall name="access" number="33"/>
+  <syscall name="nice" number="34"/>
+  <syscall name="ftime" number="35"/>
+  <syscall name="sync" number="36"/>
+  <syscall name="kill" number="37"/>
+  <syscall name="rename" number="38"/>
+  <syscall name="mkdir" number="39"/>
+  <syscall name="rmdir" number="40"/>
+  <syscall name="dup" number="41"/>
+  <syscall name="pipe" number="42"/>
+  <syscall name="times" number="43"/>
+  <syscall name="prof" number="44"/>
+  <syscall name="brk" number="45"/>
+  <syscall name="setgid" number="46"/>
+  <syscall name="getgid" number="47"/>
+  <syscall name="signal" number="48"/>
+  <syscall name="geteuid" number="49"/>
+  <syscall name="getegid" number="50"/>
+  <syscall name="acct" number="51"/>
+  <syscall name="umount2" number="52"/>
+  <syscall name="lock" number="53"/>
+  <syscall name="ioctl" number="54"/>
+  <syscall name="fcntl" number="55"/>
+  <syscall name="mpx" number="56"/>
+  <syscall name="setpgid" number="57"/>
+  <syscall name="ulimit" number="58"/>
+  <syscall name="oldolduname" number="59"/>
+  <syscall name="umask" number="60"/>
+  <syscall name="chroot" number="61"/>
+  <syscall name="ustat" number="62"/>
+  <syscall name="dup2" number="63"/>
+  <syscall name="getppid" number="64"/>
+  <syscall name="getpgrp" number="65"/>
+  <syscall name="setsid" number="66"/>
+  <syscall name="sigaction" number="67"/>
+  <syscall name="sgetmask" number="68"/>
+  <syscall name="ssetmask" number="69"/>
+  <syscall name="setreuid" number="70"/>
+  <syscall name="setregid" number="71"/>
+  <syscall name="sigsuspend" number="72"/>
+  <syscall name="sigpending" number="73"/>
+  <syscall name="sethostname" number="74"/>
+  <syscall name="setrlimit" number="75"/>
+  <syscall name="getrlimit" number="76"/>
+  <syscall name="getrusage" number="77"/>
+  <syscall name="gettimeofday" number="78"/>
+  <syscall name="settimeofday" number="79"/>
+  <syscall name="getgroups" number="80"/>
+  <syscall name="setgroups" number="81"/>
+  <syscall name="select" number="82"/>
+  <syscall name="symlink" number="83"/>
+  <syscall name="oldlstat" number="84"/>
+  <syscall name="readlink" number="85"/>
+  <syscall name="uselib" number="86"/>
+  <syscall name="swapon" number="87"/>
+  <syscall name="reboot" number="88"/>
+  <syscall name="readdir" number="89"/>
+  <syscall name="mmap" number="90"/>
+  <syscall name="munmap" number="91"/>
+  <syscall name="truncate" number="92"/>
+  <syscall name="ftruncate" number="93"/>
+  <syscall name="fchmod" number="94"/>
+  <syscall name="fchown" number="95"/>
+  <syscall name="getpriority" number="96"/>
+  <syscall name="setpriority" number="97"/>
+  <syscall name="profil" number="98"/>
+  <syscall name="statfs" number="99"/>
+  <syscall name="fstatfs" number="100"/>
+  <syscall name="ioperm" number="101"/>
+  <syscall name="socketcall" number="102"/>
+  <syscall name="syslog" number="103"/>
+  <syscall name="setitimer" number="104"/>
+  <syscall name="getitimer" number="105"/>
+  <syscall name="stat" number="106"/>
+  <syscall name="lstat" number="107"/>
+  <syscall name="fstat" number="108"/>
+  <syscall name="olduname" number="109"/>
+  <syscall name="iopl" number="110"/>
+  <syscall name="vhangup" number="111"/>
+  <syscall name="idle" number="112"/>
+  <syscall name="vm86" number="113"/>
+  <syscall name="wait4" number="114"/>
+  <syscall name="swapoff" number="115"/>
+  <syscall name="sysinfo" number="116"/>
+  <syscall name="ipc" number="117"/>
+  <syscall name="fsync" number="118"/>
+  <syscall name="sigreturn" number="119"/>
+  <syscall name="clone" number="120"/>
+  <syscall name="setdomainname" number="121"/>
+  <syscall name="uname" number="122"/>
+  <syscall name="modify_ldt" number="123"/>
+  <syscall name="adjtimex" number="124"/>
+  <syscall name="mprotect" number="125"/>
+  <syscall name="sigprocmask" number="126"/>
+  <syscall name="create_module" number="127"/>
+  <syscall name="init_module" number="128"/>
+  <syscall name="delete_module" number="129"/>
+  <syscall name="get_kernel_syms" number="130"/>
+  <syscall name="quotactl" number="131"/>
+  <syscall name="getpgid" number="132"/>
+  <syscall name="fchdir" number="133"/>
+  <syscall name="bdflush" number="134"/>
+  <syscall name="sysfs" number="135"/>
+  <syscall name="personality" number="136"/>
+  <syscall name="afs_syscall" number="137"/>
+  <syscall name="setfsuid" number="138"/>
+  <syscall name="setfsgid" number="139"/>
+  <syscall name="_llseek" number="140"/>
+  <syscall name="getdents" number="141"/>
+  <syscall name="_newselect" number="142"/>
+  <syscall name="flock" number="143"/>
+  <syscall name="msync" number="144"/>
+  <syscall name="readv" number="145"/>
+  <syscall name="writev" number="146"/>
+  <syscall name="getsid" number="147"/>
+  <syscall name="fdatasync" number="148"/>
+  <syscall name="_sysctl" number="149"/>
+  <syscall name="mlock" number="150"/>
+  <syscall name="munlock" number="151"/>
+  <syscall name="mlockall" number="152"/>
+  <syscall name="munlockall" number="153"/>
+  <syscall name="sched_setparam" number="154"/>
+  <syscall name="sched_getparam" number="155"/>
+  <syscall name="sched_setscheduler" number="156"/>
+  <syscall name="sched_getscheduler" number="157"/>
+  <syscall name="sched_yield" number="158"/>
+  <syscall name="sched_get_priority_max" number="159"/>
+  <syscall name="sched_get_priority_min" number="160"/>
+  <syscall name="sched_rr_get_interval" number="161"/>
+  <syscall name="nanosleep" number="162"/>
+  <syscall name="mremap" number="163"/>
+  <syscall name="setresuid" number="164"/>
+  <syscall name="getresuid" number="165"/>
+</syscalls_info>
diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp
index 395fcd4..1066caf 100644
--- a/gdb/testsuite/gdb.base/catch-syscall.exp
+++ b/gdb/testsuite/gdb.base/catch-syscall.exp
@@ -34,7 +34,7 @@ if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
 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 "mips*-linux*"] && ![istarget "arm*-linux*"] } {
      continue
 }
 
@@ -407,11 +407,12 @@ proc do_syscall_tests_without_xml {} {
 proc fill_all_syscalls_numbers {} {
     global all_syscalls_numbers
 
-    # For Linux on x86, PPC, PPC64, SPARC and SPARC64, the numbers for the syscalls
-    # "close" and "chroot" are the same.
+    # For Linux on x86, PPC, PPC64, SPARC, SPARC64 and ARM,
+    # the numbers for the syscalls "close" and "chroot" are the same.
     if { [istarget "i\[34567\]86-*-linux*"]
          || [istarget "powerpc-*-linux*"] || [istarget "powerpc64-*-linux*"]
-         || [istarget "sparc-*-linux*"] || [istarget "sparc64-*-linux*"] } {
+         || [istarget "sparc-*-linux*"] || [istarget "sparc64-*-linux*"]
+         || [istarget "arm*-linux*"] } {
          set all_syscalls_numbers { "6" "61" }
     }
 }
-- 
1.8.3.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]