mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
save lastpc on exception and use it in mruby stack trace
This commit is contained in:
+5
-2
@@ -920,8 +920,9 @@ mrb_obj_public_methods(mrb_state *mrb, mrb_value self)
|
||||
mrb_value
|
||||
mrb_f_raise(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_value a[2];
|
||||
mrb_value a[2], exc;
|
||||
int argc;
|
||||
|
||||
|
||||
argc = mrb_get_args(mrb, "|oo", &a[0], &a[1]);
|
||||
switch (argc) {
|
||||
@@ -936,7 +937,9 @@ mrb_f_raise(mrb_state *mrb, mrb_value self)
|
||||
}
|
||||
/* fall through */
|
||||
default:
|
||||
mrb_exc_raise(mrb, mrb_make_exception(mrb, argc, a));
|
||||
exc = mrb_make_exception(mrb, argc, a);
|
||||
mrb_obj_iv_set(mrb, mrb_obj_ptr(exc), mrb_intern(mrb, "lastpc"), mrb_voidp_value(mrb->ci->pc));
|
||||
mrb_exc_raise(mrb, exc);
|
||||
}
|
||||
return mrb_nil_value(); /* not reached */
|
||||
}
|
||||
|
||||
@@ -1151,6 +1151,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
|
||||
int eidx;
|
||||
|
||||
L_RAISE:
|
||||
mrb_obj_iv_ifnone(mrb, mrb->exc, mrb_intern(mrb, "lastpc"), mrb_voidp_value(pc));
|
||||
ci = mrb->ci;
|
||||
eidx = mrb->ci->eidx;
|
||||
if (ci == mrb->cibase) goto L_STOP;
|
||||
|
||||
+25
-8
@@ -188,8 +188,15 @@ showcallinfo(mrb_state *mrb)
|
||||
mrb_irep *irep = ci->proc->body.irep;
|
||||
if (irep->filename != NULL)
|
||||
filename = irep->filename;
|
||||
if (irep->lines != NULL && i+1 <= ciidx) {
|
||||
mrb_code *pc = mrb->cibase[i+1].pc;
|
||||
if (irep->lines != NULL) {
|
||||
mrb_code *pc;
|
||||
|
||||
if (i+1 <= ciidx) {
|
||||
pc = mrb->cibase[i+1].pc;
|
||||
}
|
||||
else {
|
||||
pc = (mrb_code*)mrb_voidp(mrb_obj_iv_get(mrb, mrb->exc, mrb_intern(mrb, "lastpc")));
|
||||
}
|
||||
if (irep->iseq <= pc && pc < irep->iseq + irep->ilen) {
|
||||
line = irep->lines[pc - irep->iseq - 1];
|
||||
}
|
||||
@@ -201,12 +208,22 @@ showcallinfo(mrb_state *mrb)
|
||||
sep = "#";
|
||||
|
||||
method = mrb_sym2name(mrb, ci->mid);
|
||||
printf("\t[%d] %s:%d%s%s%s%s\n",
|
||||
i, filename, line,
|
||||
method ? ":in " : "",
|
||||
method ? mrb_class_name(mrb, ci->proc->target_class) : "",
|
||||
method ? sep : "",
|
||||
method ? method : "");
|
||||
if (method) {
|
||||
const char *cn = mrb_class_name(mrb, ci->proc->target_class);
|
||||
|
||||
if (cn) {
|
||||
printf("\t[%d] %s:%d:in %s%s%s\n",
|
||||
i, filename, line, cn, sep, method);
|
||||
}
|
||||
else {
|
||||
printf("\t[%d] %s:%d:in %s\n",
|
||||
i, filename, line, method);
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("\t[%d] %s:%d\n",
|
||||
i, filename, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user