From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31319 invoked by alias); 15 May 2008 04:07:45 -0000 Received: (qmail 30920 invoked by uid 22791); 15 May 2008 04:07:42 -0000 X-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_20,J_CHICKENPOX_74,SPF_PASS X-Spam-Check-By: sourceware.org Received: from igw2.br.ibm.com (HELO igw2.br.ibm.com) (32.104.18.25) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 15 May 2008 04:07:20 +0000 Received: from mailhub1.br.ibm.com (mailhub1 [9.18.232.109]) by igw2.br.ibm.com (Postfix) with ESMTP id 1C41317F480 for ; Thu, 15 May 2008 00:56:42 -0300 (BRST) Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.18.232.46]) by mailhub1.br.ibm.com (8.13.8/8.13.8/NCO v8.7) with ESMTP id m4F47FHc1142818 for ; Thu, 15 May 2008 01:07:15 -0300 Received: from d24av01.br.ibm.com (loopback [127.0.0.1]) by d24av01.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m4F472HM019788 for ; Thu, 15 May 2008 01:07:03 -0300 Received: from [9.12.237.223] ([9.12.237.223]) by d24av01.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id m4F46xaC019738; Thu, 15 May 2008 01:07:00 -0300 Subject: Re: [RFC] initial support for watchpoints in frysk From: Thiago Jung Bauermann To: Phil Muldoon Cc: frysk ml In-Reply-To: <1210786270.617.75.camel@localhost.localdomain> References: <1210733704.617.55.camel@localhost.localdomain> <482A999F.7030107@redhat.com> <1210786270.617.75.camel@localhost.localdomain> Content-Type: text/plain Date: Thu, 15 May 2008 15:41:00 -0000 Message-Id: <1210823367.31401.14.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.22.1.1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2008-q2/txt/msg00077.txt.bz2 On Wed, 2008-05-14 at 14:31 -0300, Thiago Jung Bauermann wrote: > > Access to the x86 and x8664 debug status registers are performed as follows: > > > > return task.getRegister(X8664Registers.DEBUG_STATUS); > > > > I think this call eventually resolves to > > RegisterBanks.getBankArrayRegister() which again resolves into ISA > > specific methods to get the register. Andrew who did the register code > > would know better here. > > I can create a debugregs() method in the frysk.sys.ptrace.RegisterSet > class (or in a subclass, perhaps?) and then use the > RegisterSetByteBuffer to use the infrastructure you mention. It's a > somehwat involved solution for just one register, but it does fit better > the Frysk registers framework. The patch below implements this approach. What do you think? The only disadvantage is that if powerpc's ptrace ever offers a second debug register using PTRACE_{GET,SET}_DEBUGREG, this implementation will not work. But that could be fixed by creating a new kind of ByteBuffer to deal with that special situation, I believe. The PPCWatchpointFunctions class is nearly the same as before, except that it now uses: task.setRegister(PPC64Registers.DABR, addr); This patch still doesn't work because of the siginfo issue. > > On x86/x8664 we can just look at the bits in the debug status register > > when a stop event/sigtrap has arrived to see if it is a watchpoint > > event. If you look at the handleTrappedEvent in the Running and the > > Stepping states you can see there is a very specific sequence of checks > > here. I'm guessing this won't work on the PPC then as you need to > > examine the siginfo structure. > > I just looked at Running.checkWatchpoint (I believe that is what you are > referring to) and it will work fine for powerpc. The siginfo check would > take place inside WatchpointFunctions.hasWatchpointTriggered method, so > it's encapsulated. I just need checkWatchpoint to pass the Signal object > to it (and also, I need the object to have the siginfo information). I had a quick first look and it seems this approach isn't good. Frysk maintains only one Signal object per kind of signal, so having siginfo piggyback on it won't work (since the latter will be different for each Signal instance). Unless it is guaranteed that there's only one signal of each kind being handled by Frysk at any moment. Then we could set the siginfo attribute each time the signal arrives, and not worry about changing the signal object behind someone's back. I still need to investigate more to see if I can make that assumption. -- []'s Thiago Jung Bauermann Software Engineer IBM Linux Technology Center diff --git a/frysk-core/frysk/isa/banks/LinuxPPCRegisterBanks.java b/frysk-core/frysk/isa/banks/LinuxPPCRegisterBanks.java index b2fd02b..e08a5ce 100644 --- a/frysk-core/frysk/isa/banks/LinuxPPCRegisterBanks.java +++ b/frysk-core/frysk/isa/banks/LinuxPPCRegisterBanks.java @@ -260,4 +260,6 @@ public class LinuxPPCRegisterBanks { .add(new BankRegister(148*8, 8, PPC64Registers.VRSAVE)) // PT_VRSAVE (PT_VR0 + 33*2), index 148 ; + public static final BankRegisterMap DEBUGREGS + = new BankRegisterMap().add(new BankRegister(0, 8, PPC64Registers.DABR)); } diff --git a/frysk-core/frysk/isa/banks/PPCBankRegisters.java b/frysk-core/frysk/isa/banks/PPCBankRegisters.java index 40d72d6..b8588b9 100644 --- a/frysk-core/frysk/isa/banks/PPCBankRegisters.java +++ b/frysk-core/frysk/isa/banks/PPCBankRegisters.java @@ -55,6 +55,7 @@ public class PPCBankRegisters { = new BankArrayRegisterMap() .add(0, LinuxPPCRegisterBanks.GREGS32) .add(0, LinuxPPCRegisterBanks.FPREGS32) + .add(1, LinuxPPCRegisterBanks.DEBUGREGS) ; /** @@ -66,6 +67,7 @@ public class PPCBankRegisters { .add(0, LinuxPPCRegisterBanks.FPREGS64) // AltiVec registers go to a separate note section called NT_PPC_VMX .add(0, LinuxPPCRegisterBanks.VRREGS64) + .add(1, LinuxPPCRegisterBanks.DEBUGREGS) ; public static final BankArrayRegisterMap PPC32BE_ON_PPC64BE diff --git a/frysk-core/frysk/isa/registers/PPC32Registers.java b/frysk-core/frysk/isa/registers/PPC32Registers.java index 1aabb9c..adb990c 100644 --- a/frysk-core/frysk/isa/registers/PPC32Registers.java +++ b/frysk-core/frysk/isa/registers/PPC32Registers.java @@ -246,6 +246,12 @@ public class PPC32Registers extends Registers { = new Register("fpscr", StandardTypes.INT32B_T); /* + * Debug register. + */ + public static final Register DABR + = new Register("dabr", StandardTypes.INT64B_T); + + /* * Defining Register Groups */ public static final RegisterGroup GENERAL diff --git a/frysk-core/frysk/isa/registers/PPC64Registers.java b/frysk-core/frysk/isa/registers/PPC64Registers.java index a5505c4..248c769 100644 --- a/frysk-core/frysk/isa/registers/PPC64Registers.java +++ b/frysk-core/frysk/isa/registers/PPC64Registers.java @@ -345,6 +345,12 @@ public class PPC64Registers extends Registers { public static final Register SPEFSCR = new Register("spefscr", StandardTypes.INT64B_T); + /* + * Debug register. + */ + public static final Register DABR + = new Register("dabr", StandardTypes.INT64B_T); + /* * Defining Register Groups */ diff --git a/frysk-core/frysk/isa/watchpoints/PPCWatchpointFunctions.java b/frysk-core/frysk/isa/watchpoints/PPCWatchpointFunctions.java new file mode 100644 index 0000000..3309bd7 --- /dev/null +++ b/frysk-core/frysk/isa/watchpoints/PPCWatchpointFunctions.java @@ -0,0 +1,179 @@ +// This file is part of the program FRYSK. +// +// Copyright 2008, Red Hat Inc. +// +// FRYSK is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// FRYSK is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with FRYSK; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// In addition, as a special exception, Red Hat, Inc. gives You the +// additional right to link the code of FRYSK with code not covered +// under the GNU General Public License ("Non-GPL Code") and to +// distribute linked combinations including the two, subject to the +// limitations in this paragraph. Non-GPL Code permitted under this +// exception must only link to the code of FRYSK through those well +// defined interfaces identified in the file named EXCEPTION found in +// the source code files (the "Approved Interfaces"). The files of +// Non-GPL Code may instantiate templates or use macros or inline +// functions from the Approved Interfaces without causing the +// resulting work to be covered by the GNU General Public +// License. Only Red Hat, Inc. may make changes or additions to the +// list of Approved Interfaces. You must obey the GNU General Public +// License in all respects for all of the FRYSK code and other code +// used in conjunction with FRYSK except the Non-GPL Code covered by +// this exception. If you modify this file, you may extend this +// exception to your version of the file, but you are not obligated to +// do so. If you do not wish to provide this exception without +// modification, you must delete this exception statement from your +// version and license this file solely under the GPL without +// exception. + +package frysk.isa.watchpoints; + +import frysk.isa.registers.PPC64Registers; +import frysk.proc.Task; + +class PPCWatchpointFunctions extends WatchpointFunctions { + + // Architecture Watchpoint Count. Number of usable + // Address-Breakpoint Registers: only one, DABR. + public PPCWatchpointFunctions () { + noOfWatchpoints = 1; + } + + /** + * Builds and sets a hardware watchpoint on a task. + * + * @param task - task to set a watchpoint on. + * @param index - watchpoint number to write. 4 on + * x8664 + * @param addr - linear virtual address to watch. + * @param range - length of range to watch. Normally + * 1,24, or 8 bytes. + * @param writeOnly - When true, only trigger when address is + * written. False, trigger when address is read or written to. + */ + public void setWatchpoint(Task task, int index, + long addr, int range, + boolean writeOnly) { + + if (index != 0) { + throw new RuntimeException("Invalid hardware watchpoint index." + + "Has to be 0."); + } + + if (range != 8) { + throw new RuntimeException("Invalid size for watchpoint " + + "range. Has to be 8."); + } + + if ((addr &~ 7) != addr) + throw new RuntimeException("Address 0x"+Long.toHexString(addr) + + " is not aligned on an 8 byte boundary. Cannot set watchpoint."); + + if (writeOnly) + // set translation and write bits + addr |= 6; + else + // set translation and read bits + addr |= 5; + + task.setRegister(PPC64Registers.DABR, addr); + } + + /** + * Reads a watchpoint. Takes a task, and an index. + * + * @param task - task to read a watchpoint from. + * @param index - watchpoint number to read. + + * @return Watchpoint - value of Watchpoint at + * register. + */ + public Watchpoint readWatchpoint(Task task, int index) { + + if (index != 0) { + throw new RuntimeException("Invalid hardware watchpoint index." + + "Has to be 0."); + } + + // Get Address from watchpoint register + long dabr_value = task.getRegister(PPC64Registers.DABR); + long address = dabr_value & ~7; + boolean writeOnly = testBit(address, 0) && !testBit(address, 1); + + return Watchpoint.create(address, 8, index, writeOnly); + } + + /** + * Deletes a watchpoint. Takes a task, and an index. + * + * @param task - task on which to delete a watchpoint. + * @param index - watchpoint number to delete. + * + * @return long - value of register for wp + */ + public final void deleteWatchpoint(Task task, int index) { + task.setRegister(PPC64Registers.DABR, 0); + } + + /** + * Reads the Debug control register. + * + * @param task - task to read the debug control + * register from. + */ + protected long readControlRegister(Task task) { + throw new RuntimeException("There is no debug control register in PowerPC."); + } + + /** + * Reads the Debug cstatus register. + * + * @param task - task to read the debug status + * register from. + */ + protected long readStatusRegister(Task task) { + throw new RuntimeException("There is no debug status register in PowerPC."); + } + + /** + * Reads the Debug Status Register and checks if + * the breakpoint specified has fired. + * + * @param task - task to read the debug control + * register from. + */ + public boolean hasWatchpointTriggered(Task task, int index) { + // FIXME: in PowerPC, the address which triggered the watchpoint is + // sent in the siginfo for the SIGTRAP. There's no way to grab it + // in Frysk yet. + throw new RuntimeException("Watchpoints not fully supported in PowerPC yet."); + } + + /** + * Resets the appropriate bit in the debug status register + * after a watchpoint has triggered, thereby reseting it. + * + * @param task - task to read the debug control + * register from. + * @param index - Debug register to reset. + */ + public void resetWatchpoint(Task task, int index) { + // There is no need to reset a watchpoint after it triggers. + } + + private boolean testBit(long register, int bitToTest) { + return (register & (1L << bitToTest)) != 0; + } + +} diff --git a/frysk-core/frysk/isa/watchpoints/WatchpointFunctionFactory.java b/frysk-core/frysk/isa/watchpoints/WatchpointFunctionFactory.java index fe8b81b..5ff68da 100644 --- a/frysk-core/frysk/isa/watchpoints/WatchpointFunctionFactory.java +++ b/frysk-core/frysk/isa/watchpoints/WatchpointFunctionFactory.java @@ -50,6 +50,8 @@ public class WatchpointFunctionFactory { private static final ISAMap watchpointTables = new ISAMap("watchpoint table") .put(ISA.IA32, new IA32WatchpointFunctions()) .put(ISA.X8664, new X8664WatchpointFunctions()) + .put(ISA.PPC32BE, new PPCWatchpointFunctions()) + .put(ISA.PPC64BE, new PPCWatchpointFunctions()) ; public static WatchpointFunctions getWatchpointFunctions(ISA isa) { diff --git a/frysk-core/frysk/proc/live/PtraceRegisterBanksFactory.java b/frysk-core/frysk/proc/live/PtraceRegisterBanksFactory.java index daa86d9..656f687 100644 --- a/frysk-core/frysk/proc/live/PtraceRegisterBanksFactory.java +++ b/frysk-core/frysk/proc/live/PtraceRegisterBanksFactory.java @@ -85,7 +85,8 @@ class PtraceRegisterBanksFactory { private static ByteBuffer[] ppcBanksBE(ProcessIdentifier pid) { ByteBuffer[] bankBuffers = new ByteBuffer[] { - new AddressSpaceByteBuffer(pid, AddressSpace.USR) + new AddressSpaceByteBuffer(pid, AddressSpace.USR), + new RegisterSetByteBuffer(pid, RegisterSet.DEBUGREGS) }; for (int i = 0; i < bankBuffers.length; i++) { diff --git a/frysk-sys/frysk/sys/ptrace/RegisterSet.java b/frysk-sys/frysk/sys/ptrace/RegisterSet.java index 7fa028a..3a4340d 100644 --- a/frysk-sys/frysk/sys/ptrace/RegisterSet.java +++ b/frysk-sys/frysk/sys/ptrace/RegisterSet.java @@ -80,8 +80,10 @@ public class RegisterSet { private static native RegisterSet regs(); private static native RegisterSet fpregs(); private static native RegisterSet fpxregs(); + private static native RegisterSet debugregs(); public static final RegisterSet REGS = regs(); public static final RegisterSet FPREGS = fpregs(); public static final RegisterSet FPXREGS = fpxregs(); + public static final RegisterSet DEBUGREGS = debugregs(); } diff --git a/frysk-sys/frysk/sys/ptrace/cni/RegisterSet.cxx b/frysk-sys/frysk/sys/ptrace/cni/RegisterSet.cxx index 2c3a861..51cf13c 100644 --- a/frysk-sys/frysk/sys/ptrace/cni/RegisterSet.cxx +++ b/frysk-sys/frysk/sys/ptrace/cni/RegisterSet.cxx @@ -87,3 +87,15 @@ frysk::sys::ptrace::RegisterSet::fpxregs() { return NULL; #endif } + +frysk::sys::ptrace::RegisterSet* +frysk::sys::ptrace::RegisterSet::debugregs() { +#if defined(__powerpc__) + /* The DABR is 64-bit wide, even in powerpc32. */ + return new frysk::sys::ptrace::RegisterSet(sizeof(long long), + PTRACE_GET_DEBUGREG, + PTRACE_SET_DEBUGREG); +#else + return NULL; +#endif +}