frysk.stepping
Class SteppingEngine

java.lang.Object
  extended by frysk.stepping.SteppingEngine

public class SteppingEngine
extends Object

State machine for thread and process stepping. Provides static methods for manipulating groups of threads by running, blocking, and various types of stepping.


Constructor Summary
SteppingEngine()
           
SteppingEngine(Proc[] procs)
          Sets the initial processes for this SteppingEngine.
SteppingEngine(Proc[] procs, Observer o)
           
 
Method Summary
 void addBlocker(Task task, TaskObserver observer)
          Add a blocker to the list of blockers that the stepping engine must unblock before continuing.
 void addBreakpoint(Task task, Breakpoint bp)
          Adds the given Breakpoint on the given Task.
 void addObserver(Observer o)
          Adds the given Observer to this.steppingObserver's Observer list.
 boolean addProc(Proc proc)
          Once SteppingEngine is already managing one or more Tasks, appends the given process to the data structures in SteppingEngine.
 void blockedByActionPoint(Task task, TaskObserver to)
          Sets the stepping engine on being hit by an action point.
 void blockedByActionPoint(Task task, TaskObserver to, String message, PrintWriter writer)
          Sets the stepping engine on being hit by an action point.
 void cleanTask(Task task)
          Clears information out of SteppingEngine data structures which are mapped to the given Task.
 void cleanUpBreakPoint(Task task)
           
 void clear()
          Removes all information from all SteppingEngine data structures.
 void continueExecution(LinkedList list)
          Deletes the blocking observer from each of the incoming tasks, effectively 'running', or continuing, the process.
 void continueExecution(Task task)
           
 boolean continueForStepping(Task task, boolean unblockStepper)
          Unblock a task so that, from the point of view of the stepping engine, execution can continue.
 void deleteBreakpoint(Task task, Breakpoint bp)
          Deletes the given Breakpoint from the given Task
 void detachProc(Proc proc, boolean kill)
          Detaches all observers and breakpoints from all Tasks of the given Proc.
 void executeTasks(LinkedList tasks)
          Method to handle am incoming list of tasks to be run, with four cases.
 LinkedList getAndClearBlockers(Task task)
          Get the list of blocking observers that have notified the stepping engine and clear it.
 LinkedList getBlockers(Task task)
          Get the list of blocking observers that have notified the stepping engine.
 BreakpointManager getBreakpointManager()
           
 HashSet getRunningTasks()
          Returns a Set of tasks currently in an executing state.
 frysk.stepping.SteppingEngine.SteppingObserver getSteppingObserver()
          Gets the this.steppingObserver currently being used by the SteppingEngine.
 Breakpoint getTaskBreakpoint(Task task)
          Returns the Breakpoint set on the given Task
 State getTaskState(Task task)
          Get the state of a particular Task.
 boolean isProcRunning(LinkedList tasks)
          Iterates through the given list of Tasks and returns true if any have a non-stopped state.
 boolean isTaskRunning(Task task)
          Checks to see if the state of the given task is not a stopped state.
 void removeBreakpoint(Task task)
          Removes the set SteppingBreakpoint from the given Task.
 void removeObserver(Observer o, Proc p, boolean unblock)
          Remove the incoming Observer object from the this.steppingObserver's list of Observers to notify.
 void requestAdd()
           
 void run(LinkedList tasks)
          When implemented, re-runs the process from the beginning of the debugging session if proper breakpoints are in place; otherwise just re-executes the process from its start.
 void setBreakpoint(Task task, long address)
          Sets a SteppingBreakpoint on the given Task at the given address.
 void setRunning(LinkedList tasks)
          Set the current state of the given tasks as running.
 void setTaskRunning(Task task)
          Set the current state of the given task as running.
 void setTaskState(Task task, State state)
          Set the state of a particular Task.
 void setThreadObserver(Observer o)
          Supplies an Observer to be added to the ThreadLifeObserver's Observer list.
 void setUp(LinkedList tasks, boolean isLine)
          Sets up stepping information for a list of Tasks.
 void stepAdvance(Task task, DebugInfoFrame frame)
          Steps the Task until it reaches the given frame's current address.
 boolean stepInstruction(LinkedList tasks)
          Perform an instruction step on a list of Tasks.
 boolean stepInstruction(Task task)
          Perform an instruction step on the given Task.
 boolean stepLine(LinkedList tasks)
          Perform a line-step on a list of Tasks
 boolean stepLine(Task task)
          Sets up SteppingEngine to perform a line step on the given Task.
 void stepNextInstruction(LinkedList tasks)
          Instruction steps the list of Tasks, but ensures that none enter any new frames on the stack.
 void stepNextInstruction(Task task, DebugInfoFrame lastFrame)
          Instruction stepping, but stepping-over any function calls.
 void stepOut(LinkedList tasks)
          Performs a step-out operation on a list of Tasks - runs each Task until it returns from its current frame.
 void stepOut(Task task, Frame frame)
          Sets the stage for stepping out of a frame.
 void stepOut(Task task, Frame frame, State state)
           
 void stepOver(LinkedList tasks)
          Performs a step-over operation on a list of tasks; none of the given Tasks will line-step into any new frames.
 void stepOver(Task task, DebugInfoFrame lastFrame)
          Performs a step-operation - line-steps the given Task, unless presented with an entry to a new frame on the stack, which will not be stepped into.
 void stop(LinkedList keepRunning, LinkedList stopTasks)
          Re-blocks all running Tasks except for those in the incoming LinkedList.
 void updateActionpointDoneEvent(String message, PrintWriter writer)
          Creates an actionpoint done event at the first sight of an action point.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SteppingEngine

