summaryrefslogtreecommitdiff
path: root/vm_backtrace.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-07 08:04:33 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-07 08:04:33 +0000
commit3f6a4be3a40566b6cacdb20577a02eebaba8e90a (patch)
treed81182d35f72fe7b43637d013a1e8a9ba50359af /vm_backtrace.c
parent0f36bc093fc738040e71f32da33411f15915c3d7 (diff)
vm_backtrace.c: pos can be zero
(lldb) target create "./miniruby" Current executable set to './miniruby' (x86_64). (lldb) settings set -- target.run-args "-e0" (lldb) run Process 97005 launched: './miniruby' (x86_64) ./miniruby(rb_print_backtrace+0x15) [0x10024f7d5] vm_dump.c:715 ./miniruby(rb_vm_get_sourceline+0x85) [0x10024c4f5] vm_backtrace.c:43 ./miniruby(rb_vm_make_binding+0x146) [0x100236976] vm.c:941 ./miniruby(Init_VM+0x592) [0x100249f02] vm.c:3091 ./miniruby(rb_call_inits+0xc2) [0x1000c5a72] inits.c:58 ./miniruby(ruby_setup+0xcb) [0x100098c6b] eval.c:74 ./miniruby(ruby_init+0x9) [0x100098c99] eval.c:91 ./miniruby(main+0x4d) [0x10025ddbd] addr2line.c:246 Process 97005 stopped * thread #1: tid = 0x639bb, 0x000000010024c4f5 miniruby`rb_vm_get_sourceline(cfp=<unavailable>) + 133 at vm_backtrace.c:44, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) frame #0: 0x000000010024c4f5 miniruby`rb_vm_get_sourceline(cfp=<unavailable>) + 133 at vm_backtrace.c:44 41 else { 42 /* SDR() is not possible; that causes infinite loop. */ 43 rb_print_backtrace(); -> 44 __builtin_trap(); 45 } 46 #endif 47 return rb_iseq_line_no(iseq, pos); (lldb) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_backtrace.c')
-rw-r--r--vm_backtrace.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/vm_backtrace.c b/vm_backtrace.c
index 0493ed8..776f6d1 100644
--- a/vm_backtrace.c
+++ b/vm_backtrace.c
@@ -33,8 +33,18 @@ inline static int
calc_lineno(const rb_iseq_t *iseq, const VALUE *pc)
{
size_t pos = (size_t)(pc - iseq->body->iseq_encoded);
- /* use pos-1 because PC points next instruction at the beginning of instruction */
- return rb_iseq_line_no(iseq, pos - 1);
+ if (LIKELY(pos)) {
+ /* use pos-1 because PC points next instruction at the beginning of instruction */
+ pos--;
+ }
+#if VMDEBUG && defined(HAVE_BUILTIN___BUILTIN_TRAP)
+ else {
+ /* SDR() is not possible; that causes infinite loop. */
+ rb_print_backtrace();
+ __builtin_trap();
+ }
+#endif
+ return rb_iseq_line_no(iseq, pos);
}
int