on master help sign in
Implement tracing for C backend
8d8869bNiklas Larsson
rts/idris_rts.c+9−1
@@ -419,6 +419,13 @@ VAL MKB64(VM* vm, uint64_t bits64) {
419 return cl;
419 return cl;
420}
420}
421
421
422+void idris_trace(VM* vm, const char* func, int line) {
423+ printf("At %s:%d\n", func, line);
424+ dumpStack(vm);
425+ puts("");
426+ fflush(stdout);
427+}
428+
422void dumpStack(VM* vm) {
429void dumpStack(VM* vm) {
423 int i = 0;
430 int i = 0;
424 VAL* root;
431 VAL* root;
@@ -426,7 +433,8 @@ void dumpStack(VM* vm) {
426 for (root = vm->valstack; root < vm->valstack_top; ++root, ++i) {
433 for (root = vm->valstack; root < vm->valstack_top; ++root, ++i) {
427 printf("%d: ", i);
434 printf("%d: ", i);
428 dumpVal(*root);
435 dumpVal(*root);
429− if (*root >= (VAL)(vm->heap.heap) && *root < (VAL)(vm->heap.end)) { printf("OK"); }
436+ if (*root >= (VAL)(vm->heap.heap) && *root < (VAL)(vm->heap.end)) { printf(" OK"); }
437+ if (root == vm->valstack_base) { printf(" <--- base"); }
430 printf("\n");
438 printf("\n");
431 }
439 }
432 printf("RET: ");
440 printf("RET: ");
rts/idris_rts.h+10−1
@@ -235,7 +235,15 @@ typedef intptr_t i_int;
235
235
236// Stack management
236// Stack management
237
237
238+#ifdef IDRIS_TRACE
239+#define TRACE idris_trace(vm, __FUNCTION__, __LINE__);
240+#else
241+#define TRACE
242+#endif
243+
238−#define INITFRAME VAL* myoldbase
244+#define INITFRAME TRACE\
245+ VAL* myoldbase
246+
239#define REBASE vm->valstack_base = oldbase
247#define REBASE vm->valstack_base = oldbase
240#define RESERVE(x) if (vm->valstack_top+(x) > vm->stack_max) { stackOverflow(); } \
248#define RESERVE(x) if (vm->valstack_top+(x) > vm->stack_max) { stackOverflow(); } \
241 else { memset(vm->valstack_top, 0, (x)*sizeof(VAL)); }
249 else { memset(vm->valstack_top, 0, (x)*sizeof(VAL)); }
@@ -348,6 +356,7 @@ VM* idris_getSender(Msg* msg);
348int idris_getChannel(Msg* msg);
356int idris_getChannel(Msg* msg);
349void idris_freeMsg(Msg* msg);
357void idris_freeMsg(Msg* msg);
350
358
359+void idris_trace(VM* vm, const char* func, int line);
351void dumpVal(VAL r);
360void dumpVal(VAL r);
352void dumpStack(VM* vm);
361void dumpStack(VM* vm);
353
362