public SteppingEngine()

SteppingEngine

public SteppingEngine(Proc[] procs)
Sets the initial processes for this SteppingEngine. Maps the initial keys in this.contextMap and this.taskStateMap for each Task from each Proc, and adds the necessary observers to each of the Tasks.

Parameters:
procs - The Procs to be managed by SteppingEngine

SteppingEngine

public SteppingEngine(Proc[] procs,
                      Observer o)
Method Detail

addProc

public boolean addProc(Proc proc)
Once SteppingEngine is already managing one or more Tasks, appends the given process to the data structures in SteppingEngine.

Parameters:
proc - The Proc to be added to SteppingEngine

stepInstruction

public boolean stepInstruction(Task task)
Perform an instruction step on the given Task.

Parameters:
task - The Task to be stepped a single instruction.
Returns:
false The Task is not currently blocked

stepInstruction

public boolean stepInstruction(LinkedList tasks)
Perform an instruction step on a list of Tasks.

Parameters:
tasks - The Tasks to be stepped a single instruction.
Returns:
false Not all tasks are currently blocked.

stepLine

public boolean stepLine(Task task)
Sets up SteppingEngine to perform a line step on the given Task.

Parameters:
task - The Task to be line-stepped
Returns:
false The Task is not currently blocked

stepLine

public boolean stepLine(LinkedList tasks)
Perform a line-step on a list of Tasks

Parameters:
tasks - The Tasks to line step
Returns:
false Not all tasks are currently blocked.

setUp

public void setUp(LinkedList tasks,
                  boolean isLine)
Sets up stepping information for a list of Tasks. Checks line numbers and whether the Tasks have any debuginfo at this point in time, before proceeding.

Parameters:
tasks - The Tasks to begin stepping
isLine - Whether this set up is for a line step or otherwise.

stepAdvance

public void stepAdvance(Task task,
                        DebugInfoFrame frame)
Steps the Task until it reaches the given frame's current address. Intended to be used when the given frame is a frame on the stack which is outer to the innermost frame; thus the Task will continue until the frames inner to this one have all returned.

Parameters:
task - The Task to be stepped.
frame - The frame on the stack to be continued to.

stepNextInstruction

public void stepNextInstruction(Task task,
                                DebugInfoFrame lastFrame)
Instruction stepping, but stepping-over any function calls.

Parameters:
task - The stepping Task
lastFrame - The current innermost frame of the Task

stepNextInstruction

public void stepNextInstruction(LinkedList tasks)
Instruction steps the list of Tasks, but ensures that none enter any new frames on the stack.

