Class Breakpoint
Breakpoint lifetime
- A client of a
DebuggerSession
uses aBreakpoint.Builder
to create a new breakpoint, choosing among multiple ways to specify the intended location. Examples include a specifiedsource
, a specifiedURI
, line ranges, or an exactSourceSection
. - A new breakpoint cannot affect execution until after it has been installed by a session, which may be done only once.
- A breakpoint that is both installed and enabled (true by default) will suspend any guest language execution thread that arrives at a matching AST location. The breakpoint (synchronously) calls back to the responsible session on the execution thread.
- A breakpoint may be enabled or disabled any number of times.
- A breakpoint that is no longer needed may be disposed. A disposed
breakpoint:
- is disabled
- is not installed in any session
- can have no effect on program execution, and
- must not be used again.
- A session being closed disposes all installed breakpoints.
Example usage:
try (DebuggerSession session = Debugger.find(instrumentEnvironment).
startSession(suspendedCallback)) {
// install breakpoint in someCode at line 3.
session.install(Breakpoint.newBuilder(someCode).
lineIs(3).build());
// install breakpoint for a URI at line 3
session.install(Breakpoint.newBuilder(someCode.getURI()).
lineIs(3).build());
}
- Since:
- 0.9
-
Nested Class Summary
Modifier and TypeClassDescriptionfinal class
Builder implementation for a newbreakpoint
.final class
Builder implementation for a newbreakpoint
ofEXCEPTION
kind.static enum
Specifies a breakpoint kind.static interface
This listener is called when a breakpoint is resolved at the target location. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Permanently prevents this breakpoint from affecting execution.Returns the expression used to create the current breakpoint condition, null if no condition set.int
int
getKind()
Returns the kind of this breakpoint.Returns the suspended position within the guest language source location.boolean
boolean
boolean
Test whether this breakpoint can be modified.boolean
boolean
static Breakpoint.Builder
newBuilder
(Source source) Creates a new breakpoint builder based on aSource
.static Breakpoint.Builder
newBuilder
(SourceSection sourceSection) Creates a new breakpoint builder based on the textual region of a guest language source element.static Breakpoint.Builder
newBuilder
(URI sourceUri) Creates a new breakpoint builder based on a URI location.static Breakpoint.ExceptionBuilder
newExceptionBuilder
(boolean caught, boolean uncaught) Creates a new exception breakpoint builder.void
setCondition
(String expression) Assigns to this breakpoint a boolean expression whose evaluation will determine whether the breakpoint suspends execution (i.e.void
setEnabled
(boolean enabled) Controls whether this breakpoint is currently allowed to suspend execution (true by default).void
setIgnoreCount
(int ignoreCount) Changes the number of times the breakpoint must be executed before it hits (i.e.toString()
-
Method Details
-
getKind
Returns the kind of this breakpoint.- Since:
- 19.0
-
isDisposed
public boolean isDisposed()- Returns:
- whether this breakpoint is permanently unable to affect execution
- Since:
- 0.17
- See Also:
-
isEnabled
public boolean isEnabled()- Returns:
- whether this breakpoint is currently allowed to suspend execution (true by default)
- Since:
- 0.9
- See Also:
-
setEnabled
public void setEnabled(boolean enabled) Controls whether this breakpoint is currently allowed to suspend execution (true by default). This can be changed arbitrarily until breakpoint is disposed.When not
modifiable
,IllegalStateException
is thrown.- Parameters:
enabled
- whether this breakpoint should be allowed to suspend execution- Since:
- 0.9
-
isResolved
public boolean isResolved()- Returns:
- whether at least one source has been loaded that contains a match for this breakpoint's location.
- Since:
- 0.17
-
setCondition
Assigns to this breakpoint a boolean expression whose evaluation will determine whether the breakpoint suspends execution (i.e. "hits"),null
to remove any condition and always suspend.Breakpoints are by default unconditional.
Evaluation: expressions are parsed and evaluated in the lexical context of the breakpoint's location. A conditional breakpoint that applies to multiple code locations will be parsed and evaluated separately for each location.
Evaluation failure: when evaluation of a condition fails for any reason, including the return of a non-boolean value:
- execution suspends, as if evaluation had returned
true
, and - a message is logged that can be retrieved while execution is suspended.
modifiable
,IllegalStateException
is thrown.- Parameters:
expression
- if non-null
, a boolean expression, expressed in the guest language of the breakpoint's location.- Since:
- 0.9
- See Also:
- execution suspends, as if evaluation had returned
-
getCondition
Returns the expression used to create the current breakpoint condition, null if no condition set.- Since:
- 0.20
-
dispose
public void dispose()Permanently prevents this breakpoint from affecting execution. When notmodifiable
,IllegalStateException
is thrown.- Since:
- 0.9
-
isOneShot
public boolean isOneShot()- Returns:
- whether this breakpoint disables itself after suspending execution, i.e. on first hit
- Since:
- 0.9
-
getIgnoreCount
public int getIgnoreCount()- Returns:
- the number of times breakpoint will be executed but not hit (i.e. suspend execution).
- Since:
- 0.9
- See Also:
-
setIgnoreCount
public void setIgnoreCount(int ignoreCount) Changes the number of times the breakpoint must be executed before it hits (i.e. suspends execution).When a breakpoint condition evaluates to
false
:- execution is not suspended
- it does not count as a hit
- the remaining
ignoreCount
does not change.
modifiable
,IllegalStateException
is thrown.- Parameters:
ignoreCount
- number of breakpoint activations to ignore before it hits- Since:
- 0.9
-
getHitCount
public int getHitCount()- Returns:
- the number of times this breakpoint has suspended execution
- Since:
- 0.9
-
getLocationDescription
- Returns:
- a description of this breakpoint's specified location
- Since:
- 0.9
-
getSuspendAnchor
Returns the suspended position within the guest language source location.- Since:
- 0.32
-
isModifiable
public boolean isModifiable()Test whether this breakpoint can be modified. Whenfalse
, methods that change breakpoint state throwIllegalStateException
.Unmodifiable breakpoints are created from installed breakpoints as read-only copies to be available to clients other than the one who installed the original breakpoint.
Debugger.getBreakpoints()
returns unmodifiable breakpoints, for instance.- Returns:
- whether this breakpoint can be modified.
- Since:
- 0.27
-
toString
-
newBuilder
Creates a new breakpoint builder based on a URI location.- Parameters:
sourceUri
- a URI to specify breakpoint location- Since:
- 0.17
-
newBuilder
Creates a new breakpoint builder based on aSource
.- Parameters:
source
- aSource
to specify breakpoint location- Since:
- 0.17
-
newBuilder
Creates a new breakpoint builder based on the textual region of a guest language source element.- Parameters:
sourceSection
- a specification for guest language source element- Since:
- 0.17
-
newExceptionBuilder
Creates a new exception breakpoint builder. The exception breakpoint can be set to intercept caught or uncaught exceptions, or both. At least one argument needs to be true. The builder createsbreakpoint
ofEXCEPTION
kind.- Parameters:
caught
-true
to intercept exceptions that are caught by guest language code.uncaught
-true
to intercept exceptions that are not caught by guest language code.- Since:
- 19.0
-