Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong line numbers inside set_trace_func for end events #4060

Closed
ivoanjo opened this issue Aug 10, 2016 · 0 comments
Closed

Wrong line numbers inside set_trace_func for end events #4060

ivoanjo opened this issue Aug 10, 2016 · 0 comments

Comments

@ivoanjo
Copy link
Contributor

ivoanjo commented Aug 10, 2016

Somewhat as a continuation of #4051 there are still some wrong line numbers passed to set_trace_func and in backtraces generated inside of it.

Environment

Running jruby 9.1.3.0-SNAPSHOT (2.3.0) 2016-08-06 3ba469b OpenJDK 64-Bit Server VM 25.91-b14 on 1.8.0_91-8u91-b14-3ubuntu1~15.10.1-b14 [linux-x86_64] (latest master, 3ba469b) on Ubuntu 15.10.

Expected Behavior

Example code:

set_trace_func proc { |type, _, line, *stuff|
  puts "Event #{type} @ #{line}, caller: #{caller.first}" if type == 'end'
}

module Foo
  class Bar
  end
end

Output in MRI 2.3.1:

Event end @ 7, caller: test.rb:7:in `<class:Bar>'
Event end @ 8, caller: test.rb:8:in `<module:Foo>'

Actual Behavior

Output in JRuby:

Event end @ 7, caller: test.rb:6:in `<class:Bar>'
Event end @ 7, caller: test.rb:6:in `<module:Foo>'

You'll notice that neither the lines supplied to caller nor the ones to set_trace_func are correct in this case.

@enebo enebo closed this as completed in 7c60d07 Dec 22, 2017
enebo added a commit that referenced this issue Dec 22, 2017
Fixes #4051. Wrong line numbers in Kernel#caller inside set_trace_func (with code to reproduce)

#4051 was largely already fixed but the backtrace elements themselves had the
wrong line (which was why #4060 was opened).

The problem was mri changes their position of class/module/sclass from start
line to end line.  We just store start line.  They will also look at first
instr/node within the class/module for start line.  That solution is memory
efficient but then makes those nodes report wrong lines with -S ast.

Our solution was to just add an endLine field to those nodes.  The memory
increase from that is very small so I think it is ok.

The second part of this was that we build backtrace from setting line number
via a line number instr.  We had no end line so we couldn't emit one.  Now that
we have one we do....but only if --debug is supplied since the only instr after
this point is return and that cannot raise (so we cannot generate a backtrace).
@enebo enebo added this to the JRuby 9.1.16.0 milestone Dec 22, 2017
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

No branches or pull requests

2 participants