Parameters:
tasks - The list of Tasks to be stepped

stepOver

public void stepOver(Task task,
                     DebugInfoFrame lastFrame)
Performs a step-operation - line-steps the given Task, unless presented with an entry to a new frame on the stack, which will not be stepped into.

Parameters:
task - The Task to be stepped-over
lastFrame - The current innermost StackFrame of the given Task

stepOver

public void stepOver(LinkedList tasks)
Performs a step-over operation on a list of tasks; none of the given Tasks will line-step into any new frames.

Parameters:
tasks - The Tasks to step.

stepOut

public void stepOut(Task task,
                    Frame frame)
Sets the stage for stepping out of a frame. Runs until a breakpoint on the return address is hit.

Parameters:
task - The Task to be stepped
frame - The frame to step out of.

stepOut

public void stepOut(Task task,
                    Frame frame,
                    State state)

stepOut

public void stepOut(LinkedList tasks)
Performs a step-out operation on a list of Tasks - runs each Task until it returns from its current frame.

Parameters:
tasks - The Tasks to step-out

cleanUpBreakPoint

public void cleanUpBreakPoint(Task task)

run

public void run(LinkedList tasks)
When implemented, re-runs the process from the beginning of the debugging session if proper breakpoints are in place; otherwise just re-executes the process from its start.


continueExecution

public void continueExecution(LinkedList list)
Deletes the blocking observer from each of the incoming tasks, effectively 'running', or continuing, the process.

Parameters:
tasks - The list of Tasks to be run

continueExecution

public void continueExecution(Task task)

continueForStepping

public boolean continueForStepping(Task task,
                                   boolean unblockStepper)
Unblock a task so that, from the point of view of the stepping engine, execution can continue. For now this unblocks instruction observers and code observers for breakpoints, but ultimately I (timoore) think it should unblock all blockers.


stop

public void stop(LinkedList keepRunning,
                 LinkedList stopTasks)
Re-blocks all running Tasks except for those in the incoming LinkedList. If the list is null or has size zero, than by default all Tasks are blocked by the ProcBlockObserver. Otherwise, the list is compared to the set of running tasks and those Tasks not in the list are stopped.

Parameters:
keepRunning - The list of Tasks to not block

executeTasks

public void executeTasks(LinkedList tasks)
Method to handle am incoming list of tasks to be run, with four cases. Case 1: List of tasks is empty, and there are no running tasks. Case 2: List of tasks is empty, and there are running tasks. Case 3: List of tasks is not empty, and there are no running tasks. Case 4: List of tasks is not empty, and there are running tasks. It is assumed that any running Tasks not in the incoming list are to be blocked, and all tasks in that list are to be unblocked or run. If any of those Tasks are already running, leave them be. Return an int representing which state the calling class should be in after this method is executed.

Parameters:
tasks - The list of tasks to be run

isProcRunning

public boolean isProcRunning(LinkedList tasks)
Iterates through the given list of Tasks and returns true if any have a non-stopped state. Tasks are assumed be Tasks from the same Proc.

Parameters:
tasks - The Tasks to check states for.
Returns:
true If any of the Tasks are not stopped

isTaskRunning

public boolean isTaskRunning(Task task)
Checks to see if the state of the given task is not a stopped state.

Parameters:
task - The Task to check the state of
Returns:
true If the Task is not stopped

detachProc

public void detachProc(Proc proc,
                       boolean kill)
Detaches all observers and breakpoints from all Tasks of the given Proc.

Parameters:
proc - The Proc to be detached
kill - Whether the Proc should be killed after detaching

cleanTask

public void cleanTask(Task task)
Clears information out of SteppingEngine data structures which are mapped to the given Task.

Parameters:
task - The Task to clear information for

clear

public void clear()
Removes all information from all SteppingEngine data structures.


setTaskState

public void setTaskState(Task task,
                         State state)
Set the state of a particular Task.

Parameters:
task - The Task to set the state of
state - The State to set it to

getTaskState

public State getTaskState(Task task)
Get the state of a particular Task.

