Added stack trace functions

This commit is contained in:
Justin Ethier 2015-07-10 21:36:37 -04:00
parent 8dce2178d1
commit af1cf74b3b
2 changed files with 24 additions and 5 deletions

View file

@ -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 */

View file

@ -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);