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

IDE debugging of apps on Rails 5.2 broken #146

Closed
grumBit opened this issue Apr 27, 2018 · 11 comments
Closed

IDE debugging of apps on Rails 5.2 broken #146

grumBit opened this issue Apr 27, 2018 · 11 comments

Comments

@grumBit
Copy link

grumBit commented Apr 27, 2018

Your environment

  • vscode-ruby version: 0.18.0
  • Ruby version: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
  • Rails version: 5.2.0
  • ruby-debug-ide version: 0.6.1
  • debase version: 0.2.2
  • VS Code version: 1.22.2 (1.22.2)
  • Operating System: macOS 10.13.4 (17E199)
  • Hardware (optional): MacBook Pro (13-inch, Mid 2012) & MacBook (13-inch, Mid 2010)

Expected behavior

In IDE;

  • add break point to first line of [app root]/ config/application.rb;
    require_relative 'boot'
  • start debug.
  • debugger should stop at breakpoint

Actual behavior

  • debugger continues without stopping
  • NB: Any breakpoint further into execution of the Rails app fails to halt execution.

Work around;

Edit [app root]/ config/boot.rb
Comment out line;

  • require 'bootsnap/setup'

Debugging now works throughout app as expected.

Notes;

Looking at Shopify/bootsnap#93, I believe this problem occurs due a combination of the following;

NB: The same problem is occurring in other IDE's;

I don't believe this is a ruby-debug-ide issue itself, however, I'm wondering if a change to ruby-debug-ide could address the issue for developers using IDE's?

Also, I wanted to log the problem with a clear title so other Rails developers using IDE's will know what is going on, rather than spending time on searching for answers

(Apologies if my shotgun approach to submitting this issue on multiple repos is poor-form. I'm new to open-source development)

Steps to reproduce the problem

See attached development_machine_installation.txt, then follow steps in expected behaviour section above.
development_machine_installation.txt

@ViugiNick
Copy link
Collaborator

@grumBit Did you try the workaround, which is described in the ticket (https://youtrack.jetbrains.com/issue/RUBY-20684)

@grumBit
Copy link
Author

grumBit commented Apr 27, 2018

I tried the earlier comment to not use bootsnap - https://youtrack.jetbrains.com/issue/RUBY-20684#comment=27-2669909, by commenting out bootsnap in boot.rb as per "Work around" above.

I didn't try the second comment to use an alternate debase gem - https://youtrack.jetbrains.com/issue/RUBY-20684#comment=27-2773671

For my purposes, not using bootsnap at all is good enough. Would it help you, for me to try the alternate debase gem?

Because it took me sometime (possibly because I'm new to Rails), I was wondering if a workaround built into ruby-debug-ide on master would help other folks moving to rails 5.2 from going through the same pain of investigating & working around this problem.

@ViugiNick
Copy link
Collaborator

@grumBit This fix does not seem to me successful enough for merging it into master (and yes it would be very good if you tried the second approach)

@grumBit
Copy link
Author

grumBit commented Apr 27, 2018

I totally agree the workaround I've used is not appropriate for merging into ruby-debug-ide. It's just good enough for my purposes (i.e. learning rails).

I'll try using the alternate debase gem and let you know how I go.

@grumBit
Copy link
Author

grumBit commented Apr 28, 2018

@ViugiNick I installed the alternate debase into my environment, and it did allow the debugger to work.

However, I needed to start using Bundler in order to directly install a gem from a github branch. Alternatively, I could have; cloned the repo, checked-out the branch, built the gem, and installed the gem. Either way, the workaround being on a branch means getting it to work in some environments is tricky.

Also, using the alternate debase means manually editing <app_root_dir>/config/boot.rb, which doesn't seem ideal to me either.

Given the above, what do you think of using the alternate debase as a workaround?

For my purposes, it's easier to just comment out bootsnap from boot.rb.


These are the steps I used to get the alternate debase working;

  • Append to Gemfile;
    group :development, :test do
        gem 'ruby-debug-ide'
        gem 'debase', git: 'https://github.com/ViugiNick/debase.git', branch: 'load_iseq_monkeypatch'
    end
  • At command line;
    gem uninstall debase
    cd <app root dir>
    bundler install
  • In VS Code, add to Rails server section of launch.json;
    "useBundler": true
  • Append the following line to <app_root_dir>/config/boot.rb;
    Debugger.mp_load_iseq

@grumBit
Copy link
Author

grumBit commented Apr 28, 2018

@ViugiNick I've just put 2 & 2 together and noticed it's your branch on the debase repo for the workaround! Does this mean you might be merging it into master? If so, that would make the workaround much easier for people to adopt.

@nicolasrouanne
Copy link

@ViugiNick +1 Do you have any idea if your quick fix for debase (ruby-debug/debase#62) would be mergeable any time soon?
It would be nice to keep bootsnap and a normal released debase

@nicolasrouanne
Copy link

Here is how I got it working on Rails 5.2 and ruby 2.5.1p57

# config/boot.rb
[...]
require 'bootsnap/setup' unless ENV['RUBY_DEBUG_IDE'] == 'true'

And launching my debugger with `RUBY_DEBUG_IDE=true``

For those using VS Code here is my configuration

   {
      "name": "Rails server",
      "type": "Ruby",
      "request": "launch",
      "cwd": "${workspaceRoot}",
      "program": "${workspaceRoot}/bin/rails",
      "args": ["server"],
      "useBundler": true,
      "pathToBundler": "/Users/<username>/.rvm/gems/ruby-2.5.1/wrappers/bundle",
      "env": { "RUBY_DEBUG_IDE": true }
    },

Note that if you use rvm (like me), you need to set useBundler to true.
I found my path to bundler by typing which bundle and replacing bin by wrapper in the the PATH as stated in rubyide/vscode-ruby#16 (comment)

@ycherniavskyi
Copy link

One more possible workaround but without additional environment variable:

# config/boot.rb
[...]
unless defined?(Debugger)
  require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
end
[...]

@grumBit
Copy link
Author

grumBit commented Sep 14, 2018

@ycherniavskyi Your workaround is very nice! Thank you :).

@grumBit grumBit closed this as completed Sep 14, 2018
@grumBit
Copy link
Author

grumBit commented Sep 14, 2018

@ycherniavskyi It would appear the underlying Ruby issue is fixed in 2.5.2 (ruby/ruby@b85b10c).

Given the problem only existed on Ruby versions 2.5.0 through 2.5.1., perhaps the following workaround would be a keeper?

# config/boot.rb
[...]
unless ( (('2.5.0'..'2.5.1').include? RUBY_VERSION) && defined?(Debugger) )
  require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
end
[...]

ViugiNick added a commit to ViugiNick/debase that referenced this issue Jan 16, 2019
valich pushed a commit to ruby-debug/debase that referenced this issue Jan 18, 2019
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

4 participants