This is the mail archive of the
frysk@sources.redhat.com
mailing list for the frysk project.
Merging Running and runningInSyscall TaskStates
- From: Mark Wielaard <mark at klomp dot org>
- To: frysk at sourceware dot org
- Date: Fri, 08 Sep 2006 12:46:23 +0200
- Subject: Merging Running and runningInSyscall TaskStates
Hi,
Another episode in the continuous merging of states story. This patch
merges the Running and runningInSyscall TaskStates. It removes another
100+ lines of duplicate code which is good.
2006-09-08 Mark Wielaard <mark@klomp.org>
* TaskState.java: Merge Running and runningInSyscall states.
We are really almost done with this (hopefully end of the day at the
latest). Then we can finally mix and match signal, syscall and
breakpoint observers whenever we want.
The reason I am posting this is small installments is because this is
pretty central code and I want to make sure I don't break anything. I
test on x86 and x86_64 each time (fc5 for now). And it should make it
easier for people to spot silly mistakes or yell and scream if they
think I am moving in the wrong direction.
Next up are the transitionToSyscallRunning and
transitionOutOfSyscallRunning states. Then we need to move the pending
code observers into the Task so they can be easily shared by the
TaskStates. And then we should be finally done.
Cheers,
Mark
Index: frysk-core/frysk/proc/TaskState.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/proc/TaskState.java,v
retrieving revision 1.112
diff -u -r1.112 TaskState.java
--- frysk-core/frysk/proc/TaskState.java 7 Sep 2006 20:11:47 -0000 1.112
+++ frysk-core/frysk/proc/TaskState.java 8 Sep 2006 10:24:29 -0000
@@ -738,12 +738,18 @@
private static class Running
extends TaskState
{
- private final boolean syscalltracing;
+ // Whether or not we are tracing syscalls
+ private final boolean syscalltracing;
- protected Running (String state, boolean syscalltracing)
+ // Whether or not we are running inside a syscall
+ private final boolean insyscall;
+
+ protected Running (String state,
+ boolean syscalltracing, boolean insyscall)
{
super (state);
this.syscalltracing = syscalltracing;
+ this.insyscall = insyscall;
}
/**
@@ -759,10 +765,12 @@
/**
* Returns a blocked TaskState depending on whether we are
- * syscall tracing the Task.
+ * syscall tracing the Task and being inside or outside a syscall.
*/
private TaskState blockedContinue()
{
+ if (insyscall)
+ return syscallBlockedInSyscallContinue;
return syscalltracing ? syscallBlockedContinue : blockedContinue;
}
@@ -770,7 +778,7 @@
{
logger.log (Level.FINE, "{0} handleSignaledEvent, signal: {1}\n", new Object[] {task, new Integer(sig)});
if (task.notifySignaled (sig) > 0) {
- return new BlockedSignal(sig, syscalltracing, false);
+ return new BlockedSignal(sig, syscalltracing, insyscall);
}
else {
sendContinue(task, sig);
@@ -828,21 +836,21 @@
TaskState handleTerminatingEvent (Task task, boolean signal,
int value)
{
- logger.log (Level.FINE, "{0} handleTerminatingEvent\n", task);
- if(task.notifyTerminating (signal, value) > 0){
- if (signal){
- return new BlockedSignal(value, syscalltracing, false);
- }else{
- return blockedContinue();
- }
- }
+ logger.log(Level.FINE, "{0} handleTerminatingEvent\n", task);
+ if(task.notifyTerminating (signal, value) > 0)
+ {
+ if (signal)
+ return new BlockedSignal(value, syscalltracing, insyscall);
+ else
+ return blockedContinue();
+ }
- if (signal)
- sendContinue(task, value);
- else
- sendContinue(task, 0);
+ if (signal)
+ sendContinue(task, value);
+ else
+ sendContinue(task, 0);
- return this;
+ return this;
}
TaskState handleTerminatedEvent (Task task, boolean signal,
int value)
@@ -860,12 +868,17 @@
((LinuxProc)task.proc).getStat ().refresh();
if (task.notifyExeced () > 0)
{
- return blockedInExecSyscall;
+ return (syscalltracing
+ ? syscallBlockedInSyscallContinue
+ : blockedInExecSyscall);
}
else
{
- sendContinue(task, 0);
- return this;
+ if (syscalltracing)
+ task.sendSyscallContinue(0);
+ else
+ sendContinue(task, 0);
+ return runningInSyscall;
}
}
TaskState handleDisappearedEvent (Task task, Throwable w)
@@ -1042,7 +1055,6 @@
}
return this;
}
-
TaskState handleDeleteSyscallObserver(Task task,
Observable observable,
Observer observer)
@@ -1063,12 +1075,21 @@
TaskState handleSyscalledEvent(Task task)
{
logger.log (Level.FINE, "{0} handleSyscalledEvent\n", task);
- if (task.notifySyscallEnter () > 0)
- return syscallBlockedInSyscallContinue;
- else
+ if (syscalltracing)
{
+ if (! insyscall && task.notifySyscallEnter() > 0)
+ return syscallBlockedInSyscallContinue;
+
+ if (insyscall && task.notifySyscallExit() > 0)
+ return syscallBlockedContinue;
+
task.sendSyscallContinue(0);
- return runningInSyscall;
+ return insyscall ? syscallRunning : runningInSyscall;
+ }
+ else
+ {
+ task.sendContinue(0);
+ return this;
}
}
@@ -1078,20 +1099,12 @@
* options and trasition to syscallRunning.
*/
private static TaskState transitionToSyscallRunning = new TaskState("transitionToSyscallRunning"){
- TaskState handleAddObserver (Task task, Observable observable,
- Observer observer)
- {
- logger.log(Level.FINE, "{0} handleAddObserver\n", task);
- observable.add(observer);
- return running;
- }
-
TaskState handleDeleteObserver (Task task, Observable observable,
Observer observer)
{
logger.log(Level.FINE, "{0} handleDeleteObserver\n", task);
observable.delete(observer);
- return running;
+ return this;
}
TaskState handleAddSyscallObserver (Task task, Observable observable, Observer observer)
{
@@ -1147,142 +1160,17 @@
* Sharable instance of the running state.
*/
private static final TaskState running =
- new Running("running", false);
+ new Running("running", false, false);
/**
* Sharable instance of the syscallRunning state.
*/
private static final TaskState syscallRunning =
- new Running("syscallRunning", true);
-
+ new Running("syscallRunning", true, false);
// Task is running inside a syscall.
private static final TaskState runningInSyscall =
- new TaskState ("runningInSyscall")
- {
- // XXX: We needn't look for signal events because the
- // syscall will exit before we get the signal, however, we still.
- // need to look for terminating and terminated events
- // because an exit syscall will produce these events and
- // never produce a syscall-exit event.
-
- TaskState handleSyscalledEvent (Task task)
- {
- logger.log (Level.FINE, "{0} handleSyscalledEvent\n", task);
- if(task.notifySyscallExit () > 0){
- return syscallBlockedContinue;
- }else{
- task.sendSyscallContinue (0);
- return syscallRunning;
- }
- }
- TaskState handleTerminatingEvent (Task task, boolean signal,
- int value)
- {
- logger.log (Level.FINE, "{0} handleTerminatingEvent\n", task);
-
- if(task.notifyTerminating (signal, value) > 0){
- if (signal)
- return new SyscallBlockedInSyscall(value);
- else
- return syscallBlockedInSyscallContinue;
- }
-
- task.notifyTerminating (signal, value);
- if (signal)
- task.sendSyscallContinue (value);
- else
- task.sendSyscallContinue (0);
- return runningInSyscall;
- }
- TaskState handleTerminatedEvent (Task task, boolean signal,
- int value)
- {
- logger.log (Level.FINE, "{0} handleTerminatedEvent\n", task);
- task.proc.remove (task);
- handleAttachedTerminated (task, signal, value);
- return destroyed;
- }
- TaskState handleContinue (Task task)
- {
- logger.log (Level.FINE, "{0} handleContinue\n", task);
- return runningInSyscall;
- }
- TaskState handleDetach (Task task)
- {
- logger.log (Level.FINE, "{0} handleDetach\n", task);
- task.sendStop ();
- return detaching;
- }
- TaskState handleExecedEvent (Task task)
- {
- logger.log (Level.FINE, "{0} handleExecedEvent\n", task);
- // Remove all tasks, retaining just this one.
- task.proc.retain (task);
- ((LinuxProc)task.proc).getStat ().refresh();
- if (task.notifyExeced () > 0) {
- return syscallBlockedInSyscallContinue;
- }
- else {
- task.sendSyscallContinue (0);
- return runningInSyscall;
- }
- }
- TaskState handleAddObserver (Task task, Observable observable,
- Observer observer)
- {
- logger.log (Level.FINE, "{0} handleAddObserver\n", task);
- observable.add (observer);
- return this;
- }
- TaskState handleAddSyscallObserver(Task task,
- Observable observable,
- Observer observer)
- {
- // Nothing special to do, we are already traceing syscalls.
- logger.log (Level.FINE, "{0} handleAddSyscallObserver\n", task);
- observable.add(observer);
- return this;
- }
- TaskState handleDeleteSyscallObserver (Task task, Observable observable, Observer observer)
- {
- logger.log(Level.FINE, "{0} handleDeleteSyscallObserver\n", task);
- observable.delete(observer);
- if(observable.numberOfObservers() == 0){
- task.sendStop();
- return transitionOutOfSyscallRunning;
- }else{
- return this;
- }
- }
- TaskState handleForkedEvent (Task task, Task fork)
- {
- logger.log (Level.FINE, "{0} handleForkedEvent\n", task);
- if (task.notifyForkedParent (fork) > 0)
- return syscallBlockedInSyscallContinue;
- task.sendSyscallContinue (0);
- return runningInSyscall;
- }
- TaskState handleClonedEvent (Task task, Task clone)
- {
- logger.log (Level.FINE, "{0} handleClonedEvent\n", task);
- if (task.notifyClonedParent (clone) > 0)
- return syscallBlockedInSyscallContinue;
- task.sendSyscallContinue (0);
- return runningInSyscall;
- }
- TaskState handleSignaledEvent (Task task, int sig)
- {
- logger.log (Level.FINE, "{0} handleSignaledEvent\n", task);
- if (task.notifySignaled (sig) > 0) {
- return new SyscallBlockedInSyscall (sig);
- }
- else {
- task.sendSyscallContinue (sig);
- return runningInSyscall;
- }
- }
- };
+ new Running("runningInSyscall", true, true);
private static final TaskState detaching = new TaskState ("detaching")
{