Skip to content

Commit 3f6a4be

Browse files
committed
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
1 parent 0f36bc0 commit 3f6a4be

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,7 @@ AS_IF([test x$rb_cv_builtin___builtin_choose_expr = xyes], [
19931993
])
19941994
])
19951995
RUBY_CHECK_BUILTIN_FUNC(__builtin_types_compatible_p, [__builtin_types_compatible_p(int, int)])
1996+
RUBY_CHECK_BUILTIN_FUNC(__builtin_trap, [__builtin_trap()])
19961997

19971998
AS_IF([test "$ac_cv_func_qsort_r" != no], [
19981999
AC_CACHE_CHECK(whether qsort_r is GNU version, rb_cv_gnu_qsort_r,

vm_backtrace.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,18 @@ inline static int
3333
calc_lineno(const rb_iseq_t *iseq, const VALUE *pc)
3434
{
3535
size_t pos = (size_t)(pc - iseq->body->iseq_encoded);
36-
/* use pos-1 because PC points next instruction at the beginning of instruction */
37-
return rb_iseq_line_no(iseq, pos - 1);
36+
if (LIKELY(pos)) {
37+
/* use pos-1 because PC points next instruction at the beginning of instruction */
38+
pos--;
39+
}
40+
#if VMDEBUG && defined(HAVE_BUILTIN___BUILTIN_TRAP)
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);
3848
}
3949

4050
int

0 commit comments

Comments
 (0)