add debug hooks

This commit is contained in:
2025-02-06 09:11:09 -06:00
parent e6fcf7d09a
commit 94bb2ed5d3
2 changed files with 23 additions and 44 deletions

View File

@@ -736,7 +736,7 @@ static JSValue js_std_getenviron(JSContext *ctx, JSValueConst this_val,
static JSValue js_std_gc(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv)
{
JS_RunGC(JS_GetRuntime(ctx));
JS_RunGC(JS_GetRuntime(ctx), ctx);
return JS_UNDEFINED;
}

View File

@@ -33,10 +33,6 @@
#include <fenv.h>
#include <math.h>
#ifdef TRACY_ENABLE
#include <tracy/TracyC.h>
#endif
#if defined(__APPLE__)
#include <malloc/malloc.h>
#elif defined(__linux__) || defined(__GLIBC__)
@@ -433,6 +429,9 @@ struct JSContext {
JSAtom doc_sym;
JSAtom typeof_sym;
void (*fn_start_hook)(JSContext*, JSValue);
void (*fn_end_hook)(JSContext*, JSValue);
uint64_t random_state;
@@ -2089,6 +2088,9 @@ JSContext *JS_NewContextRaw(JSRuntime *rt)
ctx->typeof_sym = JS_ValueToAtom(ctx,tsym);
JS_FreeValue(ctx,dsym);
JS_FreeValue(ctx,tsym);
ctx->fn_start_hook = NULL;
ctx->fn_end_hook = NULL;
return ctx;
}
@@ -6224,9 +6226,9 @@ static void JS_RunGCInternal(JSRuntime *rt, BOOL remove_weak_objects)
gc_remove_weak_objects(rt);
}
double n = stm_now();
double size = rt->malloc_state.malloc_size;
double n = stm_now();
double size = rt->malloc_state.malloc_size;
/* decrement the reference of the children of each object. mark =
1 after this pass. */
gc_decref(rt);
@@ -6246,14 +6248,10 @@ static void JS_RunGCInternal(JSRuntime *rt, BOOL remove_weak_objects)
JSValue dump = js_dump_object(ctx, (JSObject*)p);
JS_SetPropertyUint32(ctx, ret, idx++, dump);
}
}
*/
}*/
/* free the GC objects in a cycle */
gc_free_cycles(rt);
#ifdef TRACY_ENABLE
TracyCZoneEnd(js_gc)
#endif
return ret;
}
@@ -16180,13 +16178,9 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj,
sf->arg_buf = (JSValue*)arg_buf;
func = p->u.cfunc.c_function;
#if defined(TRACY_ENABLE) && !defined(_WIN32)
const char *ccname = get_func_name(ctx,func_obj);
const char *file = "<native C>";
TracyCZoneCtx tracy_ctx = ___tracy_emit_zone_begin_alloc(___tracy_alloc_srcloc(1, file, strlen(file), ccname, strlen(ccname), (int)ccname), 1);
JS_FreeCString(ctx,ccname);
#endif
// if (unlikely(ctx->fn_start_hook))
// ctx->fn_start_hook(ctx,func_obj);
switch(cproto) {
case JS_CFUNC_constructor:
@@ -16273,10 +16267,10 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj,
rt->current_stack_frame = sf->prev_frame;
#if defined(TRACY_ENABLE) && !defined(_WIN32)
___tracy_emit_zone_end(tracy_ctx);
#endif
// if (unlikely(ctx->fn_end_hook))
// ctx->fn_end_hook(ctx, func_obj);
return ret_val;
}
@@ -16408,23 +16402,8 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
}
b = p->u.func.function_bytecode;
// IS A FUNCTION ****** TRACE HERE ******
#ifdef TRACY_ENABLE
const char *fn_src = JS_AtomToCString(caller_ctx, js_fn_filename(caller_ctx,func_obj));
const char *js_func_name = get_func_name(caller_ctx, func_obj);
const char *fn_name;
if (!js_func_name || js_func_name[0] == '\0')
fn_name = "<anonymous>";
else
fn_name = js_func_name;
uint64_t srcloc;
srcloc = ___tracy_alloc_srcloc(js_fn_linenum(caller_ctx,func_obj), fn_src, strlen(fn_src), fn_name, strlen(fn_name), (int)fn_src);
TracyCZoneCtx tracy_ctx = ___tracy_emit_zone_begin_alloc(srcloc,1);
JS_FreeCString(caller_ctx,js_func_name);
JS_FreeCString(caller_ctx,fn_src);
#endif
// if (unlikely(ctx->fn_start_hook))
// ctx->fn_start_hook(ctx,func_obj);
if (unlikely(argc < b->arg_count || (flags & JS_CALL_FLAG_COPY_ARGV))) {
arg_allocated_size = b->arg_count;
@@ -18980,9 +18959,9 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
}
rt->current_stack_frame = sf->prev_frame;
#ifdef TRACY_ENABLE
___tracy_emit_zone_end(tracy_ctx);
#endif
// if (unlikely(ctx->fn_end_hook))
// ctx->fn_end_hook(ctx,func_obj);
return ret_val;
}