From 32366483dcbe2c16c47b44f59c829627ef3679a8 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Thu, 22 May 2025 16:17:11 -0500 Subject: [PATCH] split out debug --- source/qjs_debug.c | 29 +++++++++++++++++++++++++++++ source/qjs_debug.h | 8 ++++++++ 2 files changed, 37 insertions(+) create mode 100644 source/qjs_debug.c create mode 100644 source/qjs_debug.h diff --git a/source/qjs_debug.c b/source/qjs_debug.c new file mode 100644 index 00000000..8819b384 --- /dev/null +++ b/source/qjs_debug.c @@ -0,0 +1,29 @@ +#include "qjs_debug.h" +#include "qjs_macros.h" +#include "jsffi.h" + +// Debug function implementations + +JSC_CCALL(debug_stack_depth, return number2js(js,js_debugger_stack_depth(js))) +JSC_CCALL(debug_build_backtrace, return js_debugger_build_backtrace(js,NULL)) +JSC_CCALL(debug_closure_vars, return js_debugger_closure_variables(js,argv[0])) +JSC_CCALL(debug_local_vars, return js_debugger_local_variables(js, js2number(js,argv[0]))) +JSC_CCALL(debug_fn_info, return js_debugger_fn_info(js, argv[0])) +JSC_CCALL(debug_backtrace_fns, return js_debugger_backtrace_fns(js,NULL)) +JSC_CCALL(debug_dump_obj, return js_dump_value(js, argv[0])) + +static const JSCFunctionListEntry js_debug_funcs[] = { + MIST_FUNC_DEF(debug, stack_depth, 0), + MIST_FUNC_DEF(debug, build_backtrace, 0), + MIST_FUNC_DEF(debug, closure_vars, 1), + MIST_FUNC_DEF(debug, local_vars, 1), + MIST_FUNC_DEF(debug, fn_info, 1), + MIST_FUNC_DEF(debug, backtrace_fns,0), + MIST_FUNC_DEF(debug, dump_obj, 1), +}; + +JSValue js_debug_use(JSContext *js) { + JSValue mod = JS_NewObject(js); + JS_SetPropertyFunctionList(js,mod,js_debug_funcs,countof(js_debug_funcs)); + return mod; +} \ No newline at end of file diff --git a/source/qjs_debug.h b/source/qjs_debug.h new file mode 100644 index 00000000..2e0c661b --- /dev/null +++ b/source/qjs_debug.h @@ -0,0 +1,8 @@ +#ifndef QJS_DEBUG_H +#define QJS_DEBUG_H + +#include + +JSValue js_debug_use(JSContext *ctx); + +#endif \ No newline at end of file