Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Byebug with a remote process (e.g., pow)

How do I connect to a remote debugging instance of Byebug (for use with Pow, etc)?

like image 796
Joseph Siefers Avatar asked Apr 01 '14 18:04

Joseph Siefers


People also ask

How do you run a Byebug?

Starting Byebug If you're running Byebug on a Rails application in development mode, you no longer need to start the server with --debugger – the debugger is on by default. To get going, simply type byebug (or debugger ) into your source file at the line you're interested in and run the program.

How do you use a pry remote?

When the breakpoint is hit, pry-remote will block your app and open up a DRb endpoint that a client can connect to. Running pry-remote in a shell will then connect to the session and you'll be able to interact with Pry as you normally would. Simply call exit in the Pry session to unblock the application.

What is Byebug?

Byebug is a Ruby debugger. It's implemented using the TracePoint C API for execution control and the Debug Inspector C API for call stack navigation. The core component provides support that front-ends can build on.


2 Answers

Joseph's answer was good but confusing in some small ways. He places the starting of the byebug server in config/environments/development.rb, when it would be better in an initializer. Additionally the exporting of the environment variable go in .powenv or .powrc. This is how I got it to work.

In your gemfile:

gem 'byebug' 

On the command line:

bundle install 

If you are using Pow, add the following to .powenv:

export BYEBUGPORT=3001 

If you are using other frameworks (e.g. just foreman), you may have to modify .env instead.

In config/initializers/byebug.rb

if Rails.env.development? and ENV['BYEBUGPORT']   require 'byebug/core'   Byebug.start_server 'localhost', ENV['BYEBUGPORT'].to_i end 

And finally on the command line:

touch tmp/restart.txt 

Once you go to your pow site, the byebug server should be started. On the command line you can now do:

[bundle exec] byebug -R localhost:3001 
like image 177
Nick Gronow Avatar answered Sep 22 '22 21:09

Nick Gronow


I had to piece together information from several different sources to accomplish the above, so I thought I'd include a consolidated guide here for convenience:

  • https://github.com/deivid-rodriguez/byebug/pull/29,
  • https://github.com/deivid-rodriguez/byebug/pull/36,
  • https://github.com/deivid-rodriguez/byebug/issues/31
  • http://mines.mouldwarp.com/2012/04/pow-guard-and-rdebug-staying-in-web-app.html

Here are the steps:

  1. In config/environments/development.rb, add:

    require 'byebug'  #set in your .powconfig if ENV['RUBY_DEBUG_PORT']   Byebug.start_server 'localhost', ENV['RUBY_DEBUG_PORT'].to_i else   Byebug.start_server 'localhost' end 
  2. Restart Pow and visit yourapp.dev

  3. Run the following:

    [bundle exec] byebug -R localhost:<port_you_defined_in_pow_config> 

You should see a successful connection to the remote instance.

like image 44
Joseph Siefers Avatar answered Sep 21 '22 21:09

Joseph Siefers