Giter Site home page Giter Site logo

Debugging Rack apps about vim-ruby-debugger HOT 5 CLOSED

astashov avatar astashov commented on June 16, 2024
Debugging Rack apps

from vim-ruby-debugger.

Comments (5)

astashov avatar astashov commented on June 16, 2024

Sure, it is possible. You can debug any Rack application, including Sinatra and Rails.
For now, AFAIK there is no way to use Passenger for debugging Rack applications. I use Webrat or Mongrel instead, by the following algorithm:

  1. Open Vim (or gVim/MacVim) in the root dir of the app

  2. Run debugger by:

    :Rdebugger (for Rails 2.*)
    :Rdebugger 'script/rails start' (for Rails 3.*)
    :Rdebugger '/usr/bin/rackup config.ru' (for any other Rack app, e.g. Sinatra or just plain Rack app). 
    

Note that you have to use the full absolute path to rackup, usually it is /usr/bin. Also, specify the path to config.ru as the relative path from the app's root dir. I.e. if config.ru is placed right in the root path of the app, you can specify it just as 'config.ru'

This command will start rdebug-ide, which will start app server like Webrat and Mongrel on some port (see below).
3. Put breakpoint e.g. somewhere in your controller.
4. Open a route for that controller in some browser, e.g. http://localhost:3000/posts
Rails usually starts itself on the 3000 port, 'rackup' usually starts Rack apps on the 9292 port.
5. After that, debugger should stop execution on the breakpoint you specified and you should be able to see variables there.

Ports 39767 and 39768 are inner ports used only by vim-ruby-debugger for passing messages from and to rdebug-ide, and you don't need to use them at all.

Please keep me posted if you can or can't run it successfully. I'm sure we'll be able to make it work in any case.

Thanks for using it. :)

from vim-ruby-debugger.

constfun avatar constfun commented on June 16, 2024

Thank you for the quick and detailed reply.

I had to install the pre-release version of mongrel since I'm using the current version of ruby (1.9.2) as per: http://stackoverflow.com/questions/1073841/gem-install-mongrel-fails-with-ruby-1-9-1/2892360#2892360

I also installed and tried Thin.

I can run the following commands from the terminal and in root of my Sinatra app and they all launch the server and allow me to navigate to http://localhost:9292 to view the app:

$ rackup
127.0.0.1 - - [09/Jan/2011 15:48:10] "GET / HTTP/1.1" 200 4 0.0164
127.0.0.1 - - [09/Jan/2011 15:48:10] "GET /favicon.ico HTTP/1.1" 200 28 0.0009

- or -

$ rackup -s thin
>> Thin web server (v1.2.7 codename No Hup)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9292, CTRL+C to stop
127.0.0.1 - - [09/Jan/2011 15:51:41] "GET / HTTP/1.1" 200 4 0.0319
127.0.0.1 - - [09/Jan/2011 15:51:41] "GET /favicon.ico HTTP/1.1" 200 28 0.0011

- or -

$ rackup -s webrick
[2011-01-09 15:52:16] INFO  WEBrick 1.3.1
[2011-01-09 15:52:16] INFO  ruby 1.9.2 (2010-12-25) [i686-linux]
[2011-01-09 15:52:16] INFO  WEBrick::HTTPServer#start: pid=5442 port=9292
127.0.0.1 - - [09/Jan/2011 15:52:22] "GET / HTTP/1.1" 200 4 0.0031
127.0.0.1 - - [09/Jan/2011 15:52:22] "GET /favicon.ico HTTP/1.1" 200 28 0.0008

- or explicitly (mongrel seems to be default with just 'rackup') -

$ rackup -s mongrel
127.0.0.1 - - [09/Jan/2011 15:53:48] "GET / HTTP/1.1" 200 4 0.0146
127.0.0.1 - - [09/Jan/2011 15:53:48] "GET /favicon.ico HTTP/1.1" 200 28 0.0009

However, when in vim I do:

:Rdebugger '/usr/local/bin/rackup config.ru'
or :Rdebugger '/usr/local/bin/rackup -s mongrel config.ru'
or :Rdebugger '/usr/local/bin/rackup -s thin config.ru'
etc.

Rdebugger reports that the debugger has been started, but I get nothing in the browser at http://localhost:9292

from vim-ruby-debugger.

astashov avatar astashov commented on June 16, 2024

Looks like you use Ruby 1.9.2 as default Ruby installed system-wide, and without RVM, right?
Please do these things:

  1. Update vim-ruby-debugger to the latest version
  2. Add 'let g:ruby_debugger_debug_mode = 1' to your .vimrc
  3. Go to the Sinatra app's dir and run Vim
  4. Execute :Rdebugger /usr/local/bin/rackup
  5. Send me log files:
    ~/.vim/tmp/ruby_debugger
    ~/.vim/tmp/ruby_debugger_log
    ~/.vim/tmp/ruby_debugger_output

Thanks!

from vim-ruby-debugger.

constfun avatar constfun commented on June 16, 2024

Pulling your latest changes from today fixed the problem!

Before pulling latest. This was in ruby_debugger_output:
Fast Debugger (ruby-debug-ide 0.4.16, ruby-debug-base 0.11) listens on 127.0.0.1:39767
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug-ide-0.4.16/lib/ruby-debug-ide.rb:112:in debug_load' /usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug-ide-0.4.16/lib/ruby-debug-ide.rb:112:indebug_program'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug-ide-0.4.16/bin/rdebug-ide:87:in <top (required)>' /usr/local/bin/rdebug-ide:19:inload'
/usr/local/bin/rdebug-ide:19:in `

'
Uncaught exception: no such file to load -- /home/nick/workspace/test_project//usr/local/bin/rackup

As a sanity check I ran:
Rdebugger '../../../../usr/local/bin/rackup'

This worked! Again, this is prior to pulling latest.

Then I pulled your latest changes and it now works with the absolute path as well:
Rdebugger '/usr/local/bin/rackup'

It appears that somewhere in b49005f you fixed the problem.

And yes, you're exactly right. 1.9.2 and no RVM

Everything is working perfectly now (breaks, variable browser). Thank you!

from vim-ruby-debugger.

astashov avatar astashov commented on June 16, 2024

Great! Yes, I've fixed path resolving, and now you can use just ':Rdebugger rackup' if /usr/local/bin is presented in your PATH environment variable.

from vim-ruby-debugger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.