Skip to content

Fix Kernel#set_trace_func invocation after native Java EventHooks#2604

Closed
gsamokovarov wants to merge 1 commit intojruby:masterfrom
gsamokovarov:set-trace-func-after-java-event-hook
Closed

Fix Kernel#set_trace_func invocation after native Java EventHooks#2604
gsamokovarov wants to merge 1 commit intojruby:masterfrom
gsamokovarov:set-trace-func-after-java-event-hook

Conversation

@gsamokovarov
Copy link
Contributor

Hello,

Currently, registering plain Ruby Kernel#set_trace_func after native
extensions EventHooks fails with:

bug.rb:2 warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
Ruby.java:3058:in `removeEventHook': java.lang.ArrayIndexOutOfBoundsException: 0
         from Ruby.java:3066:in `setTraceFunction'
         from RubyKernel.java:1206:in `set_trace_func'
         from RubyKernel$INVOKER$s$1$0$set_trace_func.gen:-1:in `call'
         from JavaMethod.java:364:in `call'
         from CachingCallSite.java:317:in `cacheAndCall'
         from CachingCallSite.java:167:in `call'
         from Interpreter.java:293:in `processCall'
         from Interpreter.java:550:in `interpret'
         from Interpreter.java:617:in `INTERPRET_ROOT'
         from Interpreter.java:112:in `execute'
         from Interpreter.java:28:in `execute'
         from IRTranslator.java:39:in `execute'
         from Ruby.java:855:in `runInterpreter'
         from Ruby.java:863:in `runInterpreter'
         from Ruby.java:759:in `runNormally'
         from Ruby.java:564:in `runFromMain'
         from Main.java:405:in `doRunFromMain'
         from Main.java:300:in `internalRun'
         from Main.java:227:in `run'
         from Main.java:199:in `main'

I have a small reproduction script, which uses Coverage's native
EventHook, however the problem is present in custom extensions that
implement EventHooks themselves as well.

Here is the script:

require 'coverage'
Coverage.start

set_trace_func proc { |*args| p args }

I'm not sure whether my current solution is good enough, since I don't
know if the bargain with removeEventHook is to always find the previous
eventHook before, however it does prevent the crash in my tests.

Hope it helps!

Hello,

Currently, registering plain Ruby `Kernel#set_trace_func` after native
extensions EventHooks fails with:

```
bug.rb:2 warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
Ruby.java:3058:in `removeEventHook': java.lang.ArrayIndexOutOfBoundsException: 0
         from Ruby.java:3066:in `setTraceFunction'
         from RubyKernel.java:1206:in `set_trace_func'
         from RubyKernel$INVOKER$s$1$0$set_trace_func.gen:-1:in `call'
         from JavaMethod.java:364:in `call'
         from CachingCallSite.java:317:in `cacheAndCall'
         from CachingCallSite.java:167:in `call'
         from Interpreter.java:293:in `processCall'
         from Interpreter.java:550:in `interpret'
         from Interpreter.java:617:in `INTERPRET_ROOT'
         from Interpreter.java:112:in `execute'
         from Interpreter.java:28:in `execute'
         from IRTranslator.java:39:in `execute'
         from Ruby.java:855:in `runInterpreter'
         from Ruby.java:863:in `runInterpreter'
         from Ruby.java:759:in `runNormally'
         from Ruby.java:564:in `runFromMain'
         from Main.java:405:in `doRunFromMain'
         from Main.java:300:in `internalRun'
         from Main.java:227:in `run'
         from Main.java:199:in `main'
```

I have a small reproduction script, which uses `Coverage`'s native
EventHook, however the problem is present in custom extensions that
implement EventHooks themselves as well.

Here is the script:

```ruby
require 'coverage'
Coverage.start

set_trace_func proc { |*args| p args }
```

I'm not sure whether my current solution is good enough, since I don't
know if the bargain with removeEventHook is to always find the previous
eventHook before, however it does prevent the crash in my tests.

Hope it helps!
@gsamokovarov gsamokovarov force-pushed the set-trace-func-after-java-event-hook branch from e8f6556 to 6eee5e4 Compare February 20, 2015 10:00
@enebo enebo added this to the Invalid or Duplicate milestone May 1, 2015
@enebo
Copy link
Member

enebo commented May 1, 2015

I totally rewrote this method because it had a second issue in addition to the AIIOB (see #2903).

@enebo enebo closed this May 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants