1616#include < clasp/core/designators.h> // calledFunctionDesignator
1717#include < clasp/core/evaluator.h> // eval::funcall
1818#include < clasp/gctools/interrupt.h> // handle_all_queued_interrupts
19+ #include < clasp/core/step.h> // breakstep_arguments
1920
2021#define VM_CODES
2122#include < virtualMachine.h>
@@ -60,6 +61,19 @@ void BytecodeModule_O::register_for_debug() {
6061 newc->setCdr (old);
6162}
6263
64+ // Note that we check stepping in the callER not the callEE.
65+ // This is so that we could provide the actual source forms, as we already do
66+ // in native code. TODO
67+ static void maybe_step_call (void * frame,
68+ Function_sp func, size_t nargs, T_O** rargs) {
69+ if (my_thread->_Breakstep ) [[unlikely]] {
70+ ql::list args;
71+ for (size_t iarg = 0 ; iarg < nargs; ++iarg)
72+ args << T_sp ((gctools::Tagged)rargs[iarg]);
73+ breakstep_args (frame, func, args.cons ());
74+ }
75+ }
76+
6377static inline int16_t read_s16 (unsigned char * pc) {
6478 uint8_t byte0 = *pc;
6579 uint8_t byte1 = *(pc + 1 );
@@ -259,6 +273,7 @@ bytecode_vm(VirtualMachine& vm, T_O** literals, T_O** closed, Closure_O* closure
259273 T_sp tfunc ((gctools::Tagged)(*(vm.stackref (sp, nargs))));
260274 Function_sp func = gc::As_assert<Function_sp>(tfunc);
261275 T_O** args = vm.stackref (sp, nargs - 1 );
276+ maybe_step_call (__builtin_frame_address (0 ), func, nargs, args);
262277 // We push the PC for the debugger (see make_bytecode_frame in backtrace.cc)
263278 // We do this here rather than bytecode_call because e.g. we may call a
264279 // non-bytecode function, that in turn calls a bunch of different bytecode
@@ -281,6 +296,7 @@ bytecode_vm(VirtualMachine& vm, T_O** literals, T_O** closed, Closure_O* closure
281296 VM_RECORD_PLAYBACK (func, " vm_call_receive_one_func" );
282297 VM_RECORD_PLAYBACK ((void *)(uintptr_t )nargs, " vm_call_receive_one_nargs" );
283298 T_O** args = vm.stackref (sp, nargs - 1 );
299+ maybe_step_call (__builtin_frame_address (0 ), func, nargs, args);
284300#if DEBUG_VM_RECORD_PLAYBACK == 1
285301 for (size_t ii = 0 ; ii < nargs; ii++) {
286302 stringstream name_args;
@@ -305,6 +321,7 @@ bytecode_vm(VirtualMachine& vm, T_O** literals, T_O** closed, Closure_O* closure
305321 T_sp tfunc ((gctools::Tagged)(*(vm.stackref (sp, nargs))));
306322 Function_sp func = gc::As_assert<Function_sp>(tfunc);
307323 T_O** args = vm.stackref (sp, nargs - 1 );
324+ maybe_step_call (__builtin_frame_address (0 ), func, nargs, args);
308325 vm.push (sp, (T_O*)pc);
309326 vm._pc = pc;
310327 vm._stackPointer = sp;
@@ -658,6 +675,7 @@ bytecode_vm(VirtualMachine& vm, T_O** literals, T_O** closed, Closure_O* closure
658675 T_sp tfunc ((gctools::Tagged)(*(vm.stackref (sp, nargs))));
659676 Function_sp func = gc::As_assert<Function_sp>(tfunc);
660677 T_O** args = vm.stackref (sp, nargs - 1 );
678+ maybe_step_call (__builtin_frame_address (0 ), func, nargs, args);
661679 vm.push (sp, (T_O*)pc);
662680 vm._pc = pc;
663681 vm._stackPointer = sp;
@@ -675,6 +693,7 @@ bytecode_vm(VirtualMachine& vm, T_O** literals, T_O** closed, Closure_O* closure
675693 T_sp tfunc ((gctools::Tagged)(*(vm.stackref (sp, nargs))));
676694 Function_sp func = gc::As_assert<Function_sp>(tfunc);
677695 T_O** args = vm.stackref (sp, nargs - 1 );
696+ maybe_step_call (__builtin_frame_address (0 ), func, nargs, args);
678697 vm.push (sp, (T_O*)pc);
679698 vm._pc = pc;
680699 vm._stackPointer = sp;
@@ -693,6 +712,7 @@ bytecode_vm(VirtualMachine& vm, T_O** literals, T_O** closed, Closure_O* closure
693712 T_sp tfunc ((gctools::Tagged)(*(vm.stackref (sp, nargs))));
694713 Function_sp func = gc::As_assert<Function_sp>(tfunc);
695714 T_O** args = vm.stackref (sp, nargs - 1 );
715+ maybe_step_call (__builtin_frame_address (0 ), func, nargs, args);
696716 vm.push (sp, (T_O*)pc);
697717 vm._pc = pc;
698718 vm._stackPointer = sp;
@@ -1045,6 +1065,7 @@ static unsigned char* long_dispatch(VirtualMachine& vm, unsigned char* pc, Multi
10451065 T_sp tfunc ((gctools::Tagged)(*(vm.stackref (sp, nargs))));
10461066 Function_sp func = gc::As_assert<Function_sp>(tfunc);
10471067 T_O** args = vm.stackref (sp, nargs - 1 );
1068+ maybe_step_call (__builtin_frame_address (0 ), func, nargs, args);
10481069 vm.push (sp, (T_O*)pc);
10491070 vm._pc = pc;
10501071 vm._stackPointer = sp;
@@ -1060,9 +1081,10 @@ static unsigned char* long_dispatch(VirtualMachine& vm, unsigned char* pc, Multi
10601081 DBG_VM1 (" long call-receive-one %" PRIu16 " \n " , nargs);
10611082 T_sp tfunc ((gctools::Tagged)(*(vm.stackref (sp, nargs))));
10621083 Function_sp func = gc::As_assert<Function_sp>(tfunc);
1084+ T_O** args = vm.stackref (sp, nargs - 1 );
1085+ maybe_step_call (__builtin_frame_address (0 ), func, nargs, args);
10631086 VM_RECORD_PLAYBACK (func, " vm_call_receive_one_func" );
10641087 VM_RECORD_PLAYBACK ((void *)(uintptr_t )nargs, " vm_call_receive_one_nargs" );
1065- T_O** args = vm.stackref (sp, nargs - 1 );
10661088#if DEBUG_VM_RECORD_PLAYBACK == 1
10671089 for (size_t ii = 0 ; ii < nargs; ii++) {
10681090 stringstream name_args;
@@ -1089,6 +1111,7 @@ static unsigned char* long_dispatch(VirtualMachine& vm, unsigned char* pc, Multi
10891111 T_sp tfunc ((gctools::Tagged)(*(vm.stackref (sp, nargs))));
10901112 Function_sp func = gc::As_assert<Function_sp>(tfunc);
10911113 T_O** args = vm.stackref (sp, nargs - 1 );
1114+ maybe_step_call (__builtin_frame_address (0 ), func, nargs, args);
10921115 vm.push (sp, (T_O*)pc);
10931116 vm._pc = pc;
10941117 vm._stackPointer = sp;
@@ -1307,6 +1330,7 @@ static unsigned char* long_dispatch(VirtualMachine& vm, unsigned char* pc, Multi
13071330 T_sp tfunc ((gctools::Tagged)(*(vm.stackref (sp, nargs))));
13081331 Function_sp func = gc::As_assert<Function_sp>(tfunc);
13091332 T_O** args = vm.stackref (sp, nargs - 1 );
1333+ maybe_step_call (__builtin_frame_address (0 ), func, nargs, args);
13101334 vm.push (sp, (T_O*)pc);
13111335 vm._pc = pc;
13121336 vm._stackPointer = sp;
0 commit comments