save stacktrace in error objects

This commit is contained in:
Yuichi Nishiwaki 2014-04-06 14:02:21 +09:00
parent 920524dc40
commit 5893dd5b5c
4 changed files with 6 additions and 1 deletions

View File

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

View File

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

View File

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

View File

@ -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: {