diff --git a/include/picrin/error.h b/include/picrin/error.h index cebc85e1..1c62294f 100644 --- a/include/picrin/error.h +++ b/include/picrin/error.h @@ -41,6 +41,7 @@ struct pic_error { } type; struct pic_string *msg; pic_value irrs; + pic_str *stack; }; #define pic_error_p(v) (pic_type(v) == PIC_TT_ERROR) diff --git a/src/debug.c b/src/debug.c index 63bc88a0..7ce89fc0 100644 --- a/src/debug.c +++ b/src/debug.c @@ -65,7 +65,7 @@ pic_print_backtrace(pic_state *pic, struct pic_error *e) /* TODO: print error irritants */ trace = pic_strcat(pic, trace, pic_str_new(pic, "\n", 1)); - trace = pic_strcat(pic, trace, pic_get_backtrace(pic)); + trace = pic_strcat(pic, trace, e->stack); /* print! */ printf("%s", pic_str_cstr(trace)); diff --git a/src/error.c b/src/error.c index 227c80f3..2c319b79 100644 --- a/src/error.c +++ b/src/error.c @@ -96,6 +96,7 @@ pic_errorf(pic_state *pic, const char *fmt, ...) e->type = PIC_ERROR_OTHER; e->msg = pic_str_ptr(pic_car(pic, err_line)); e->irrs = pic_cdr(pic, err_line); + e->stack = pic_get_backtrace(pic); pic_throw(pic, e); } @@ -133,6 +134,7 @@ pic_error_raise(pic_state *pic) e->type = PIC_ERROR_RAISED; e->msg = pic_str_new_cstr(pic, "object is raised"); e->irrs = pic_list1(pic, v); + e->stack = pic_get_backtrace(pic); pic_throw(pic, e); } @@ -151,6 +153,7 @@ pic_error_error(pic_state *pic) e->type = PIC_ERROR_OTHER; e->msg = str; e->irrs = pic_list_by_array(pic, argc, argv); + e->stack = pic_get_backtrace(pic); pic_throw(pic, e); } diff --git a/src/gc.c b/src/gc.c index 81906f66..fd48833e 100644 --- a/src/gc.c +++ b/src/gc.c @@ -391,6 +391,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj) struct pic_error *err = (struct pic_error *)obj; gc_mark_object(pic,(struct pic_object *)err->msg); gc_mark(pic, err->irrs); + gc_mark_object(pic, (struct pic_object *)err->stack); break; } case PIC_TT_STRING: {