]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Handle all stack layouts in (delayed) TRACE vmevent.
authorMike Pall <mike>
Thu, 21 Sep 2023 00:15:16 +0000 (02:15 +0200)
committerMike Pall <mike>
Thu, 21 Sep 2023 00:15:16 +0000 (02:15 +0200)
Thanks to Sergey Bronnikov and Peter Cawley. #1087

src/lj_trace.c

index a72e73a3a38f718ffe01f2a31ce633d25abaa650..25e610b58992a92bb2ed6fdc74eff3509d58d82f 100644 (file)
@@ -524,21 +524,27 @@ static int trace_abort(jit_State *J)
     J->cur.link = 0;
     J->cur.linktype = LJ_TRLINK_NONE;
     lj_vmevent_send(L, TRACE,
-      TValue *frame;
+      cTValue *bot = tvref(L->stack);
+      cTValue *frame;
       const BCIns *pc;
-      GCfunc *fn;
+      BCPos pos = 0;
       setstrV(L, L->top++, lj_str_newlit(L, "abort"));
       setintV(L->top++, traceno);
       /* 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_iscont(frame) ? frame_contpc(frame) : frame_pc(frame)) - 1;
-       frame = frame_prev(frame);
+      for (frame = J->L->base-1, pc = J->pc; ; frame = frame_prev(frame)) {
+       if (isluafunc(frame_func(frame))) {
+         pos = proto_bcpos(funcproto(frame_func(frame)), pc);
+         break;
+       } else if (frame_prev(frame) <= bot) {
+         break;
+       } else if (frame_iscont(frame)) {
+         pc = frame_contpc(frame) - 1;
+       } else {
+         pc = frame_pc(frame) - 1;
+       }
       }
-      fn = frame_func(frame);
-      setfuncV(L, L->top++, fn);
-      setintV(L->top++, proto_bcpos(funcproto(fn), pc));
+      setfuncV(L, L->top++, frame_func(frame));
+      setintV(L->top++, pos);
       copyTV(L, L->top++, restorestack(L, errobj));
       copyTV(L, L->top++, &J->errinfo);
     );