trace
This commit is contained in:
@@ -1345,6 +1345,20 @@ JSValue JS_CallRegisterVM(JSContext *ctx, JSCodeRegister *code,
|
||||
|
||||
pc = code->entry_point;
|
||||
result = JS_NULL;
|
||||
|
||||
/* Fire trace hook for top-level register function entry */
|
||||
if (unlikely(ctx->trace_hook) && (ctx->trace_type & JS_HOOK_CALL)) {
|
||||
js_debug dbg = {0};
|
||||
if (code->name_cstr)
|
||||
snprintf(dbg.name, sizeof(dbg.name), "%s", code->name_cstr);
|
||||
if (code->filename_cstr)
|
||||
snprintf(dbg.filename, sizeof(dbg.filename), "%s", code->filename_cstr);
|
||||
if (code->line_table)
|
||||
dbg.line = code->line_table[code->entry_point].line;
|
||||
dbg.param_n = code->arity;
|
||||
dbg.unique = (int)(uintptr_t)code;
|
||||
ctx->trace_hook(ctx, JS_HOOK_CALL, &dbg, ctx->trace_data);
|
||||
}
|
||||
} /* end normal path block */
|
||||
|
||||
vm_dispatch:
|
||||
@@ -2132,6 +2146,8 @@ vm_dispatch:
|
||||
stone_mutable_text(frame->slots[a]);
|
||||
result = frame->slots[a];
|
||||
if (!JS_IsPtr(frame->caller)) goto done;
|
||||
if (unlikely(ctx->trace_hook) && (ctx->trace_type & JS_HOOK_RET))
|
||||
ctx->trace_hook(ctx, JS_HOOK_RET, NULL, ctx->trace_data);
|
||||
{
|
||||
#ifdef VALIDATE_GC
|
||||
const char *callee_name = "?";
|
||||
@@ -2177,6 +2193,8 @@ vm_dispatch:
|
||||
VM_CASE(MACH_RETNIL):
|
||||
result = JS_NULL;
|
||||
if (!JS_IsPtr(frame->caller)) goto done;
|
||||
if (unlikely(ctx->trace_hook) && (ctx->trace_type & JS_HOOK_RET))
|
||||
ctx->trace_hook(ctx, JS_HOOK_RET, NULL, ctx->trace_data);
|
||||
{
|
||||
JSFrameRegister *caller = (JSFrameRegister *)JS_VALUE_GET_PTR(frame->caller);
|
||||
frame->caller = JS_NULL;
|
||||
@@ -2745,6 +2763,19 @@ vm_dispatch:
|
||||
if (fn->kind == JS_FUNC_KIND_REGISTER) {
|
||||
/* Register function: FRAME already allocated nr_slots — just switch */
|
||||
JSCodeRegister *fn_code = JS_VALUE_GET_CODE(fn->u.cell.code)->u.reg.code;
|
||||
/* Fire trace hook for register-to-register call */
|
||||
if (unlikely(ctx->trace_hook) && (ctx->trace_type & JS_HOOK_CALL)) {
|
||||
js_debug dbg = {0};
|
||||
if (fn_code->name_cstr)
|
||||
snprintf(dbg.name, sizeof(dbg.name), "%s", fn_code->name_cstr);
|
||||
if (fn_code->filename_cstr)
|
||||
snprintf(dbg.filename, sizeof(dbg.filename), "%s", fn_code->filename_cstr);
|
||||
if (fn_code->line_table)
|
||||
dbg.line = fn_code->line_table[fn_code->entry_point].line;
|
||||
dbg.param_n = fn_code->arity;
|
||||
dbg.unique = (int)(uintptr_t)fn_code;
|
||||
ctx->trace_hook(ctx, JS_HOOK_CALL, &dbg, ctx->trace_data);
|
||||
}
|
||||
/* Save return info */
|
||||
frame->address = JS_NewInt32(ctx, (pc << 16) | b);
|
||||
fr->caller = JS_MKPTR(frame);
|
||||
@@ -2800,6 +2831,23 @@ vm_dispatch:
|
||||
|
||||
if (fn->kind == JS_FUNC_KIND_REGISTER) {
|
||||
JSCodeRegister *fn_code = JS_VALUE_GET_CODE(FN_READ_CODE(fn))->u.reg.code;
|
||||
/* Tail call: fire RET for current, CALL for new */
|
||||
if (unlikely(ctx->trace_hook)) {
|
||||
if (ctx->trace_type & JS_HOOK_RET)
|
||||
ctx->trace_hook(ctx, JS_HOOK_RET, NULL, ctx->trace_data);
|
||||
if (ctx->trace_type & JS_HOOK_CALL) {
|
||||
js_debug dbg = {0};
|
||||
if (fn_code->name_cstr)
|
||||
snprintf(dbg.name, sizeof(dbg.name), "%s", fn_code->name_cstr);
|
||||
if (fn_code->filename_cstr)
|
||||
snprintf(dbg.filename, sizeof(dbg.filename), "%s", fn_code->filename_cstr);
|
||||
if (fn_code->line_table)
|
||||
dbg.line = fn_code->line_table[fn_code->entry_point].line;
|
||||
dbg.param_n = fn_code->arity;
|
||||
dbg.unique = (int)(uintptr_t)fn_code;
|
||||
ctx->trace_hook(ctx, JS_HOOK_CALL, &dbg, ctx->trace_data);
|
||||
}
|
||||
}
|
||||
int current_slots = (int)objhdr_cap56(frame->header);
|
||||
|
||||
if (fn_code->nr_slots <= current_slots) {
|
||||
@@ -3003,6 +3051,9 @@ suspend:
|
||||
return result;
|
||||
|
||||
done:
|
||||
/* Fire trace hook for top-level register function return */
|
||||
if (unlikely(ctx->trace_hook) && (ctx->trace_type & JS_HOOK_RET))
|
||||
ctx->trace_hook(ctx, JS_HOOK_RET, NULL, ctx->trace_data);
|
||||
#ifdef HAVE_ASAN
|
||||
__asan_js_ctx = NULL;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user