From 7c8823f3334dab17779ce1b90c8500889ff81ee2 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Sat, 17 Oct 2020 19:21:14 -0400 Subject: [PATCH] Cleanup printing of call history --- CHANGELOG.md | 1 + runtime.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7729122d..01f7ce30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Features - 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 diff --git a/runtime.c b/runtime.c index a8876858..c25f81a6 100644 --- a/runtime.c +++ b/runtime.c @@ -406,12 +406,16 @@ void Cyc_st_print(void *data, FILE * out) not be an issue in practice? a bit risky to ignore though */ 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) { 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); fprintf(stderr, "\n"); //raise(SIGINT); // break into debugger, unix only