fix debug stack getting
This commit is contained in:
@@ -14,11 +14,6 @@ if get_option('bignum')
|
||||
add_project_arguments('-DCONFIG_BIGNUM', language : 'c')
|
||||
endif
|
||||
|
||||
if get_option('trace')
|
||||
add_project_arguments('-DTRACY_ENABLE', language:'c')
|
||||
deps += dependency('tracy', static:true)
|
||||
endif
|
||||
|
||||
lib_sources = ['libbf.c', 'libregexp.c', 'quickjs.c', 'libunicode.c', 'cutils.c']
|
||||
|
||||
libquickjs = library('quickjs',
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
option('bignum', type:'boolean', value:true)
|
||||
option('trace', type:'boolean', value:false)
|
||||
73
quickjs.c
73
quickjs.c
@@ -387,6 +387,7 @@ struct JSContext {
|
||||
js_hook fn_end_hook;
|
||||
js_hook fn_cycle_hook;
|
||||
js_hook fn_gc_hook;
|
||||
int hook_disabled;
|
||||
|
||||
uint64_t random_state;
|
||||
bf_context_t *bf_ctx; /* points to rt->bf_ctx, shared by all contexts */
|
||||
@@ -1683,9 +1684,6 @@ static void *js_def_malloc(JSMallocState *s, size_t size)
|
||||
|
||||
s->malloc_count++;
|
||||
s->malloc_size += js_def_malloc_usable_size(ptr) + MALLOC_OVERHEAD;
|
||||
#ifdef TRACY_ENABLE
|
||||
TracyCAllocN(ptr,js_def_malloc_usable_size(ptr) + MALLOC_OVERHEAD, "quickjs");
|
||||
#endif
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -1696,9 +1694,6 @@ static void js_def_free(JSMallocState *s, void *ptr)
|
||||
|
||||
s->malloc_count--;
|
||||
s->malloc_size -= js_def_malloc_usable_size(ptr) + MALLOC_OVERHEAD;
|
||||
#ifdef TRACY_ENABLE
|
||||
TracyCFreeN(ptr, "quickjs");
|
||||
#endif
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
@@ -1715,26 +1710,17 @@ static void *js_def_realloc(JSMallocState *s, void *ptr, size_t size)
|
||||
if (size == 0) {
|
||||
s->malloc_count--;
|
||||
s->malloc_size -= old_size + MALLOC_OVERHEAD;
|
||||
#ifdef TRACY_ENABLE
|
||||
TracyCFreeN(ptr, "quickjs");
|
||||
#endif
|
||||
free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
if (s->malloc_size + size - old_size > s->malloc_limit)
|
||||
return NULL;
|
||||
|
||||
#ifdef TRACY_ENABLE
|
||||
TracyCFreeN(ptr, "quickjs");
|
||||
#endif
|
||||
ptr = realloc(ptr, size);
|
||||
if (!ptr)
|
||||
return NULL;
|
||||
|
||||
s->malloc_size += js_def_malloc_usable_size(ptr) - old_size;
|
||||
#ifdef TRACY_ENABLE
|
||||
TracyCAllocN(ptr,js_def_malloc_usable_size(ptr) + MALLOC_OVERHEAD, "quickjs");
|
||||
#endif
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -2138,6 +2124,7 @@ JSContext *JS_NewContextRaw(JSRuntime *rt)
|
||||
|
||||
ctx->fn_start_hook = NULL;
|
||||
ctx->fn_end_hook = NULL;
|
||||
ctx->hook_disabled = 0;
|
||||
|
||||
return ctx;
|
||||
}
|
||||
@@ -16223,8 +16210,11 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj,
|
||||
|
||||
func = p->u.cfunc.c_function;
|
||||
|
||||
if (unlikely(ctx->fn_start_hook))
|
||||
if (unlikely(ctx->fn_start_hook) && !ctx->hook_disabled) {
|
||||
ctx->hook_disabled = 1;
|
||||
ctx->fn_start_hook(ctx,func_obj);
|
||||
ctx->hook_disabled = 0;
|
||||
}
|
||||
|
||||
switch(cproto) {
|
||||
case JS_CFUNC_constructor:
|
||||
@@ -16312,8 +16302,11 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj,
|
||||
rt->current_stack_frame = sf->prev_frame;
|
||||
|
||||
|
||||
if (unlikely(ctx->fn_end_hook))
|
||||
if (unlikely(ctx->fn_end_hook) && !ctx->hook_disabled) {
|
||||
ctx->hook_disabled = 1;
|
||||
ctx->fn_end_hook(ctx, func_obj);
|
||||
ctx->hook_disabled = 0;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
@@ -16446,8 +16439,11 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
|
||||
}
|
||||
b = p->u.func.function_bytecode;
|
||||
|
||||
if (unlikely(caller_ctx->fn_start_hook))
|
||||
if (unlikely(caller_ctx->fn_start_hook) && !caller_ctx->hook_disabled) {
|
||||
caller_ctx->hook_disabled = 1;
|
||||
caller_ctx->fn_start_hook(caller_ctx,func_obj);
|
||||
caller_ctx->hook_disabled = 0;
|
||||
}
|
||||
|
||||
if (unlikely(argc < b->arg_count || (flags & JS_CALL_FLAG_COPY_ARGV))) {
|
||||
arg_allocated_size = b->arg_count;
|
||||
@@ -18918,8 +18914,11 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
|
||||
}
|
||||
rt->current_stack_frame = sf->prev_frame;
|
||||
|
||||
if (unlikely(caller_ctx->fn_end_hook))
|
||||
caller_ctx->fn_end_hook(ctx,func_obj);
|
||||
if (unlikely(caller_ctx->fn_end_hook) && !caller_ctx->hook_disabled) {
|
||||
caller_ctx->hook_disabled = 1;
|
||||
caller_ctx->fn_end_hook(caller_ctx,func_obj);
|
||||
caller_ctx->hook_disabled = 0;
|
||||
}
|
||||
|
||||
|
||||
return ret_val;
|
||||
@@ -56171,14 +56170,29 @@ void js_debug_info(JSContext *js, JSValue fn, js_debug *dbg)
|
||||
if (!JS_IsObject(fn)) return;
|
||||
JSObject *p = JS_VALUE_GET_OBJ(fn);
|
||||
|
||||
dbg->name = get_func_name(js,fn);
|
||||
JS_FreeCString(js,dbg->name);
|
||||
|
||||
if (!dbg->name) dbg->name = "<anonymous>";
|
||||
char *fn_name = get_func_name(js,fn);
|
||||
|
||||
if (!fn_name || fn_name[0] == 0)
|
||||
dbg->name = js_strdup(js, "<anonymous>");
|
||||
else {
|
||||
dbg->name = js_strdup(js, fn_name);
|
||||
JS_FreeCString(js,fn_name);
|
||||
}
|
||||
|
||||
dbg->unique = (int)p;
|
||||
|
||||
switch(p->class_id) {
|
||||
case JS_CLASS_BYTECODE_FUNCTION: {
|
||||
JSFunctionBytecode *b = p->u.func.function_bytecode;
|
||||
JSFunctionBytecode *b = p->u.func.function_bytecode;
|
||||
// get filename
|
||||
char *filename = JS_AtomToCString(js, b->debug.filename);
|
||||
if (!filename || filename[0] == 0)
|
||||
dbg->filename = js_strdup(js, "unknown");
|
||||
else {
|
||||
dbg->filename = js_strdup(js, filename);
|
||||
JS_FreeCString(js,filename);
|
||||
}
|
||||
|
||||
dbg->what = "JS";
|
||||
dbg->closure_n = b->closure_var_count;
|
||||
dbg->param_n = b->arg_count;
|
||||
@@ -56189,16 +56203,23 @@ void js_debug_info(JSContext *js, JSValue fn, js_debug *dbg)
|
||||
break;
|
||||
}
|
||||
case JS_CLASS_C_FUNCTION:
|
||||
dbg->filename = js_strdup(js, "<native C>");
|
||||
dbg->what = "C";
|
||||
dbg->nparams = 0;
|
||||
dbg->vararg = 1;
|
||||
dbg->line = -1;
|
||||
dbg->line = 0;
|
||||
dbg->source = CSTR;
|
||||
dbg->srclen = STRLEN(CSTR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void free_js_debug_info(JSContext *js, js_debug *dbg)
|
||||
{
|
||||
js_free(js, dbg->filename);
|
||||
js_free(js, dbg->name);
|
||||
}
|
||||
|
||||
JSValue js_debugger_build_backtrace(JSContext *ctx, const uint8_t *cur_pc)
|
||||
{
|
||||
JSStackFrame *sf;
|
||||
|
||||
@@ -1161,18 +1161,21 @@ int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
|
||||
const JSCFunctionListEntry *tab, int len);
|
||||
|
||||
typedef struct js_debug {
|
||||
const char *name;
|
||||
const char *name; // nameof function
|
||||
const char *what;
|
||||
const char *source;
|
||||
const char *source; // source code of function
|
||||
size_t srclen;
|
||||
const char *filename; // name of file function is in
|
||||
int nparams;
|
||||
int vararg;
|
||||
int line;
|
||||
int line; // line the function is on
|
||||
int param_n;
|
||||
int closure_n;
|
||||
uint32_t unique; // a unique identifier for this function
|
||||
} js_debug;
|
||||
|
||||
void js_debug_info(JSContext *js, JSValue fn, js_debug *dbg);
|
||||
void free_js_debug_info(JSContext *js, js_debug *dbg);
|
||||
|
||||
JSValue js_debugger_closure_variables(JSContext *js, JSValue fn);
|
||||
JSValue js_debugger_local_variables(JSContext *ctx, int stack_index);
|
||||
|
||||
Reference in New Issue
Block a user