diff options
| author | Yukihiro Matz Matsumoto <[email protected]> | 2012-12-12 18:23:20 +0900 |
|---|---|---|
| committer | Yukihiro Matz Matsumoto <[email protected]> | 2012-12-12 18:23:20 +0900 |
| commit | fd12f87712ee22b0a727f33f0c46c22ae968ec83 (patch) | |
| tree | 3c69cbafe260611f10a79b997d2bc76404cbd338 /tools | |
| parent | f63d5c290510965e1256e4fac77709da83a6719a (diff) | |
| download | mruby-fd12f87712ee22b0a727f33f0c46c22ae968ec83.tar.gz mruby-fd12f87712ee22b0a727f33f0c46c22ae968ec83.zip | |
save lastpc on exception and use it in mruby stack trace
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/mruby/mruby.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/tools/mruby/mruby.c b/tools/mruby/mruby.c index d3ea924c7..99af7bc5d 100644 --- a/tools/mruby/mruby.c +++ b/tools/mruby/mruby.c @@ -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); + } } } |