Parameters:
task - The Task to return the State of
Returns:
state The State of the given Task

getSteppingObserver

public frysk.stepping.SteppingEngine.SteppingObserver getSteppingObserver()
Gets the this.steppingObserver currently being used by the SteppingEngine.

Returns:
this.steppingObserver The this.steppingObserver currently in use

setBreakpoint

public void setBreakpoint(Task task,
                          long address)
Sets a SteppingBreakpoint on the given Task at the given address.

Parameters:
task - The Task to breakpoint
address - The address to set the breakpoint at

removeBreakpoint

public void removeBreakpoint(Task task)
Removes the set SteppingBreakpoint from the given Task.

Parameters:
task - The Task to remove the SteppingBreakpoint from

getTaskBreakpoint

public Breakpoint getTaskBreakpoint(Task task)
Returns the Breakpoint set on the given Task

Parameters:
task - The Task whose breakpoint is requested
Returns:
bp The Breakpoint set at the given Task

addBreakpoint

public void addBreakpoint(Task task,
                          Breakpoint bp)
Adds the given Breakpoint on the given Task.

Parameters:
task - The Task to have the Breakpoint added to
bp - The Breakpoint to add to the given Task

deleteBreakpoint

public void deleteBreakpoint(Task task,
                             Breakpoint bp)
Deletes the given Breakpoint from the given Task

Parameters:
task - The Task to delete the Breakpoint from
bp - The Breakpoint to delete from the given Task

setRunning

public void setRunning(LinkedList tasks)
Set the current state of the given tasks as running. Used when the running of these Tasks was out of the scope of control for SteppingEngine.

Parameters:
tasks - The Tasks to be set as running.

setTaskRunning

public void setTaskRunning(Task task)
Set the current state of the given task as running. Used when the running of this task was out of the scope of control for SteppingEngine.

Parameters:
task - to be set as running

blockedByActionPoint

public void blockedByActionPoint(Task task,
                                 TaskObserver to)
Sets the stepping engine on being hit by an action point. to - Observer that causes task to block.


blockedByActionPoint

public void blockedByActionPoint(Task task,
                                 TaskObserver to,
                                 String message,
                                 PrintWriter writer)
Sets the stepping engine on being hit by an action point. to - Observer that causes task to block. message - message describing the cause of program block writer - writer to print message to


updateActionpointDoneEvent

public void updateActionpointDoneEvent(String message,
                                       PrintWriter writer)
Creates an actionpoint done event at the first sight of an action point. This event process the action point messages to be outputted.

Parameters:
message - - Actionpoint information message to be added
writer - - writer to print message to

addObserver

public void addObserver(Observer o)
Adds the given Observer to this.steppingObserver's Observer list.

Parameters:
o - The Observer to be added.

setThreadObserver

public void setThreadObserver(Observer o)
Supplies an Observer to be added to the ThreadLifeObserver's Observer list.

Parameters:
o - The Observer to be added.

getRunningTasks

public HashSet getRunningTasks()
Returns a Set of tasks currently in an executing state.

Returns:
runningTasks The Tasks in an executing state.

removeObserver

public void removeObserver(Observer o,
                           Proc p,
                           boolean unblock)
Remove the incoming Observer object from the this.steppingObserver's list of Observers to notify. Unblocks the given process if required.

Parameters:
o - The Observer to delete
p - The Proc to delete the Observer from
unblock - Whether the given Proc should be unblocked

requestAdd

public void requestAdd()

getBreakpointManager

public BreakpointManager getBreakpointManager()

addBlocker

public void addBlocker(Task task,
                       TaskObserver observer)
Add a blocker to the list of blockers that the stepping engine must unblock before continuing.

Parameters:
task - the task
observer - the blocker

getBlockers

public LinkedList getBlockers(Task task)
Get the list of blocking observers that have notified the stepping engine.

Parameters:
task - the task
Returns:
list of blockers

getAndClearBlockers

public LinkedList getAndClearBlockers(Task task)
Get the list of blocking observers that have notified the stepping engine and clear it.

Parameters:
task - the task
Returns:
list of blockers