8.8.1.1.1.3.2. Exceptions

exception ScriptingTimeoutError()

Exception that is raised when a scripting command times out

The timeout duration can be configured with setScriptingTimeout or as an argument to initScripting.

// configure with a timeout of 10 seconds
ds = initScripting({ timeout: 10000 });

// this also works
ds.setScriptingTimeout(10000);

// Configure a debug session and load a program on the first CPU
ds.configure("/path/to/my/ccxml_file.ccxml");
session = ds.openSession();
session.memory.loadProgram("/path/to/my/program.out");

// We expect our program to reach the function foo()
session.breakpoints.add("foo");

try {
    // Will resume execution and wait for the cpu to halt
    session.target.run();

    // CPU halted, did it halt at foo?
    if (session.registers.read("PC") == session.expressions.evaluate("foo")):
        console.log("CPU halted at foo()");
    else:
        console.log("CPU halted, but not at foo");
} catch (e) {
    if (e instanceof ScriptingTimeoutError) {
        console.log("CPU did not halt, gave up after 10 seconds");
        session.target.halt();
    } else {
        // some other error, rethrow
        throw e;
    }
}

ds.shutdown();