From afa07e0c4645289c6c00541c653b190394b150a1 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 15 Feb 2010 22:44:23 +0100 Subject: [PATCH] Improve error reporting for traces aborted in non-Lua functions. --- src/lj_trace.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lj_trace.c b/src/lj_trace.c index 8cbbf0f3..ae88f844 100644 --- a/src/lj_trace.c +++ b/src/lj_trace.c @@ -441,10 +441,21 @@ static int trace_abort(jit_State *J) if (J->curtrace) { /* Is there anything to abort? */ ptrdiff_t errobj = savestack(L, L->top-1); /* Stack may be resized. */ lj_vmevent_send(L, TRACE, + TValue *frame; + const BCIns *pc; + GCfunc *fn; setstrV(L, L->top++, lj_str_newlit(L, "abort")); setintV(L->top++, J->curtrace); - setfuncV(L, L->top++, J->fn); - setintV(L->top++, proto_bcpos(J->pt, J->pc)); + /* Find original Lua function call to generate a better error message. */ + frame = J->L->base-1; + pc = J->pc; + while (!isluafunc(frame_func(frame))) { + pc = frame_pc(frame) - 1; + frame = frame_prev(frame); + } + fn = frame_func(frame); + setfuncV(L, L->top++, fn); + setintV(L->top++, proto_bcpos(funcproto(fn), pc)); copyTV(L, L->top++, restorestack(L, errobj)); copyTV(L, L->top++, &J->errinfo); );