public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Add watch command to hpd.
@ 2008-04-15 22:13 tthomas
  0 siblings, 0 replies; only message in thread
From: tthomas @ 2008-04-15 22:13 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  9a4f439eacad3c3f7c84c5bfe3cf5546c35572d8 (commit)
       via  54752415bfe2de440e7a573ee96a6e0d42929c25 (commit)
       via  81f3b02af674a022a1b9166caf76fabe109941f1 (commit)
      from  4461f311e336610949daff324b7c37c706986b3c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 9a4f439eacad3c3f7c84c5bfe3cf5546c35572d8
Author: Teresa Thomas <tthomas@redhat.com>
Date:   Tue Apr 15 13:38:23 2008 -0400

    Add watch command to hpd.
    
    frysk-core/frysk/hpd/ChangeLog:
    2008-04-15  Teresa Thomas  <tthomas@redhat.com>
    
    	* WatchCommand.java: New.
    	* TestWatchCommand.java: New.
    	* TopLevelCommand.java (TopLevelCommand): Add watch command.

commit 54752415bfe2de440e7a573ee96a6e0d42929c25
Author: Teresa Thomas <tthomas@redhat.com>
Date:   Tue Apr 15 13:36:56 2008 -0400

    Add requestAddSteppingEngine and setTaskStopped to stepping engine.
    
    frysk-core/frysk/stepping/ChangeLog:
    2008-04-15  Teresa Thomas  <tthomas@redhat.com>
    
    	* SteppingEngine.java (requestAddSteppingObserver): New.
    	(setTaskStopped): New.

commit 81f3b02af674a022a1b9166caf76fabe109941f1
Author: Teresa Thomas <tthomas@redhat.com>
Date:   Tue Apr 15 13:33:16 2008 -0400

    Add isInstructionObserverAdded to Task.
    
    frysk-core/frysk/proc/ChangeLog:
    2008-04-15  Teresa Thomas  <tthomas@redhat.com>
    
    	* Task.java (isInstructionObserverAdded): New.
    
    frysk-core/frysk/proc/dead/ChangeLog:
    2008-04-15  Teresa Thomas  <tthomas@redhat.com>
    
    	* DeadTask.java (isInstructionObserverAdded): New.
    
    frysk-core/frysk/proc/dummy/ChangeLog:
    2008-04-15  Teresa Thomas  <tthomas@redhat.com>
    
    	* DummyTask.java (isInstructionObserverAdded): New.
    
    frysk-core/frysk/proc/live/ChangeLog:
    2008-04-15  Teresa Thomas  <tthomas@redhat.com>
    
    	* LinuxPtraceTask.java (isInstructionObserverAdded): New.

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/hpd/ChangeLog                  |    6 +
 frysk-core/frysk/hpd/TestWatchCommand.java      |   67 +++++++++
 frysk-core/frysk/hpd/TopLevelCommand.java       |    1 +
 frysk-core/frysk/hpd/WatchCommand.java          |  163 +++++++++++++++++++++++
 frysk-core/frysk/proc/ChangeLog                 |    6 +-
 frysk-core/frysk/proc/Task.java                 |    6 +-
 frysk-core/frysk/proc/dead/ChangeLog            |    4 +
 frysk-core/frysk/proc/dead/DeadTask.java        |    4 +
 frysk-core/frysk/proc/dummy/ChangeLog           |    4 +
 frysk-core/frysk/proc/dummy/DummyTask.java      |    4 +
 frysk-core/frysk/proc/live/ChangeLog            |    4 +
 frysk-core/frysk/proc/live/LinuxPtraceTask.java |    5 +
 frysk-core/frysk/stepping/ChangeLog             |    5 +
 frysk-core/frysk/stepping/SteppingEngine.java   |   28 ++++-
 14 files changed, 304 insertions(+), 3 deletions(-)
 create mode 100644 frysk-core/frysk/hpd/TestWatchCommand.java
 create mode 100644 frysk-core/frysk/hpd/WatchCommand.java

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index a4ccf28..aaa86d9 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,3 +1,9 @@
+2008-04-15  Teresa Thomas  <tthomas@redhat.com>
+
+	* WatchCommand.java: New.
+	* TestWatchCommand.java: New.
+	* TopLevelCommand.java (TopLevelCommand): Add watch command.
+	
 2008-04-10  Stan Cox  <scox@redhat.com>
 
 	* KillCommand.java (interpret): Make load sysroot aware.
