summaryrefslogtreecommitdiff
path: root/vm_backtrace.c
diff options
context:
space:
mode:
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 0493ed8c89..776f6d188a 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