---
title: "DebuggerTester"
description: "Test utility class that makes it easier to test and debug debugger functionality for guest languages."
kind: "class"
id: "com.oracle.truffle.tck.DebuggerTester"
module: "truffle-tck"
version: "25.6.0-elide.4"
canonical: "https://graalvm.elide.help/25.6.0-elide.4/api/truffle-tck/com/oracle/truffle/tck/DebuggerTester.html"
---

# ◆ DebuggerTester

[truffle-tck](../../../../index.md) › [com.oracle.truffle.tck](index.md) · Every page: [llms.txt](../../../../llms.txt)

Class in [`com.oracle.truffle.tck`](index.md). Since 0.16.

```java
public final class DebuggerTester implements AutoCloseable
```

Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `DebuggerTester`

Implements: [`AutoCloseable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AutoCloseable.html)

Test utility class that makes it easier to test and debug debugger functionality for guest languages. Testing suspended callbacks can be cumbersome when having to assert multiple sequential events. The debugger tester allows to test suspended callbacks using sequential code that allows to assert multiple [`events`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/debug/SuspendedEvent.html). It does so by running the engine on a separate thread and it uses internal APIs to allow access to the [`SuspendedEvent`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/debug/SuspendedEvent.html) from another Thread. Do not use this class for anything else than testing.

The debugger tester can print debug traces to standard output with -Dtruffle.debug.trace=true. Example usage:

```java
public void testDebugging() {
    try (DebuggerTester tester = new DebuggerTester()) {
        // use your guest language source here
        Source source = null;
        try (DebuggerSession session = tester.startSession()) {
            session.suspendNextExecution();
            tester.startEval(source);

            tester.expectSuspended(new SuspendedCallback() {
                @Override
                public void onSuspend(SuspendedEvent event) {
                    // assert suspended event is proper here
                    event.prepareStepInto(1);

                }
            });
            tester.expectSuspended(new SuspendedCallback() {
                @Override
                public void onSuspend(SuspendedEvent event) {
                    // assert another suspended event is proper here
                    event.prepareContinue();
                }
            });

            // expect no more suspended events
            tester.expectDone();
        }
    }
}
```

## Nested types

- [`DebuggerTester.PositionPredicate`](DebuggerTester.PositionPredicate.md) (interface): Predicate of testable positions.

## Constructors

### DebuggerTester()
<a id="&lt;init&gt;()"></a>`public DebuggerTester()`. Since 0.16. Constructs a new debugger tester instance. Boots up a new `context` on Thread in the background. The tester instance needs to be `closed` after use. Throws an AssertionError if the engine initialization fails. Cite: `com/oracle/truffle/tck/DebuggerTester.html#<init>()`

### DebuggerTester(Context.Builder)
<a id="&lt;init&gt;(org.graalvm.polyglot.Context.Builder)"></a>`public DebuggerTester(Context.Builder contextBuilder)`. Since 0.31. Constructs a new debugger tester instance with a pre-set context builder. Parameters: `contextBuilder` `Context.Builder`: a pre-set context builder. Only out and err streams are set on this builder prior the `Context` instance creation. See also: `DebuggerTester()`. Cite: `com/oracle/truffle/tck/DebuggerTester.html#<init>(org.graalvm.polyglot.Context.Builder)`

### DebuggerTester(Engine, Context.Builder)
<a id="&lt;init&gt;(org.graalvm.polyglot.Engine,org.graalvm.polyglot.Context.Builder)"></a>`public DebuggerTester(Engine engine, Context.Builder contextBuilder)`. Since 25.0. Constructs a new debugger tester instance with a pre-set context builder and engine. Parameters: `engine` `Engine`: engine to use for the context builder. `contextBuilder` `Context.Builder`: a pre-set context builder. Only out and err streams are set on this builder prior the `Context` instance creation. See also: `DebuggerTester()`. Cite: `com/oracle/truffle/tck/DebuggerTester.html#<init>(org.graalvm.polyglot.Engine,org.graalvm.polyglot.Context.Builder)`

## Methods

### getErr()
<a id="getErr()"></a>`public String getErr()`. Since 0.16. Returns the error output of the underlying `context`. Cite: `com/oracle/truffle/tck/DebuggerTester.html#getErr()`

### getOut()
<a id="getOut()"></a>`public String getOut()`. Since 0.16. Returns the standard output of the underlying `context`. Cite: `com/oracle/truffle/tck/DebuggerTester.html#getOut()`

### getDebugger()
<a id="getDebugger()"></a>`public Debugger getDebugger()`. Since 0.27. Get the Debugger instance associated with the current engine. Cite: `com/oracle/truffle/tck/DebuggerTester.html#getDebugger()`

### startSession()
<a id="startSession()"></a>`public DebuggerSession startSession()`. Since 0.16. Starts a new [`debugger session`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/debug/Debugger.html#startSession%28com.oracle.truffle.api.debug.SuspendedCallback%29) in the context's `engine`. The debugger session allows to suspend the execution and to install breakpoints. If multiple sessions are created for one `evaluation` then all suspended events are delegated to this debugger tester instance. Returns `DebuggerSession`: a new debugger session. Cite: `com/oracle/truffle/tck/DebuggerTester.html#startSession()`

### startSession(SourceElement...)
<a id="startSession(com.oracle.truffle.api.debug.SourceElement...)"></a>`public DebuggerSession startSession(SourceElement... sourceElements)`. Since 0.33. Starts a new [`debugger session`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/debug/Debugger.html#startSession%28com.oracle.truffle.api.debug.SuspendedCallback,com.oracle.truffle.api.debug.SourceElement...%29) in the context's `engine`. The debugger session allows to suspend the execution on the provided source elements and to install breakpoints. If multiple sessions are created for one `evaluation` then all suspended events are delegated to this debugger tester instance. Parameters: `sourceElements` `SourceElement...`: a list of source elements. Returns `DebuggerSession`: a new debugger session. Cite: `com/oracle/truffle/tck/DebuggerTester.html#startSession(com.oracle.truffle.api.debug.SourceElement...)`

### startEval(Source)
<a id="startEval(org.graalvm.polyglot.Source)"></a>`public void startEval(Source s)`. Since 0.27. Starts a new `evaluation` on the background thread. Only one evaluation can be active at a time. Please ensure that `expectDone()` completed successfully before starting a new evaluation. When no source is available please refer to `DebuggerTester.startExecute(Function)`. Throws an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) if another evaluation is still executing or the tester is already closed. Cite: `com/oracle/truffle/tck/DebuggerTester.html#startEval(org.graalvm.polyglot.Source)`

### startExecute(Function)
<a id="startExecute(java.util.function.Function)"></a>`public void startExecute(Function<Context, Value> script)`. Since 20.0. Starts a new script evaluation on the background thread. Only one evaluation can be active at a time. Please ensure that `expectDone()` completed successfully before starting a new evaluation. If a Source is available please refer to `DebuggerTester.startEval(Source)` . Throws an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) if another evaluation is still executing or the tester is already closed. Cite: `com/oracle/truffle/tck/DebuggerTester.html#startExecute(java.util.function.Function)`

### expectSuspended(SuspendedCallback)
<a id="expectSuspended(com.oracle.truffle.api.debug.SuspendedCallback)"></a>`public void expectSuspended(SuspendedCallback callback)`. Since 0.16. Expects a suspended event and returns it for potential assertions. If the execution completed or was killed instead then an assertion error is thrown. The returned suspended event is only valid until on of `expectKilled()`, `expectSuspended(SuspendedCallback)` or `expectDone()` is called again. Throws an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) if the tester is already closed. Parameters: `callback` `SuspendedCallback`: handler to be called when the execution is suspended. Cite: `com/oracle/truffle/tck/DebuggerTester.html#expectSuspended(com.oracle.truffle.api.debug.SuspendedCallback)`

