From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30846 invoked by alias); 22 Aug 2013 20:35:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 30836 invoked by uid 89); 22 Aug 2013 20:35:18 -0000 X-Spam-SWARE-Status: No, score=-7.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS,T_FRT_STOCK2 autolearn=ham version=3.3.2 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 22 Aug 2013 20:35:16 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7MKZC88008139 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 22 Aug 2013 16:35:12 -0400 Received: from psique ([10.3.113.13]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r7MKZ7T2005566 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 22 Aug 2013 16:35:09 -0400 From: Sergio Durigan Junior To: Doug Evans Cc: Samuel Bronson , gdb-patches Subject: Re: [PATCH v2] ARM Linux support for `catch syscall' References: X-URL: http://www.redhat.com Date: Thu, 22 Aug 2013 20:35:00 -0000 In-Reply-To: (Doug Evans's message of "Fri, 16 Aug 2013 11:19:36 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-08/txt/msg00653.txt.bz2 On Friday, August 16 2013, Doug Evans wrote: > Hi. > Re: http://sourceware.org/ml/gdb-patches/2013-08/msg00408.html > > Given that some of the generated output is copied from ppc-linux.xml, > I guess keeping 2009 is TRTTD. > > Patch is ok by me. I committed the following patch for Samuel. http://sourceware.org/ml/gdb-cvs/2013-08/msg00114.html -- Sergio This time, it passes all the tests and comes with a nearly complete XML file (plus a script that can nearly regenerate the XML file). (I elected to leave out __ARM_NR_cmpxchg, since it has dire warnings to the effect that the only pieces of code that should be aware of it are the implementation and the __kuser_cmpxchg code in entry-armv.S.) gdb/ 2013-08-14 Samuel Bronson ARM Linux support for `catch syscall'. * syscalls/arm-linux.py: New file. * syscalls/arm-linux.xml: Likewise. * arm-linux-tdep.c (arm_linux_get_syscall_number): New function. (arm_linux_init_abi): Register the new function and syscall xml file. * data-directory/Makefile.in: Install the new syscall xml file. * NEWS: Brag about this. gdb/testsuite/ 2013-08-14 Samuel Bronson 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/NEWS | 2 + gdb/arm-linux-tdep.c | 58 +++++ gdb/data-directory/Makefile.in | 1 + gdb/syscalls/arm-linux.py | 60 +++++ gdb/syscalls/arm-linux.xml | 398 +++++++++++++++++++++++++++++++ gdb/testsuite/gdb.base/catch-syscall.exp | 9 +- 6 files changed, 524 insertions(+), 4 deletions(-) create mode 100755 gdb/syscalls/arm-linux.py create mode 100644 gdb/syscalls/arm-linux.xml diff --git a/gdb/NEWS b/gdb/NEWS index 6ee82f7..f246ee1 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -3,6 +3,8 @@ *** Changes since GDB 7.6 +* The "catch syscall" command now works on arm*-linux* targets. + * Python scripting ** Frame filters and frame decorators have been added. diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c index 1502bdc..6ac61cc 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,59 @@ 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 SWI 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 +1348,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.py b/gdb/syscalls/arm-linux.py new file mode 100755 index 0000000..0814dd4 --- /dev/null +++ b/gdb/syscalls/arm-linux.py @@ -0,0 +1,60 @@ +# Copyright (C) 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. This file is offered as-is, +# without any warranty. + +import sys +import re +import time + +infname = sys.argv[1] +inf = file(infname) + +print("""\ + + + + + + + +""" % (time.strftime("%Y"), infname)) + +def record(name, number, comment=None): + #nm = 'name="%s"' % name + #s = ' ' % (nm, number) + s = ' ' % (name, number) + if comment: + s += ' ' % comment + print(s) + +for line in inf: + m = re.match(r'^#define __NR_(\w+)\s+\(__NR_SYSCALL_BASE\+\s*(\d+)\)', + line) + if m: + record(m.group(1), int(m.group(2))) + continue + + m = re.match(r'^\s+/\* (\d+) was sys_(\w+) \*/$', line) + if m: + record(m.group(2), int(m.group(1)), 'removed') + + m = re.match(r'^#define __ARM_NR_(\w+)\s+\(__ARM_NR_BASE\+\s*(\d+)\)', + line) + if m: + record('ARM_'+m.group(1), 0x0f0000+int(m.group(2))) + continue + +print('') diff --git a/gdb/syscalls/arm-linux.xml b/gdb/syscalls/arm-linux.xml new file mode 100644 index 0000000..b35125c --- /dev/null +++ b/gdb/syscalls/arm-linux.xml @@ -0,0 +1,398 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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.4.rc3