implement settrace

This commit is contained in:
blueloveTH 2025-03-06 11:59:50 +08:00
parent 483e6fcb57
commit db7c577c94
2 changed files with 17 additions and 5 deletions

View File

@ -66,7 +66,13 @@ static bool stack_format_object(VM* self, c11_sv spec);
FrameResult res = VM__vectorcall(self, (argc), (kwargc), true); \
switch(res) { \
case RES_RETURN: PUSH(&self->last_retval); break; \
case RES_CALL: frame = self->top_frame; goto __NEXT_FRAME; \
case RES_CALL: { \
frame = self->top_frame; \
if(self->trace_info.tracefunc) { \
self->trace_info.tracefunc((py_Frame*)frame, TRACE_EVENT_CALL); \
} \
goto __NEXT_FRAME; \
} \
case RES_ERROR: goto __ERROR; \
default: c11__unreachable(); \
} \
@ -751,6 +757,9 @@ FrameResult VM__run_top_frame(VM* self) {
} else {
py_newnone(&self->last_retval);
}
if(self->trace_info.tracefunc) {
self->trace_info.tracefunc((py_Frame*)frame, TRACE_EVENT_RETURN);
}
VM__pop_frame(self);
if(frame == base_frame) { // [ frameBase<- ]
return RES_RETURN;

View File

@ -17,7 +17,6 @@ typedef struct BaseException {
c11_vector /*T=BaseExceptionFrame*/ stacktrace;
} BaseException;
void py_BaseException__stpush(py_Ref self, SourceData_ src, int lineno, const char* func_name) {
BaseException* ud = py_touserdata(self);
if(ud->stacktrace.length >= 7) return;
@ -252,6 +251,10 @@ bool py_raise(py_Ref exc) {
}
vm->curr_exception = *exc;
vm->is_curr_exc_handled = false;
if(vm->trace_info.tracefunc && !py_istype(exc, tp_StopIteration)) {
Frame* frame = vm->top_frame;
vm->trace_info.tracefunc((py_Frame*)frame, TRACE_EVENT_EXCEPTION);
}
return false;
}