From patchwork Thu Aug 27 16:23:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Weigand X-Patchwork-Id: 8484 Received: (qmail 120800 invoked by alias); 27 Aug 2015 16:23:53 -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 120785 invoked by uid 89); 27 Aug 2015 16:23:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: e06smtp11.uk.ibm.com Received: from e06smtp11.uk.ibm.com (HELO e06smtp11.uk.ibm.com) (195.75.94.107) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Thu, 27 Aug 2015 16:23:51 +0000 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 27 Aug 2015 17:23:48 +0100 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 27 Aug 2015 17:23:46 +0100 X-MailFrom: uweigand@de.ibm.com X-RcptTo: gdb-patches@sourceware.org Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 6D14E1B08072 for ; Thu, 27 Aug 2015 17:25:18 +0100 (BST) Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t7RGNgpA24314084 for ; Thu, 27 Aug 2015 16:23:45 GMT Received: from d06av05.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t7RGNXil030666 for ; Thu, 27 Aug 2015 10:23:33 -0600 Received: from oc7340732750.ibm.com (dyn-9-152-213-24.boeblingen.de.ibm.com [9.152.213.24]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t7RGNXgk030480; Thu, 27 Aug 2015 10:23:33 -0600 Received: by oc7340732750.ibm.com (Postfix, from userid 500) id 33ACF39FA; Thu, 27 Aug 2015 18:23:24 +0200 (CEST) Subject: Re: [RFC] Fix SW breakpoint handling for Cell multi-arch To: palves@redhat.com (Pedro Alves) Date: Thu, 27 Aug 2015 18:23:24 +0200 (CEST) From: "Ulrich Weigand" Cc: gdb-patches@sourceware.org In-Reply-To: <55DF3014.6090301@redhat.com> from "Pedro Alves" at Aug 27, 2015 04:43:16 PM MIME-Version: 1.0 Message-Id: <20150827162324.33ACF39FA@oc7340732750.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15082716-0041-0000-0000-0000059B1A82 Pedro Alves wrote: > On 08/27/2015 12:54 PM, Ulrich Weigand wrote: > > Hi Pedro, > > > > a second major issue with Cell multi-arch debugging right now is related > > to the new target-side SW breakpoint handling. Cell uses linux-nat as > > primary target for the PowerPC side, which now returns true from the > > to_supports_stopped_by_sw_breakpoint hook. > > > > This works fine for the PowerPC side. However, when a breakpoint on the > > SPU side is hit, the kernel does *not* provide a siginfo with TRAP_BRKPT, > > but instead simply delivers a SIGTRAP without siginfo. > > Does si_code indicate that it was a kernel-generated SIGTRAP (that is, > SI_KERNEL)? Wondering whether that would still be distinguishable > from trace/single-step traps and user sent SIGTRAPs. See comment and > table about x86's si_code in nat/linux-nat.h. I don't know whether > the SPU has to care about all the cases there, but I suspect > not (e.g., I'd assume SPU code can't exec?). That's an interesting idea. Indeed the kernel uses SI_KERNEL for SIGTRAPs indicating SW breakpoints on SPU, but nowhere else in all of PowerPC code. This means simply accepting either TRAP_BRKPT or SI_KERNEL should work. And indeed the patch appended below works just as well as the original patch for me. > If not, then we'll have to cope... :-/ . Any chance the kernel gets > fixed, in order for some future gdb stop worrying about this? I was > hoping to get rid of the moribund locations heuristic at some point. There's probably no chance of changing the kernel at this point; Cell is really just in maintenance mode at this point (the only supported OS is RHEL 5). Bye, Ulrich Index: binutils-gdb/gdb/gdbserver/linux-low.c =================================================================== --- binutils-gdb.orig/gdb/gdbserver/linux-low.c +++ binutils-gdb/gdb/gdbserver/linux-low.c @@ -651,7 +651,7 @@ check_stopped_by_breakpoint (struct lwp_ { if (siginfo.si_signo == SIGTRAP) { - if (siginfo.si_code == GDB_ARCH_TRAP_BRKPT) + if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code)) { if (debug_threads) { Index: binutils-gdb/gdb/linux-nat.c =================================================================== --- binutils-gdb.orig/gdb/linux-nat.c +++ binutils-gdb/gdb/linux-nat.c @@ -2801,7 +2801,7 @@ check_stopped_by_breakpoint (struct lwp_ { if (siginfo.si_signo == SIGTRAP) { - if (siginfo.si_code == GDB_ARCH_TRAP_BRKPT) + if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code)) { if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, Index: binutils-gdb/gdb/nat/linux-ptrace.h =================================================================== --- binutils-gdb.orig/gdb/nat/linux-ptrace.h +++ binutils-gdb/gdb/nat/linux-ptrace.h @@ -135,12 +135,19 @@ struct buffer; running to a breakpoint and checking what comes out of siginfo->si_code. - The generic Linux target code should use GDB_ARCH_TRAP_BRKPT - instead of TRAP_BRKPT to abstract out this x86 peculiarity. */ + The ppc kernel does use TRAP_BRKPT for software breakpoints + in PowerPC code, but it uses SI_KERNEL for software breakpoints + in SPU code on a Cell/B.E. However, SI_KERNEL is never seen + on a SIGTRAP for any other reason. + + The generic Linux target code should use GDB_ARCH_IS_TRAP_BRKPT + instead of TRAP_BRKPT to abstract out these peculiarities. */ #if defined __i386__ || defined __x86_64__ -# define GDB_ARCH_TRAP_BRKPT SI_KERNEL +# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL) +#elif defined __powerpc__ +# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL || (X) == TRAP_BRKPT) #else -# define GDB_ARCH_TRAP_BRKPT TRAP_BRKPT +# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == TRAP_BRKPT) #endif #ifndef TRAP_HWBKPT