Skip to content

Commit

Permalink
Reorder detach cleanup and detach callback
Browse files Browse the repository at this point in the history
This should make it easier to allow a detached callback to reattach
immediately without leaving the debugger state inconsistent.
  • Loading branch information
svaarala committed Oct 12, 2015
1 parent e125bae commit 982fa10
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/duk_debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ typedef union {
} while (0)

DUK_INTERNAL void duk_debug_do_detach(duk_heap *heap) {
duk_debug_detached_function detach_cb;

/* Can be called muliple times with no harm. */

heap->dbg_read_cb = NULL;
heap->dbg_write_cb = NULL;
heap->dbg_peek_cb = NULL;
heap->dbg_read_flush_cb = NULL;
heap->dbg_write_flush_cb = NULL;
if (heap->dbg_detached_cb) {
heap->dbg_detached_cb(heap->dbg_udata);
}
detach_cb = heap->dbg_detached_cb;
heap->dbg_detached_cb = NULL;
heap->dbg_udata = NULL;
heap->dbg_processing = 0;
Expand All @@ -58,6 +58,13 @@ DUK_INTERNAL void duk_debug_do_detach(duk_heap *heap) {
* XXX: clear breakpoint on either attach or detach?
*/
heap->dbg_breakpoints_active[0] = (duk_breakpoint *) NULL;

/* Call the detached callback last, so that if it immediately
* reattaches, the debugger state will be correct.
*/
if (detach_cb) {
detach_cb(heap->dbg_udata);
}
}

/*
Expand Down

0 comments on commit 982fa10

Please sign in to comment.