diff --git a/runtime.c b/runtime.c index b7a9a9b7..6c6fa9b0 100644 --- a/runtime.c +++ b/runtime.c @@ -71,12 +71,20 @@ static symbol_type Cyc_void_symbol = {symbol_tag, "", nil}; const object quote_void = &Cyc_void_symbol; /* Stack Traces */ -const int MAX_STACK_TRACES = 10; -char **Cyc_Stack_Traces; -int Cyc_Stack_Trace_Idx = 0; +static const int MAX_STACK_TRACES = 10; +static char **Cyc_Stack_Traces; +static int Cyc_Stack_Trace_Idx = 0; + +void Cyc_st_init() { + Cyc_Stack_Traces = calloc(MAX_STACK_TRACES, sizeof(char *)); +} + +void Cyc_st_add(char *frame) { + /* add to circ buf */ + Cyc_Stack_Traces[Cyc_Stack_Trace_Idx] = frame; + Cyc_Stack_Trace_Idx = (Cyc_Stack_Trace_Idx + 1) % MAX_STACK_TRACES; +} -void Cyc_st_init() { /* calloc tbl */ } -void Cyc_st_add(char *frame) { /* add to circ buf */ } void Cyc_st_print(FILE *out) { /* print to stream, note it is possible that some traces could be on the stack after a GC. @@ -85,6 +93,13 @@ void Cyc_st_print(FILE *out) { or, with the tbl being so small, maybe it will not be an issue in practice? a bit risky to ignore though */ + int i = (Cyc_Stack_Trace_Idx + 1) % MAX_STACK_TRACES; + while (i != Cyc_Stack_Trace_Idx) { + if (Cyc_Stack_Traces[i]) { + fprintf(out, "%s\n", Cyc_Stack_Traces[i]); + } + i = (i + 1) % MAX_STACK_TRACES; + } } /* END Stack Traces section */ diff --git a/runtime.h b/runtime.h index 6826fcd6..bd772ee3 100644 --- a/runtime.h +++ b/runtime.h @@ -156,6 +156,10 @@ object memqp(object,list); char *transport(char *,int); void GC(closure,object*,int) never_returns; +void Cyc_st_init(); +void Cyc_st_add(char *frame); +void Cyc_st_print(FILE *out); + char *_strdup (const char *s); object add_symbol(symbol_type *psym); object add_symbol_by_name(const char *name);