diff --git a/Makefile b/Makefile index 4dc24953..772eaaa9 100755 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ BUILD = build +BUILD_DBG = build_debug INSTALL_BIN = /opt/homebrew/bin INSTALL_LIB = /opt/homebrew/lib INSTALL_INC = /opt/homebrew/include @@ -12,6 +13,14 @@ all: $(BUILD)/build.ninja $(BUILD)/build.ninja: meson setup $(BUILD) -Dbuildtype=debugoptimized +debug: $(BUILD_DBG)/build.ninja + meson compile -C $(BUILD_DBG) + cp $(BUILD_DBG)/libcell_runtime.dylib . + cp $(BUILD_DBG)/cell . + +$(BUILD_DBG)/build.ninja: + meson setup $(BUILD_DBG) -Dbuildtype=debug -Db_sanitize=address + install: all $(CELL_SHOP) cp cell $(INSTALL_BIN)/cell cp libcell_runtime.dylib $(INSTALL_LIB)/ @@ -20,11 +29,19 @@ install: all $(CELL_SHOP) ln -s $(CURDIR) $(CELL_SHOP)/packages/core @echo "Installed cell to $(INSTALL_BIN) and $(INSTALL_LIB)" +install_debug: debug $(CELL_SHOP) + cp cell $(INSTALL_BIN)/cell + cp libcell_runtime.dylib $(INSTALL_LIB)/ + cp source/cell.h source/quickjs.h source/wota.h $(INSTALL_INC)/ + rm -rf $(CELL_SHOP)/packages/core + ln -s $(CURDIR) $(CELL_SHOP)/packages/core + @echo "Installed cell (debug+asan) to $(INSTALL_BIN) and $(INSTALL_LIB)" + $(CELL_SHOP): mkdir -p $(CELL_SHOP)/packages $(CELL_SHOP)/cache $(CELL_SHOP)/build clean: - rm -rf $(BUILD) + rm -rf $(BUILD) $(BUILD_DBG) rm -f cell libcell_runtime.dylib -.PHONY: all install clean +.PHONY: all install debug install_debug clean diff --git a/source/qjs_actor.c b/source/qjs_actor.c index 8dcf43da..2f40e554 100644 --- a/source/qjs_actor.c +++ b/source/qjs_actor.c @@ -131,12 +131,16 @@ JSC_CCALL(actor_removetimer, ) /* Log callback bridge: called from JS_Log, calls ƿit log(channel, [msg, stack]) - Captures the register VM stack trace so the log system can show the real error site. */ + Captures the register VM stack trace so the log system can show the real error site. + Uses a re-entrancy guard to prevent infinite recursion when JS_Call triggers + js_poll_interrupts -> JS_RaiseDisrupt -> JS_Log -> js_log_callback -> ... */ +static int js_log_reentrancy = 0; static void js_log_callback(JSContext *ctx, const char *channel, const char *msg) { - if (JS_IsNull(ctx->log_callback_js)) { + if (JS_IsNull(ctx->log_callback_js) || js_log_reentrancy) { fprintf(stderr, "%s\n", msg); return; } + js_log_reentrancy = 1; JS_FRAME(ctx); JS_ROOT(stack, JS_GetStack(ctx)); JS_ROOT(args_array, JS_NewArray(ctx)); @@ -147,6 +151,7 @@ static void js_log_callback(JSContext *ctx, const char *channel, const char *msg argv[1] = args_array.val; JS_Call(ctx, ctx->log_callback_js, JS_NULL, 2, argv); JS_RestoreFrame(ctx, _js_gc_frame, _js_local_frame); + js_log_reentrancy = 0; } JSC_CCALL(actor_set_log,