public final class SuspendedEvent extends Object
Debugger clients to the state of a guest language execution thread that has
been suspended, for example by a Breakpoint or stepping action.
DebuggerSession instruments guest language code in order to
implement breakpoints, stepping actions, or other debugging actions on
behalf of the session's debugger client.SuspendedEvent to the debugger client (synchronously) in a
callback on the guest language execution
thread.IllegalStateException. Please see the javadoc of the individual method for details.IllegalStateException after the suspended thread resumes
guest language execution.
SuspendedEvent.getStackFrames() describes the suspended thread's location in guest language
code. This information becomes unusable beyond the lifetime of the event and must not be stored.
SuspendedEvent.getReturnValue() describes a local result when the thread is suspended just
after a frame.Clients use the following methods to request the debugging action(s) that will take effect when the event's thread resumes guest language execution. All prepare requests accumulate until resumed.
SuspendedEvent.prepareStepInto(int)SuspendedEvent.prepareStepOut(int)SuspendedEvent.prepareStepOver(int)SuspendedEvent.prepareKill()SuspendedEvent.prepareContinue()continue is assumed.
| Modifier and Type | Method and Description |
|---|---|
Throwable |
getBreakpointConditionException(Breakpoint breakpoint)
Returns the cause of failure, if any, during evaluation of a breakpoint's
condition.
|
List<Breakpoint> |
getBreakpoints()
Returns the
breakpoints that individually would cause the "hit" where
execution is suspended. |
DebugValue |
getReturnValue()
Returns the return value of the currently executed source location.
|
DebuggerSession |
getSession()
Returns the debugger session this suspended event was created for.
|
SourceSection |
getSourceSection()
Returns the guest language source section of the AST node before/after the execution is
suspended.
|
Iterable<DebugStackFrame> |
getStackFrames()
Returns a list of guest language stack frame objects that indicate the current guest language
location.
|
DebugStackFrame |
getTopStackFrame()
Returns the topmost stack frame returned by
SuspendedEvent.getStackFrames(). |
boolean |
isHaltedBefore()
Returns
true if the execution is suspended before executing a guest language
source location. |
boolean |
isLanguageContextInitialized()
Test if the language context of the source of the event is initialized.
|
void |
prepareContinue()
Prepare to execute in Continue mode when guest language program execution resumes.
|
void |
prepareKill()
Prepare to terminate the suspended execution represented by this event.
|
SuspendedEvent |
prepareStepInto(int stepCount)
Prepare to execute in StepInto mode when guest language program execution
resumes.
|
SuspendedEvent |
prepareStepOut(int stepCount)
Prepare to execute in StepOut mode when guest language program execution
resumes.
|
SuspendedEvent |
prepareStepOver(int stepCount)
Prepare to execute in StepOver mode when guest language program execution resumes.
|
String |
toString() |
public DebuggerSession getSession()
This method is thread-safe.
public SourceSection getSourceSection()
null if no source section information is available.
This method is thread-safe.
public boolean isHaltedBefore()
true if the execution is suspended before executing a guest language
source location. Returns false if it was suspended after.
This method is thread-safe..
public boolean isLanguageContextInitialized()
public DebugValue getReturnValue()
null
if the execution is suspended before a guest language location. The
returned value is null if an exception occurred during execution of the
instrumented statement. The debug value remains valid event if the current execution was
suspend.
This method is not thread-safe and will throw an IllegalStateException if called on
another thread than it was created with.
public Throwable getBreakpointConditionException(Breakpoint breakpoint)
This method is thread-safe.
breakpoint - a breakpoint associated with this eventpublic List<Breakpoint> getBreakpoints()
breakpoints that individually would cause the "hit" where
execution is suspended.
This method is thread-safe.
public DebugStackFrame getTopStackFrame()
SuspendedEvent.getStackFrames().
This method is not thread-safe and will throw an IllegalStateException if called on
another thread than it was created with.
SuspendedEvent.getStackFrames()public Iterable<DebugStackFrame> getStackFrames()
suspend and should not be stored permanently.
This method is not thread-safe and will throw an IllegalStateException if called on
another thread than it was created with.
public void prepareContinue()
This method is thread-safe and the prepared Continue mode is appended to any other previously prepared modes. No further modes can be prepared after continue.
IllegalStateException - when continue or
kill is prepared already.public SuspendedEvent prepareStepInto(int stepCount)
stepCount) with the
tag StandardTags.StatementTag, orBreakpoint, orThis method is thread-safe and the prepared StepInto mode is appended to any other previously prepared modes.
stepCount - the number of times to perform StepInto before haltingIllegalArgumentException - if stepCount <= 0IllegalStateException - when continue or
kill is prepared already.public SuspendedEvent prepareStepOut(int stepCount)
stepCount), orBreakpoint, orThis method is thread-safe and the prepared StepOut mode is appended to any other previously prepared modes.
stepCount - the number of times to perform StepOver before haltingIllegalArgumentException - if stepCount <= 0IllegalStateException - when continue or
kill is prepared already.public SuspendedEvent prepareStepOver(int stepCount)
stepCount) with the
tag StandardTags.StatementTag, ignoring nodes nested in function/method calls, or
Breakpoint, orhit;This method is thread-safe and the prepared StepOver mode is appended to any other previously prepared modes.
stepCount - the number of times to perform StepOver before haltingIllegalArgumentException - if stepCount <= 0IllegalStateException - when continue or
kill is prepared already.public void prepareKill()
class ExecWithTimeOut {
boolean pauseRequested;
void executeWithTimeOut(
ScheduledExecutorService executor, // run us later
PolyglotEngine.Value function, // unknown function
Object parameter // parameter of the function
) {
executor.schedule(new Runnable() {
public void run() {
Debugger.find(engine).startSession(new SuspendedCallback() {
public void onSuspend(SuspendedEvent event) {
pauseRequested = true;
event.prepareKill();
}
});
}
}, 10, TimeUnit.SECONDS);
Throwable caught = null;
try {
// execute with timer on
function.execute(parameter);
} catch (ThreadDeath t) {
caught = t;
}
if (pauseRequested) {
assertTrue("Pause requested", pauseRequested);
assertNotNull("Execution ended with throwable", caught);
assertEquals("Our Exception", // prepareKill produces
"com.oracle.truffle.api.debug.KillException", //
caught.getClass().getName());
}
}
}
This method is thread-safe and the prepared termination is appended to any other previously prepared modes. No further modes can be prepared after kill.
IllegalStateException - when continue or
kill is prepared already.