Bug #18329
Updated by lewispb (Lewis Buckley) about 3 years ago
The following code runs on Ruby 2.7.4 and and doesn't produce a core dump. On Ruby 3.0.0, 3.0.2 and 3.1.0-preview 1 the following code produces a core dump:
``` ruby
# example2.rb
module Probes
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def probe(*methods)
prepend(probing_module(methods))
end
def probing_module(methods)
Module.new do
methods.each do |method|
define_method(method) do |*args, **kwargs, &block|
super(*args, **kwargs, &block)
end
end
end
end
end
end
class Probed
include Probes
probe :danger!, :missing
def danger!
raise "BOOM"
end
end
5.times do
subject = Probed.new
subject.danger! rescue RuntimeError
subject.missing rescue NoMethodError
end
```
```
example2.rb:15: [BUG] Segmentation fault at 0x0000000000000000
ruby 3.1.0preview1 (2021-11-09 master 5a3b2e6141) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0005 p:0021 s:0022 e:000019 BLOCK example2.rb:15 [FINISH]
c:0004 p:0018 s:0014 e:000013 BLOCK example2.rb:35 [FINISH]
c:0003 p:---- s:0010 e:000009 CFUNC :times
c:0002 p:0021 s:0006 e:000005 EVAL example2.rb:33 [FINISH]
c:0001 p:0000 s:0003 E:0008e0 (none) [FINISH]
-- Ruby level backtrace information ----------------------------------------
example2.rb:33:in `<main>'
example2.rb:33:in `times'
example2.rb:35:in `block in <main>'
example2.rb:15:in `block (3 levels) in probing_module'
-- Machine register context ------------------------------------------------
RIP: 0x00007fbf3622c7e0 RBP: 0x00007fbf3537ae40 RSP: 0x00007ffc825f7570
RAX: 0x0000000000000000 RBX: 0x00007fbf33f9c330 RCX: 0x0000d88f02870002
RDX: 0x00007fbf3560e568 RDI: 0x00007fbf33fcab50 RSI: 0x0000000002870000
R8: 0x0000000000000000 R9: 0x00007fbf3537b000 R10: 0x00007fbf33f9c330
R11: 0x00007fbf3537ae40 R12: 0x00007fbf3560d1e0 R13: 0x000000000000d88f
R14: 0x00007fbf3560e220 R15: 0x00007fbf3560e1f8 EFL: 0x0000000000010246
-- C level backtrace information -------------------------------------------
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(rb_print_backtrace+0x11) [0x7fbf3624f7ca] vm_dump.c:759
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(rb_vm_bugreport) vm_dump.c:1045
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(rb_bug_for_fatal_signal+0xf4) [0x7fbf360546b4] error.c:820
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(sigsegv+0x4d) [0x7fbf361a5b7d] signal.c:964
/lib/x86_64-linux-gnu/libpthread.so.0(__restore_rt+0x0) [0x7fbf35f453c0] ../sysdeps/pthread/funlockfile.c:28
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(vm_search_method_fastpath+0x0) [0x7fbf3622c7e0] vm_insnhelper.c:1939
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(vm_search_super_method) vm_insnhelper.c:3785
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(vm_sendish+0x25) [0x7fbf36237286] vm_insnhelper.c:4654
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(vm_exec_core) insns.def:864
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(rb_vm_exec+0xe7) [0x7fbf3623af07] vm.c:2196
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(invoke_bmethod+0x15a) [0x7fbf3623bb5a] vm.c:1328
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(vm_call_bmethod+0x116) [0x7fbf3623c326] vm_insnhelper.c:3090
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(vm_sendish+0x3) [0x7fbf36235475] vm_insnhelper.c:4651
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(vm_exec_core) insns.def:777
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(rb_vm_exec+0xe7) [0x7fbf3623af07] vm.c:2196
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(rb_yield_1+0x2e7) [0x7fbf3623f007] vm.c:1298
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(int_dotimes+0x5c) [0x7fbf360fb7ec] numeric.c:5213
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(vm_call_cfunc_with_frame+0x12b) [0x7fbf3622743b] vm_insnhelper.c:3025
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(vm_call_method_each_type+0x79) [0x7fbf3623c419] vm_insnhelper.c:3541
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(vm_call_method+0xb4) [0x7fbf3623cdd4] vm_insnhelper.c:3665
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(vm_sendish+0x13d) [0x7fbf3622c0bd] vm_insnhelper.c:4651
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(vm_exec_core+0x22a) [0x7fbf3623552a] insns.def:758
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(rb_vm_exec+0xe7) [0x7fbf3623af07] vm.c:2196
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(rb_ec_exec_node+0xbb) [0x7fbf360591eb] eval.c:280
/home/lewis/.rbenv/versions/3.1.0-preview1/lib/libruby.so.3.1(ruby_run_node+0x5a) [0x7fbf3605f41a] eval.c:321
/home/lewis/.rbenv/versions/3.1.0-preview1/bin/ruby(main+0x73) [0x55bfb7ca71d3] ./main.c:47
...
```