### expectSuspended(SuspendedCallback, Function)
<a id="expectSuspended(com.oracle.truffle.api.debug.SuspendedCallback,java.util.function.Function)"></a>`public void expectSuspended(SuspendedCallback callback, Function<String, Boolean> errorVerifier)`. Since 24.1. Expects a suspended event and returns it for potential assertions, allows to verify errors printed to the error output. Parameters: `callback` `SuspendedCallback`: handler to be called when the execution is suspended. `errorVerifier` `Function<String, Boolean>`: handler, which returns `true` when the error is expected. Cite: `com/oracle/truffle/tck/DebuggerTester.html#expectSuspended(com.oracle.truffle.api.debug.SuspendedCallback,java.util.function.Function)`

### expectThrowable()
<a id="expectThrowable()"></a>`public Throwable expectThrowable()`. Since 0.16. Expects the current evaluation to be completed with an error and not be killed or to produce further suspended events. It returns a string representation of the result value to be asserted. If the evaluation caused any errors they are thrown as [`AssertionError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AssertionError.html). Throws an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) if the tester is already closed. Cite: `com/oracle/truffle/tck/DebuggerTester.html#expectThrowable()`

### expectDone()
<a id="expectDone()"></a>`public String expectDone()`. Since 0.16. Expects the current evaluation to be completed successfully and not be killed or to produce further suspended events. It returns a string representation of the result value to be asserted. If the evaluation caused any errors they are thrown as [`AssertionError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AssertionError.html). Throws an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) if the tester is already closed. Cite: `com/oracle/truffle/tck/DebuggerTester.html#expectDone()`

### expectKilled()
<a id="expectKilled()"></a>`public void expectKilled()`. Since 0.16. Expects the current evaluation to be killed and not be completed or to produce further suspended events. Throws an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) if the tester is already closed. If the evaluation caused any errors besides the kill exception then they are thrown as [`AssertionError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AssertionError.html). Cite: `com/oracle/truffle/tck/DebuggerTester.html#expectKilled()`

### getEvalThread()
<a id="getEvalThread()"></a>`public Thread getEvalThread()`. Since 0.16. Returns the thread that the execution started with `startEval(Source)` is running on. Returns `Thread`: the thread instance. Cite: `com/oracle/truffle/tck/DebuggerTester.html#getEvalThread()`

### closeEngine()
<a id="closeEngine()"></a>`public void closeEngine()`. Since 0.30. Close the engine. It's not possible to evaluate code after engine is closed, use it when the engine needs to be closed before the debugger session. Cite: `com/oracle/truffle/tck/DebuggerTester.html#closeEngine()`

### close()
<a id="close()"></a>`public void close()`. Since 0.16. Closes the current debugger tester session and all its associated resources like the background thread. The debugger tester becomes unusable after closing. Overrides `close()`. Cite: `com/oracle/truffle/tck/DebuggerTester.html#close()`

### assertLineBreakpointsResolution(String, String, String)
<a id="assertLineBreakpointsResolution(java.lang.String,java.lang.String,java.lang.String)"></a>`public void assertLineBreakpointsResolution(String sourceWithMarks, String resolvedMarkName, String language)`. Since 0.33. Utility method that checks proper resolution of line breakpoints. Breakpoints are submitted to every line of the source and their resolution location is checked. The source need to contain resolution marks in the form of "`R<line number>_`" where \<line number\> is line number of the original breakpoint position and `R` is the resolved mark name. These marks need to be placed at the proper breakpoint resolution line/column position, for a breakpoint submitted to every line. When several submitted breakpoints resolve to the same position, an interval can be specified in the form of "`R<line start number>-<line end number>_`", where both start and end line numbers are inclusive. The marks are stripped off before execution. The guest language code with marks may look like: Parameters: `sourceWithMarks` `String`: a source text, which contains the resolution marks. `resolvedMarkName` `String`: the mark name. It is used in a regular expression, therefore the mark must not have a special meaning in a regular expression. `language` `String`: the source language. Cite: `com/oracle/truffle/tck/DebuggerTester.html#assertLineBreakpointsResolution(java.lang.String,java.lang.String,java.lang.String)`

```java
// test
function test(n) {
  if (R1-3_n <= 1) {
    return R4_2 * n;
  }
  return R5-7_n - 1;
}
```

### assertLineBreakpointsResolution(String, DebuggerTester.PositionPredicate, …)
<a id="assertLineBreakpointsResolution(java.lang.String,com.oracle.truffle.tck.DebuggerTester.PositionPredicate,java.lang.String,java.lang.String)"></a>`public void assertLineBreakpointsResolution(String sourceWithMarks, DebuggerTester.PositionPredicate positionPredicate, String resolvedMarkName, String language)`. Since 19.3.0. Parameters: `positionPredicate` `DebuggerTester.PositionPredicate`: `null` to test line breakpoints on all lines, or a predicate that limits the testable lines. See also: `assertLineBreakpointsResolution(java.lang.String, java.lang.String, java.lang.String)`. Cite: `com/oracle/truffle/tck/DebuggerTester.html#assertLineBreakpointsResolution(java.lang.String,com.oracle.truffle.tck.DebuggerTester.PositionPredicate,java.lang.String,java.lang.String)`

### assertColumnBreakpointsResolution(String, String, …)
<a id="assertColumnBreakpointsResolution(java.lang.String,java.lang.String,java.lang.String,java.lang.String)"></a>`public void assertColumnBreakpointsResolution(String sourceWithMarks, String breakpointMarkName, String resolvedMarkName, String language)`. Since 0.33. Utility method that checks proper resolution of column breakpoints. Breakpoints are submitted to marked positions and their resolution location is checked. The source need to contain both breakpoint submission marks in the form of "B\<number\>\_" and breakpoint resolution marks in the form of "R\<number\>\_" where \<number\> is an identification of the breakpoint. These marks need to be placed at the proper breakpoint submission/resolution line/column position. When several submitted breakpoints resolve to the same position, an interval can be specified in the form of "R\<start number\>-\<end number\>\_", where both start and end line numbers are inclusive. The marks are stripped off before execution. The guest language code with marks may look like: Parameters: `sourceWithMarks` `String`: a source text, which contains the resolution marks. `breakpointMarkName` `String`: the breakpoint submission mark name. It is used in a regular expression, therefore the mark must not have a special meaning in a regular expression. `resolvedMarkName` `String`: the resolved mark name. It is used in a regular expression, therefore the mark must not have a special meaning in a regular expression. `language` `String`: the source language. Cite: `com/oracle/truffle/tck/DebuggerTester.html#assertColumnBreakpointsResolution(java.lang.String,java.lang.String,java.lang.String,java.lang.String)`

```java
// B1_test
function B2_test(n) {B3_
  if (R1-4_n <= B4_1) {B5_
    return R5_2 * n;
  }
  return R6_n - 1;
B6_}
```

### assertColumnBreakpointsResolution(String, String, …)
<a id="assertColumnBreakpointsResolution(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.net.URI)"></a>`public void assertColumnBreakpointsResolution(String sourceWithMarks, String breakpointMarkName, String resolvedMarkName, String language, URI bpURI)`. Cite: `com/oracle/truffle/tck/DebuggerTester.html#assertColumnBreakpointsResolution(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.net.URI)`

### assertBreakpointsBreakEverywhere(Source)
<a id="assertBreakpointsBreakEverywhere(org.graalvm.polyglot.Source)"></a>`public void assertBreakpointsBreakEverywhere(Source source)`. Since 0.33. Utility method that tests if a breakpoint submitted to any location in the source code suspends the execution. A two-pass test is performed. In the first pass, line breakpoints are submitted to every line. In the second pass, breakpoints are submitted to every line and column combination, even outside the source scope. It is expected that the breakpoints resolve to a nearest suspendable location and it is checked that all breakpoints are hit. Parameters: `source` `Source`: a source to evaluate with breakpoints submitted everywhere. Cite: `com/oracle/truffle/tck/DebuggerTester.html#assertBreakpointsBreakEverywhere(org.graalvm.polyglot.Source)`

### assertBreakpointsBreakEverywhere(Source, DebuggerTester.PositionPredicate)
<a id="assertBreakpointsBreakEverywhere(org.graalvm.polyglot.Source,com.oracle.truffle.tck.DebuggerTester.PositionPredicate)"></a>`public void assertBreakpointsBreakEverywhere(Source source, DebuggerTester.PositionPredicate positionPredicate)`. Since 19.3.0. Utility method that tests if a breakpoint submitted to any location permitted by the `PositionPredicate` in the source code suspends the execution. A two-pass test is performed. In the first pass, line breakpoints are submitted to every testable line. In the second pass, breakpoints are submitted to every testable line and column combination, even outside the source scope, if permitted by the `PositionPredicate`. It is expected that the breakpoints resolve to a nearest suspendable location and it is checked that all submitted breakpoints are hit. Parameters: `source` `Source`: a source to evaluate with breakpoints submitted everywhere. `positionPredicate` `DebuggerTester.PositionPredicate`: `null` to submit breakpoints everywhere, or a predicate that limits the testable positions. Cite: `com/oracle/truffle/tck/DebuggerTester.html#assertBreakpointsBreakEverywhere(org.graalvm.polyglot.Source,com.oracle.truffle.tck.DebuggerTester.PositionPredicate)`

### getSourceImpl(Source)
<a id="getSourceImpl(org.graalvm.polyglot.Source)"></a>`public static Source getSourceImpl(Source source)`. Since 0.28. Get [`Truffle Source`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/source/Source.html) that corresponds to the `Polyglot Source`. This is a bridge between the two Source implementations. Cite: `com/oracle/truffle/tck/DebuggerTester.html#getSourceImpl(org.graalvm.polyglot.Source)`

## Inherited members

- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
