public final class DebuggerSession extends Object implements Closeable
SuspendedEvent
via synchronous callback on the execution
thread.Session clients can manage guest language execution in several ways:
Breakpoint
.A session may suspend a guest language execution thread in response to more than one request from its client. For example:
There can be multiple sessions associated with a single engine, which are independent of one another in the following ways:
SuspendedEvent
instance.Usage example:
try (DebuggerSession
session =Debugger
.find(instrumentEnv). startSession(newSuspendedCallback
() { public void onSuspend(SuspendedEvent
event) { // step into the next event event.prepareStepInto(1); } })) {Source
someCode =Source
.newBuilder("...", "...", "example").build(); // install line breakpoint session.install(Breakpoint
.newBuilder(someCode).lineIs(3).build()); }
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the current debugging session and disposes all installed breakpoints.
|
DebugValue |
createPrimitiveValue(Object primitiveValue,
LanguageInfo language)
Creates a
DebugValue object that wraps a primitive value. |
List<Breakpoint> |
getBreakpoints()
Returns all breakpoints
installed
in this session, in the install order. |
Debugger |
getDebugger()
Returns the
debugger instance that this session is associated with. |
Map<String,? extends DebugValue> |
getExportedSymbols()
Returns a polyglot scope - symbols explicitly exported by languages.
|
DebugScope |
getTopScope(String languageId)
Returns a language top scope.
|
Breakpoint |
install(Breakpoint breakpoint)
Adds a new breakpoint to this session and makes it capable of suspending execution.
|
boolean |
isBreakpointsActive(Breakpoint.Kind breakpointKind)
Test whether breakpoints of the given kind are active in this session.
|
Source |
resolveSource(Source source)
Resolve the source with respect to the actual
source path . |
void |
resume(Thread t)
Resumes the execution on a given thread if it has not been suspended yet.
|
void |
resumeAll()
Resumes all suspended executions that have not yet been notified.
|
void |
setAsynchronousStackDepth(int depth)
Request for languages to provide stack frames of scheduled asynchronous execution.
|
void |
setBreakpointsActive(Breakpoint.Kind breakpointKind,
boolean active)
Set whether breakpoints of the given kind are active in this session.
|
void |
setContextsListener(DebugContextsListener listener,
boolean includeActiveContexts)
Set a
listener to be notified about changes in contexts in
guest language application. |
void |
setShowHostStackFrames(boolean showHostStackFrames)
Set to provide host information in stack traces.
|
void |
setSourcePath(Iterable<URI> uris)
Set a list of source path roots that are used to resolve relative
source URIs . |
void |
setSteppingFilter(SuspensionFilter steppingFilter)
Set a stepping suspension filter.
|
void |
setThreadsListener(DebugThreadsListener listener,
boolean includeInitializedThreads)
Set a
listener to be notified about changes in threads in guest
language application. |
void |
suspend(Thread t)
Suspends the current or the next execution of a given thread.
|
void |
suspendAll()
Suspends the current or the next execution on all threads.
|
boolean |
suspendHere(Node node)
Suspend immediately at the current location of the current execution thread.
|
void |
suspendNextExecution()
Suspends the next execution on the first thread that is encountered.
|
String |
toString() |
public Debugger getDebugger()
debugger
instance that this session is associated with. Can be
used also after the session has already been closed.public DebugScope getTopScope(String languageId) throws DebugException
DebugStackFrame.getScope()
have no relation to the suspended location.DebugException
- when guest language code throws an exceptionpublic Map<String,? extends DebugValue> getExportedSymbols()
public void setShowHostStackFrames(boolean showHostStackFrames)
true
,
host frames
and host
trace elements
are provided, when available.DebugStackFrame.isHost()
,
DebugStackTraceElement.isHost()
public void setSteppingFilter(SuspensionFilter steppingFilter)
public void suspendNextExecution()
DebuggerSession.suspendNextExecution()
is
called again. If multiple threads are executing at the same time then there are no guarantees
on which thread is going to be suspended. Will throw an IllegalStateException
if the
session is already closed.public boolean suspendHere(Node node)
Node
argument can be provided as an exact current location, if known. This method can be called on
the guest execution thread only.
This method calls SuspendedCallback.onSuspend(SuspendedEvent)
synchronously, with
SuspendedEvent
created at the actual location of the current thread. This method can
not be called from an existing callback
.
node
- the top Node of the execution, or null
true
when there is a guest code execution on the current thread and
SuspendedCallback
was called, false
otherwise.IllegalStateException
- when the current thread is suspended alreadyIllegalArgumentException
- when a node with no RootNode
is provided, or it's
root node does not match the current execution root, or the node does not match
the current call node, if known.public void suspend(Thread t)
IllegalStateException
if the session is already closed.public void suspendAll()
DebuggerSession.resumeAll()
is called or the session is closed. Will throw an
IllegalStateException
if the session is already closed.public void resumeAll()
public void resume(Thread t)
t
- the thread to resumepublic DebugValue createPrimitiveValue(Object primitiveValue, LanguageInfo language) throws IllegalArgumentException
DebugValue
object that wraps a primitive value. Strings and boxed Java
primitive types are considered primitive. Throws IllegalArgumentException
if the
value is not primitive.primitiveValue
- a primitive valuelanguage
- guest language this value is value is associated with. Some value attributes
depend on the language, like DebugValue.getMetaObject()
. Can be
null
.DebugValue
that wraps the primitive value.IllegalArgumentException
- if the value is not a boxed Java primitive or a String.public void close()
close
in interface Closeable
close
in interface AutoCloseable
public List<Breakpoint> getBreakpoints()
installed
in this session, in the install order. The returned list contains a current snapshot of
breakpoints, those that were disposed
, or
installed on Debugger
are
not included.Debugger.getBreakpoints()
public void setBreakpointsActive(Breakpoint.Kind breakpointKind, boolean active)
breakpointKind
- the kind of breakpoints to activate/deactivateactive
- true
to make breakpoints active, false
to make
breakpoints inactive.public boolean isBreakpointsActive(Breakpoint.Kind breakpointKind)
breakpointKind
- the kind of breakpoints to testpublic Breakpoint install(Breakpoint breakpoint)
The breakpoint suspends execution by making a callback
to this
session, together with an event description that includes
which breakpoint(s) were hit.
breakpoint
- a new breakpointIllegalStateException
- if the session has been closedpublic void setAsynchronousStackDepth(int depth)
depth
asynchronous stack frames are asked for. When multiple debugger sessions
or other instruments call this method, the languages get a maximum depth of these calls and
may therefore provide longer asynchronous stacks than requested. Also, languages may provide
asynchronous stacks if it's of no performance penalty, or if requested by other options.
Asynchronous stacks can then be accessed via SuspendedEvent.getAsynchronousStacks()
,
or DebugException.getDebugAsynchronousStacks()
.depth
- the requested stack depth, 0 means no asynchronous stack frames are required.SuspendedEvent.getAsynchronousStacks()
,
DebugException.getDebugAsynchronousStacks()
public void setContextsListener(DebugContextsListener listener, boolean includeActiveContexts)
listener
to be notified about changes in contexts in
guest language application. One listener can be set at a time, call with null
to
remove the current listener.listener
- a listener to receive the context events, or null
to reset itincludeActiveContexts
- whether or not this listener should be notified for present
active contextspublic void setThreadsListener(DebugThreadsListener listener, boolean includeInitializedThreads)
listener
to be notified about changes in threads in guest
language application. One listener can be set at a time, call with null
to
remove the current listener.listener
- a listener to receive the context eventsincludeInitializedThreads
- whether or not this listener should be notified for present
initialized threadspublic void setSourcePath(Iterable<URI> uris)
source URIs
. All debugger methods that provide Source
object, resolve relative
sources with respect to this source-path. When the resolution does not succeed (the relative
path does not exist under any of the supplied source-path elements), the original relative
Source
is provided.uris
- a list of absolute URIsIllegalArgumentException
- when an URI is not absoluteDebuggerSession.resolveSource(Source)
public Source resolveSource(Source source)
source path
.
Sources with relative URI
are subject to resolution to an existing
absolute location. The first source-path URI that resolves to an existing location is used.source
- the source to resolvenull
when it's not possible to resolve the provided source