Cleanup printing of call history

This commit is contained in:
Justin Ethier 2020-10-17 19:21:14 -04:00
parent 36252090d3
commit 7c8823f333
2 changed files with 9 additions and 4 deletions

View file

@ -4,6 +4,7 @@
Features Features
- Added definitions from SRFI 162 (comparators sublibrary) to the `(srfi 128)` library. - Added definitions from SRFI 162 (comparators sublibrary) to the `(srfi 128)` library.
- Cleaned up printing of call history to make it more obvious which functions were called most recently.
Bug Fixes Bug Fixes

View file

@ -406,12 +406,16 @@ void Cyc_st_print(void *data, FILE * out)
not be an issue in practice? a bit risky to ignore though not be an issue in practice? a bit risky to ignore though
*/ */
gc_thread_data *thd = (gc_thread_data *) data; gc_thread_data *thd = (gc_thread_data *) data;
int i = (thd->stack_trace_idx + 1) % MAX_STACK_TRACES; int n = 1;
int i = (thd->stack_trace_idx - 1);
if (i < 0) { i = MAX_STACK_TRACES - 1; }
while (i != thd->stack_trace_idx) { while (i != thd->stack_trace_idx) {
if (thd->stack_traces[i]) { if (thd->stack_traces[i]) {
fprintf(out, "%s\n", thd->stack_traces[i]); fprintf(out, "[%d] %s\n", n++, thd->stack_traces[i]);
} }
i = (i + 1) % MAX_STACK_TRACES; i = (i - 1);
if (i < 0) { i = MAX_STACK_TRACES - 1; }
} }
} }
@ -678,7 +682,7 @@ object Cyc_default_exception_handler(void *data, int argc, closure _,
} }
} }
fprintf(stderr, "\nCall history:\n"); fprintf(stderr, "\nCall history, most recent first:\n");
Cyc_st_print(data, stderr); Cyc_st_print(data, stderr);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
//raise(SIGINT); // break into debugger, unix only //raise(SIGINT); // break into debugger, unix only