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

No sourcefile available when debug gem is required inside an eval and breaking into the debugger inside #479

Closed
u3shit opened this issue Jan 4, 2022 · 4 comments · Fixed by #544

Comments

@u3shit
Copy link

u3shit commented Jan 4, 2022

Your environment

  • ruby -v: ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-linux]
  • rdbg -v: rdbg 1.4.0

Describe the bug
I decided to try out the new debug gem bundled with ruby 3.1.0, but it looks like I did too much black magic with how I load my code and it broke. I'm not 100% sure this is valid usage of this gem though, so feel free to close this issue if it is invalid.

To Reproduce
I have two files, a.rb:

require 'debug'
def foo; binding.debugger; end

and b.rb:

eval File.read('a.rb'), binding, 'a.rb'
foo

Running ruby b.rb, I get:

# No sourcefile available for a.rb
=>#0    Object#foo at a.rb:2
  #1    <main> at b.rb:2

If I require debug in b.rb, it works. If I use require_relative 'a' instead of File.read+eval, it works. If I require debug in a separate eval in b.rb, it also works. So does ruby -rdebug b.rb, and rdbg b.rb, obviously.

Expected behavior
It should display the source properly:

[1, 2] in a.rb
     1| require 'debug'
=>   2| def foo; binding.debugger; end

Additional context
Sorry.

@ko1
Copy link
Collaborator

ko1 commented Jan 4, 2022

Thank you for your report. I'll investigate it.

BTW binding.debugger you only need to use debugger.
(binding.break or binding.b for users prefer to write binding.xxx like binding.pry)

@ko1
Copy link
Collaborator

ko1 commented Jan 4, 2022

Ah, this is from Ruby 3.1 changes. I'll fix it soon (maybe in Jan).

@jemmaissroff
Copy link

I was curious about this so spent a little time investigating.

@ko1 do you think this is happening because the TracePoint.new(:script_compiled) call occurs after the file a.rb has already been loaded? So the debugger can't see the script as it has already been compiled?

Also, as an aside, while investigating this I found TracePoint.trace which looks like a helper method that does both the TracePoint.new and TracePoint.enable calls, and could be used in the :script_compiled case as well as a few other spots in the codebase. Let me know if it would be useful for me to make that PR.

ko1 added a commit that referenced this issue Feb 21, 2022
From Ruby 3.1, a path given by eval does not return by
`ISeq#absolute_path`.

fix #479

With this fix, use `File.readlines(chomp: true)`.
@ko1
Copy link
Collaborator

ko1 commented Feb 21, 2022

Your investigation is correct. However, if a file name is given for eval method, debugger should try to check the given file name (and if debugger can find a file, debugger should show the existing file). #544 fixes it.

@ko1 ko1 closed this as completed in #544 Feb 21, 2022
ko1 added a commit that referenced this issue Feb 21, 2022
From Ruby 3.1, a path given by eval does not return by
`ISeq#absolute_path`.

fix #479

With this fix, use `File.readlines(chomp: true)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants