Browse Source

Implement duk_debugger_pause() API

The target can call duk_debugger_pause() to initiate an immediate
debugger pause, enabling implementation of a "break into debuggeer now"
hotkey or similar mechanism.
pull/615/head
Bruce Pascoe 9 years ago
parent
commit
90758d5d32
  1. 29
      src/duk_api_debug.c
  2. 1
      src/duk_api_public.h.in

29
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 */

1
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

Loading…
Cancel
Save