public inbox for frysk-cvs@sourceware.org help / color / mirror / Atom feed
From: tthomas@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Separate watch observer(s) installer from hpd. Date: Wed, 28 May 2008 18:32:00 -0000 [thread overview] Message-ID: <20080528183251.2634.qmail@sourceware.org> (raw) The branch, master has been updated via 96c93548e77eb436d7128ed95277832242e9f092 (commit) from 7391aeb00d8f701dbfb30f026ec050cda6731f3c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 96c93548e77eb436d7128ed95277832242e9f092 Author: Teresa Thomas <tthomas@redhat.com> Date: Wed May 28 14:34:16 2008 -0400 Separate watch observer(s) installer from hpd. frysk-core/frysk/rt/ChangeLog: 2008-05-28 Teresa Thomas <tthomas@redhat.com> * WatchObserverInstaller.java: New file. frysk-core/frysk/hpd/ChangeLog: 2008-05-28 Teresa Thomas <tthomas@redhat.com> * WatchCommand.java (interpret): Use rt.WatchObserverInstaller. ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/hpd/ChangeLog | 4 + frysk-core/frysk/hpd/WatchCommand.java | 92 +----------- frysk-core/frysk/rt/ChangeLog | 4 + frysk-core/frysk/rt/WatchObserverInstaller.java | 181 +++++++++++++++++++++++ 4 files changed, 194 insertions(+), 87 deletions(-) create mode 100644 frysk-core/frysk/rt/WatchObserverInstaller.java First 500 lines of diff: diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog index adb7f00..08234d4 100644 --- a/frysk-core/frysk/hpd/ChangeLog +++ b/frysk-core/frysk/hpd/ChangeLog @@ -1,3 +1,7 @@ +2008-05-28 Teresa Thomas <tthomas@redhat.com> + + * WatchCommand.java (interpret): Use rt.WatchObserverInstaller. + 2008-05-26 Teresa Thomas <tthomas@redhat.com> * WatchCommand.java (watchpointsInUse): New diff --git a/frysk-core/frysk/hpd/WatchCommand.java b/frysk-core/frysk/hpd/WatchCommand.java index 5c0a5d6..c968f18 100644 --- a/frysk-core/frysk/hpd/WatchCommand.java +++ b/frysk-core/frysk/hpd/WatchCommand.java @@ -43,16 +43,12 @@ import java.util.Iterator; import java.util.List; import frysk.expr.Expression; -import frysk.isa.watchpoints.WatchpointFunctionFactory; -import frysk.proc.Action; import frysk.proc.Task; -import frysk.proc.TaskObserver; -import frysk.value.Format; +import frysk.rt.WatchObserverInstaller; class WatchCommand extends ParameterizedCommand { private boolean writeOnly = true; - private static int watchpointsInUse = 0; WatchCommand() { // XXX: Add details on thread-handling when implemented @@ -99,89 +95,11 @@ class WatchCommand extends ParameterizedCommand { continue; } - // XXX: getValue may modify inferior. - String oldValueStr = expr.getValue().toPrint - (Format.NATURAL, task.getMemory()); - - // Get the number of hardware watchpoints - architecture dependent - int watchpointCount = WatchpointFunctionFactory.getWatchpointFunctions - (task.getISA()).getWatchpointCount(); - // Get the max length a hardware watchpoint can watch - architecture dependent - int watchLength = WatchpointFunctionFactory.getWatchpointFunctions - (task.getISA()).getWatchpointMaxLength(); - - long variableAddress = expr.getLocation().getAddress(); - int variableLength = expr.getType().getSize(); - - if (variableLength > (watchpointCount-watchpointsInUse) * watchLength ) - throw new RuntimeException ("Watch error: Available watchpoints not sufficient to " + - "watch complete value."); - - // Calculate number of watch observers needed to completely - // watch the variable. - int numberOfObservers = (int)Math.ceil((double)variableLength/ - (double)watchLength); - - // Add watchpoint observers to task. - for (int i=0; i< numberOfObservers-1; i++) { - WatchpointObserver wpo = new WatchpointObserver - (expr, cli, expressionStr, oldValueStr); - task.requestAddWatchObserver - (wpo, variableAddress + i*watchLength, watchLength, writeOnly); - } - // Last observer may not need to watch all watchLength bytes. - WatchpointObserver wpo = new WatchpointObserver - (expr, cli, expressionStr, oldValueStr); - task.requestAddWatchObserver - (wpo, variableAddress + (numberOfObservers-1)*watchLength, - variableLength-(numberOfObservers-1)*watchLength, writeOnly); - } - } - - static class WatchpointObserver - implements TaskObserver.Watch - { - Expression expr; - CLI cli; - String exprStr; - String oldValueStr; - - WatchpointObserver(Expression expr, CLI cli, String exprStr, String oldValueStr) { - this.expr = expr; - this.cli = cli; - this.exprStr = exprStr; - this.oldValueStr = oldValueStr; - - } - public Action updateHit(Task task, long address, int length) { - - String newValueStr = expr.getValue().toPrint - (Format.NATURAL, task.getMemory()); - - String watchMessage = "Watchpoint hit: " + exprStr + "\n" + - " Value before hit = " + oldValueStr + "\n" + - " Value after hit = " + newValueStr + "\n"; - // Remember the previous value - oldValueStr = newValueStr; - - cli.getSteppingEngine().blockedByActionPoint(task, this, watchMessage, cli.outWriter); - task.requestUnblock(this); - return Action.BLOCK; - } - - public void addFailed(Object observable, Throwable w) { - cli.outWriter.println ("Watchpoint Error:" + w.getMessage()); + WatchObserverInstaller installer = new WatchObserverInstaller + (expr, cli.getSteppingEngine(), + cli.getPrintWriter(), expressionStr); + installer.install(task, writeOnly); } - - public void addedTo(Object observable) { - cli.outWriter.println("Watchpoint set: " + exprStr); - watchpointsInUse++; - } - - public void deletedFrom(Object observable) { - watchpointsInUse--; - } - } int completer(CLI cli, Input input, int cursor, List completions) { diff --git a/frysk-core/frysk/rt/ChangeLog b/frysk-core/frysk/rt/ChangeLog index 966dcae..0f9b8a9 100644 --- a/frysk-core/frysk/rt/ChangeLog +++ b/frysk-core/frysk/rt/ChangeLog @@ -1,3 +1,7 @@ +2008-05-28 Teresa Thomas <tthomas@redhat.com> + + * WatchObserverInstaller.java: New file. + 2008-05-15 Sami Wagiaalla <swagiaal@redhat.com> * FunctionBreakpoint.java: Added comment. diff --git a/frysk-core/frysk/rt/WatchObserverInstaller.java b/frysk-core/frysk/rt/WatchObserverInstaller.java new file mode 100644 index 0000000..d90bcda --- /dev/null +++ b/frysk-core/frysk/rt/WatchObserverInstaller.java @@ -0,0 +1,181 @@ +// 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.rt; + +import java.io.PrintWriter; + +import frysk.expr.Expression; +import frysk.isa.watchpoints.WatchpointFunctionFactory; +import frysk.proc.Action; +import frysk.proc.Task; +import frysk.proc.TaskObserver; +import frysk.stepping.SteppingEngine; +import frysk.value.Format; + +/** + * + * Class that installs watchpoint observers for watching + * read/write of variables or expressions. If the maximum + * size that can be watched by a hardware debug register + * is smaller than the size of the expression being watched, + * then mutiple watch observers are used. + */ +public class WatchObserverInstaller { + + private static int watchpointsInUse = 0; + + Expression expr; + String exprString; + SteppingEngine ste; + PrintWriter writer; + + /** + * + * @param expr Expression to install watchpoint on + * @param ste Stepping engine in use + * @param writer Writer to print watch messages to + * @param exprString Text string of expression + */ + public WatchObserverInstaller(Expression expr, SteppingEngine ste, + PrintWriter writer, String exprString) { + this.expr = expr; + this.ste = ste; + this.writer = writer; + this.exprString = exprString; + } + + public void install (Task task, boolean writeOnly) { + + // Get the number of hardware watchpoints - architecture dependent + int watchpointCount = WatchpointFunctionFactory.getWatchpointFunctions + (task.getISA()).getWatchpointCount(); + // Get the max length a hardware watchpoint can watch - architecture dependent + int maxWatchLength = WatchpointFunctionFactory.getWatchpointFunctions + (task.getISA()).getWatchpointMaxLength(); + + long variableAddress = expr.getLocation().getAddress(); + int variableLength = expr.getType().getSize(); + + if (variableLength > (watchpointCount-watchpointsInUse) * maxWatchLength ) { + throw new RuntimeException ("Watch error: Available watchpoints not " + + "sufficient to watch complete value."); + } + + // Calculate number of watch observers needed + // to completely watch the variable. + int numberOfObservers = (int)Math.ceil((double)variableLength/ + (double)maxWatchLength); + + // Add watchpoint observers to task. + for (int i=0; i< numberOfObservers-1; i++) { + WatchpointObserver wpo = new WatchpointObserver + (expr, exprString, task, ste, writer); + task.requestAddWatchObserver + (wpo, variableAddress + i*maxWatchLength, + maxWatchLength, writeOnly); + } + // Last observer may not need to watch all watchLength bytes. + WatchpointObserver wpo = new WatchpointObserver + (expr, exprString, task, ste, writer); + task.requestAddWatchObserver + (wpo, variableAddress + (numberOfObservers-1)*maxWatchLength, + variableLength-(numberOfObservers-1)*maxWatchLength, writeOnly); + } + + /** + * + * Watch observer that gets triggered when the + * contents of the address being watched is written to + * or read from. + */ + static class WatchpointObserver + implements TaskObserver.Watch + { + Expression expr; + String exprString; + SteppingEngine ste; + PrintWriter writer; + String oldValue; + Task task; + + WatchpointObserver(Expression expr, String exprStr, Task task, + SteppingEngine ste, PrintWriter writer) { + this.expr = expr; + this.exprString = exprStr; + this.ste = ste; + this.writer = writer; + this.task = task; + this.oldValue = ""; + + } + public Action updateHit(Task task, long address, int length) { + + String newValue = expr.getValue().toPrint + (Format.NATURAL, task.getMemory()); + + String watchMessage = "Watchpoint hit: " + exprString + "\n" + + " Value before hit = " + oldValue + "\n" + + " Value after hit = " + newValue + "\n"; + // Remember the previous value + oldValue = newValue; + + ste.blockedByActionPoint(task, this, watchMessage, writer); + task.requestUnblock(this); + return Action.BLOCK; + } + + public void addFailed(Object observable, Throwable w) { + writer.println ("Watchpoint Error:" + w.getMessage()); + } + + public void addedTo(Object observable) { + writer.println("Watchpoint set: " + exprString); + watchpointsInUse++; + // XXX: getValue may modify inferior. + oldValue = expr.getValue().toPrint + (Format.NATURAL, task.getMemory()); + } + + public void deletedFrom(Object observable) { + watchpointsInUse--; + } + + } +} \ No newline at end of file hooks/post-receive -- frysk system monitor/debugger
reply other threads:[~2008-05-28 18:32 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20080528183251.2634.qmail@sourceware.org \ --to=tthomas@sourceware.org \ --cc=frysk-cvs@sourceware.org \ --cc=frysk@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).