diff --git a/src/duk_api_debug.c b/src/duk_api_debug.c index 6f1cf3d0..9698b825 100644 --- a/src/duk_api_debug.c +++ b/src/duk_api_debug.c @@ -181,6 +181,29 @@ DUK_EXTERNAL duk_bool_t duk_debugger_notify(duk_context *ctx, duk_idx_t nvalues) return ret; } +DUK_EXTERNAL void duk_debugger_pause(duk_context *ctx) { + duk_hthread *thr; + + DUK_ASSERT_CTX_VALID(ctx); + thr = (duk_hthread *) ctx; + DUK_ASSERT(thr != NULL); + DUK_ASSERT(thr->heap != NULL); + + DUK_D(DUK_DPRINT("application called duk_debugger_pause()")); + + /* Treat like a debugger statement: ignore when not attached. */ + if (DUK_HEAP_IS_DEBUGGER_ATTACHED(thr->heap)) { + DUK_HEAP_SET_PAUSED(thr->heap); + + /* Pause on the next opcode executed. This is always safe to do even + * inside the debugger message loop: the interrupt counter will be reset + * to its proper value when the message loop exits. + */ + thr->interrupt_init = 1; + thr->interrupt_counter = 0; + } +} + #else /* DUK_USE_DEBUGGER_SUPPORT */ DUK_EXTERNAL void duk_debugger_attach_custom(duk_context *ctx, @@ -231,4 +254,10 @@ DUK_EXTERNAL duk_bool_t duk_debugger_notify(duk_context *ctx, duk_idx_t nvalues) return 0; } +DUK_EXTERNAL void duk_debugger_pause(duk_context *ctx) { + /* Treat like debugger statement: nop */ + DUK_ASSERT_CTX_VALID(ctx); + DUK_UNREF(ctx); +} + #endif /* DUK_USE_DEBUGGER_SUPPORT */ diff --git a/src/duk_api_public.h.in b/src/duk_api_public.h.in index f900deba..eeb93d97 100644 --- a/src/duk_api_public.h.in +++ b/src/duk_api_public.h.in @@ -959,6 +959,7 @@ DUK_EXTERNAL_DECL void duk_debugger_attach_custom(duk_context *ctx, DUK_EXTERNAL_DECL void duk_debugger_detach(duk_context *ctx); DUK_EXTERNAL_DECL void duk_debugger_cooperate(duk_context *ctx); DUK_EXTERNAL_DECL duk_bool_t duk_debugger_notify(duk_context *ctx, duk_idx_t nvalues); +DUK_EXTERNAL_DECL void duk_debugger_pause(duk_context *ctx); /* * Date provider related constants