diff --git a/frysk-core/frysk/hpd/TestWatchCommand.java b/frysk-core/frysk/hpd/TestWatchCommand.java
new file mode 100644
index 0000000..151cd06
--- /dev/null
+++ b/frysk-core/frysk/hpd/TestWatchCommand.java
@@ -0,0 +1,67 @@
+// 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.hpd;
+
+import frysk.config.Config;
+
+/**
+* This class tests the "watch" command.
+*/
+public class TestWatchCommand extends TestLib {
+
+  public void testWatchPointSetAndHit()
+  {
+      e = new HpdTestbed();
+      e.sendCommandExpectPrompt("load " + Config.getPkgLibFile("funit-watchpoint").getPath(),
+                                "Loaded executable file.*");
+      e.sendCommandExpectPrompt("start", "Attached to process.*");
+      
+      e.send("watch source\n"); 
+      e.expect(".*Watchpoint set: source.*");
+      
+      e.send("go\n"); 
+      e.expect(".*Watchpoint hit: source.*Value before hit ="
+  	        + ".*Value after  hit =.*");
+
+      e.send("quit\n");
+      e.expect("Quitting\\.\\.\\.");
+      e.close();
+  }
+}
\ No newline at end of file
diff --git a/frysk-core/frysk/hpd/TopLevelCommand.java b/frysk-core/frysk/hpd/TopLevelCommand.java
index d6d14bc..8d1574c 100644
--- a/frysk-core/frysk/hpd/TopLevelCommand.java
+++ b/frysk-core/frysk/hpd/TopLevelCommand.java
@@ -114,6 +114,7 @@ public class TopLevelCommand extends MultiLevelCommand {
         add(new StepFinishCommand(), "finish");
         add(new StepNextCommand(), "n|ext");
         add(new UnloadCommand(), "un|load");
+        add(new WatchCommand(), "watch");        
         add(new WhatCommand(), "what");
         add(new WhichsetsCommand(), "whichsets");
         add(new ViewsetCommand(), "viewset");
diff --git a/frysk-core/frysk/hpd/WatchCommand.java b/frysk-core/frysk/hpd/WatchCommand.java
new file mode 100644
index 0000000..55b98d9
--- /dev/null
+++ b/frysk-core/frysk/hpd/WatchCommand.java
@@ -0,0 +1,163 @@
+// 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.hpd;
+
+import java.util.Iterator;
+import java.util.List;
+
+import frysk.expr.Expression;
+import frysk.proc.Action;
+import frysk.proc.Task;
+import frysk.proc.TaskObserver;
+import frysk.value.Value;
+
+class WatchCommand extends ParameterizedCommand {
+
+    private boolean writeOnly = true;
+    
+    WatchCommand() {
+	// XXX: Add details on thread-handling when implemented
+	super("Define a watchpoint",
+	      "watch <expression> [-a | -w]",
+	      ("The watch command defines a watchpoint that stops the"
+		+ " execution of a program when the memory location" 
+	        + " associated with an expression is read or written to"));
+		
+	
+	add(new CommandOption("w", "Trigger only on a write. (default)") {
+		void parse(String arg, Object options) {
+		    writeOnly = true;
+		}
+	    });
+	add(new CommandOption("a", "Trigger on read and write.") {
+		void parse(String arg, Object options) {
+		    writeOnly = false;
+		}
+	    });
+    }
+    
+    void interpret(CLI cli, Input cmd, Object arguments) {
+        if (cmd.size() < 1) {
+            throw new InvalidCommandException
+                ("missing argument");
+        }
+        
+        String expressionStr = cmd.parameter(0);        
+        
+	PTSet ptset = cli.getCommandPTSet(cmd);
+	Iterator taskIter = ptset.getTasks();
+
+	while (taskIter.hasNext()) {	   
+	    Task task = (Task) taskIter.next();
+	    
+	    Expression expr = null;
+	    try {
+		// Construct an Expression object from the expression string.
+		expr = cli.parseExpression(task, expressionStr);
+	    } catch (RuntimeException e) {
+		cli.outWriter.println();
+		cli.printError(e);
+		continue;
+	    }	    
+	    // XXX: will fail for non-contiguos memory and registers 
+	    // XXX: Add error handling
+	    long address = expr.getLocation().getAddress();
+	    
+	    // XXX: getValue may modify inferior.
+	    String oldValue = expr.getValue().toPrint();
+	    
+	    // Add a watch point observer to task.
+	    WatchpointObserver wpo = new WatchpointObserver(expr, cli, expressionStr, oldValue);
+	    task.requestAddWatchObserver(wpo, address, expr.getType().getSize(), writeOnly);
+	}       
+    }
+    
+    static class WatchpointObserver 
+    implements TaskObserver.Watch
+    {
+        Expression expr;
+	CLI cli;
+	String exprStr;
+	String oldValue;
+
+	WatchpointObserver(Expression expr, CLI cli, String exprStr, String oldValue) {
+	    this.expr = expr;
+	    this.cli = cli;
+	    this.exprStr = exprStr;
+	    this.oldValue = oldValue;
+
+	}
+	public Action updateHit(Task task, long address, int length) {
+	    
+	    Value newValue = expr.getValue();
+	    cli.outWriter.println("Watchpoint hit: " + exprStr); 
+	    cli.outWriter.println(); 
+	    cli.outWriter.println("   Value before hit = " + oldValue);
+	    cli.outWriter.println("   Value after  hit = " + newValue.toPrint());
+	    cli.outWriter.println(); 
+	    // Remember the previous value
+	    oldValue = newValue.toPrint();
+	  	    
+	    cli.getSteppingEngine().requestAddSteppingObserver(task);
+	    // Add the watch observer to the task's blockers list
+	    cli.getSteppingEngine().addBlocker(task, this);
+	    cli.getSteppingEngine().setTaskStopped(task);
+	    return Action.BLOCK;
+	}
+
+	public void addFailed(Object observable, Throwable w) {
+	    throw new RuntimeException("TaskObserver.Watch failed " +
+	    		               "to be added to the task");
+	}
+
+	public void addedTo(Object observable) {
+	    cli.outWriter.println("Watchpoint set: " + exprStr); 
+	}
+
+	public void deletedFrom(Object observable) {
+	}
+
+    }
+    
+    int completer(CLI cli, Input input, int cursor, List completions) {
+	return CompletionFactory.completeExpression(cli, input, cursor,
+						    completions);
+    }
+}
\ No newline at end of file
diff --git a/frysk-core/frysk/proc/ChangeLog b/frysk-core/frysk/proc/ChangeLog
index ce16160..374392e 100644
--- a/frysk-core/frysk/proc/ChangeLog
+++ b/frysk-core/frysk/proc/ChangeLog
@@ -1,5 +1,9 @@
-2008-04-15  Phil Muldoon  <pmuldoon@redhat.com>
+2008-04-15  Teresa Thomas  <tthomas@redhat.com>
 
+	* Task.java (isInstructionObserverAdded): New.
+	
+2008-04-15  Phil Muldoon  <pmuldoon@redhat.com>
+	
 	* TestTaskObserverWatchpoint.java (testWatchpointActionContinue): Reset
 	expected hit count to 1.
 
diff --git a/frysk-core/frysk/proc/Task.java b/frysk-core/frysk/proc/Task.java
index 7dccaf6..0858a8e 100644
--- a/frysk-core/frysk/proc/Task.java
+++ b/frysk-core/frysk/proc/Task.java
@@ -286,7 +286,11 @@ public abstract class Task {
      * Delete TaskObserver.Instruction from the TaskObserver pool.
      */
     public abstract void requestDeleteInstructionObserver(TaskObserver.Instruction o);
-
+    /**
+     * Returns true if the observer has been added to task's
+     * instruction observer list.
+     */
+    public abstract boolean isInstructionObserverAdded (TaskObserver.Instruction o);
     /**
      * Return the address of the instruction that this task will
      * execute next.
diff --git a/frysk-core/frysk/proc/dead/ChangeLog b/frysk-core/frysk/proc/dead/ChangeLog
index 0bee9bf..1782d8f 100644
--- a/frysk-core/frysk/proc/dead/ChangeLog
+++ b/frysk-core/frysk/proc/dead/ChangeLog
@@ -1,3 +1,7 @@
+2008-04-15  Teresa Thomas  <tthomas@redhat.com>
+
+	* DeadTask.java (isInstructionObserverAdded): New.
+
 2008-04-10  Stan Cox  <scox@redhat.com>
 
 	* TestLinuxExe.java (testSysRootedProc): Change to use funit-quicksort.
diff --git a/frysk-core/frysk/proc/dead/DeadTask.java b/frysk-core/frysk/proc/dead/DeadTask.java
index 595e430..a9e1e98 100644
--- a/frysk-core/frysk/proc/dead/DeadTask.java
+++ b/frysk-core/frysk/proc/dead/DeadTask.java
@@ -247,6 +247,10 @@ abstract class DeadTask extends Task {
     public void requestDeleteInstructionObserver(TaskObserver.Instruction o) {
 	throw new RuntimeException("requestDeleteInstructionObserver");
     }
+    
+    public boolean isInstructionObserverAdded (TaskObserver.Instruction o) {
+	throw new RuntimeException("isInstructionObserverAddded");
+    }
 
     public int getMod() {
 	return 1; // never changes.
diff --git a/frysk-core/frysk/proc/dummy/ChangeLog b/frysk-core/frysk/proc/dummy/ChangeLog
index 89c6d46..4bc94ad 100644
--- a/frysk-core/frysk/proc/dummy/ChangeLog
+++ b/frysk-core/frysk/proc/dummy/ChangeLog
@@ -1,3 +1,7 @@
+2008-04-15  Teresa Thomas  <tthomas@redhat.com>
+
+	* DummyTask.java (isInstructionObserverAdded): New.
+
 2008-04-02  Phil Muldoon  <pmuldoon@redhat.com>
 
 	* DummyTask.java (requestAddWatchObserver): Add writeOnly flag.
diff --git a/frysk-core/frysk/proc/dummy/DummyTask.java b/frysk-core/frysk/proc/dummy/DummyTask.java
index c3fb350..cbf939a 100644
--- a/frysk-core/frysk/proc/dummy/DummyTask.java
+++ b/frysk-core/frysk/proc/dummy/DummyTask.java
@@ -150,6 +150,10 @@ public class DummyTask extends Task {
 	throw new RuntimeException("oops!");
     }
 
+    public boolean isInstructionObserverAdded (TaskObserver.Instruction o) {
+	throw new RuntimeException("isInstructionObserverAddded");
+    }
+    
     public int getMod() {
 	return 1;
     }
diff --git a/frysk-core/frysk/proc/live/ChangeLog b/frysk-core/frysk/proc/live/ChangeLog
index ca9c6bb..8826d51 100644
--- a/frysk-core/frysk/proc/live/ChangeLog
+++ b/frysk-core/frysk/proc/live/ChangeLog
@@ -1,3 +1,7 @@
+2008-04-15  Teresa Thomas  <tthomas@redhat.com>
+
+	* LinuxPtraceTask.java (isInstructionObserverAdded): New.
+	
 2008-04-14  Andrew Cagney  <cagney@redhat.com>
 
 	* PtraceRegisterBanksFactory.java: Use frysk.config.Host.
diff --git a/frysk-core/frysk/proc/live/LinuxPtraceTask.java b/frysk-core/frysk/proc/live/LinuxPtraceTask.java
index a0f75c7..2121018 100644
--- a/frysk-core/frysk/proc/live/LinuxPtraceTask.java
+++ b/frysk-core/frysk/proc/live/LinuxPtraceTask.java
@@ -1013,6 +1013,7 @@ public class LinuxPtraceTask extends LiveTask {
 	}
 	return blockers.size();
     }
+    
     /**
      * Request the addition of a Instruction observer that will be
      * notified as soon as the task executes an instruction.
@@ -1031,6 +1032,10 @@ public class LinuxPtraceTask extends LiveTask {
 	fine.log(this, "requestDeleteInstructionObserver");
 	((LinuxPtraceProc)getProc()).requestDeleteInstructionObserver(this, instructionObservers, o);
     }
+    public boolean isInstructionObserverAdded (TaskObserver.Instruction o) {
+	fine.log(this, "isInstructionObserverAdded");
+	return (instructionObservers.contains(o))? true: false;
+    }    
   
     /**
      * List containing the TaskObservations that are pending addition
diff --git a/frysk-core/frysk/stepping/ChangeLog b/frysk-core/frysk/stepping/ChangeLog
index 5efeee7..d0e2f6e 100644
--- a/frysk-core/frysk/stepping/ChangeLog
+++ b/frysk-core/frysk/stepping/ChangeLog
@@ -1,3 +1,8 @@
+2008-04-15  Teresa Thomas  <tthomas@redhat.com>
+
+	* SteppingEngine.java (requestAddSteppingObserver): New.
+	(setTaskStopped): New.
+
 2008-03-19  Mark Wielaard  <mwielaard@redhat.com>
 
 	* InstructionStepState.java (InstructionStepState): Take and set
diff --git a/frysk-core/frysk/stepping/SteppingEngine.java b/frysk-core/frysk/stepping/SteppingEngine.java
index 7ff86f1..8902d4e 100644
--- a/frysk-core/frysk/stepping/SteppingEngine.java
+++ b/frysk-core/frysk/stepping/SteppingEngine.java
@@ -977,8 +977,34 @@ public class SteppingEngine {
     public void setTaskRunning(Task task) {
 	TaskStepEngine tse = null;
 	tse = (TaskStepEngine) this.taskStateMap.get(task);
-	    tse.setState(new RunningState(task));
+	tse.setState(new RunningState(task));
     }
+    
+    /**
+     * Set the current state of the task as stopped.  
+     */    
+    public void setTaskStopped(Task task) {
+
+	TaskStepEngine tse = null;
+	tse = (TaskStepEngine) this.taskStateMap.get(task);	
+	if (!tse.isStopped()) {
+	    tse.setState(new StoppedState(task));	
+	    // Remove the task from the running tasks list      
+	    this.runningTasks.remove(task);
+	}
+    }
+    
+    /**
+     * Requests the addition of the stepping observer to task if 
+     * not inserted already.
+     */
+    public void requestAddSteppingObserver(Task task) {
+
+	if (!(task.isInstructionObserverAdded(this.steppingObserver))) {
+	    task.requestAddInstructionObserver(this.steppingObserver);
+	}
+    }
+    
     /**
      * Adds the given Observer to this.steppingObserver's Observer list.
      * 


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-04-15 22:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-15 22:13 [SCM] master: Add watch command to hpd tthomas

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).