3

I'm running ruby-debug with bundle exec rdebug script/server on Rails 2.3. When I press Ctrl-C, it exits the entire program and the debugger. I want it to stop execution of the program and bring me into a debugger session.

I tried catch Interrupt but it didn't work. Is there an exception that gets called when I stop rails with Ctrl-C that would be good to use for this purpose? Or is there another way?

What I want is the equivalent of pressing the Break (pause) button in Visual Studio (I haven't yet done this with a Rails IDE).

Benjamin Atkin
  • 14,071
  • 7
  • 61
  • 60
  • And at what point do you plan on pressing that pause button? I doubt you are fast enough to catch rails inside one of your action methods.. You can use the `debugger` command in your code to create a breakpoint - but breaking like in VS with the pause button is pretty much useless in a Web-App – Tigraine Jan 05 '12 at 21:59
  • Hmm, maybe a dev-only rack middleware to call `debugger` (which I already knew about, thx) in response to a certain API call that I call with CURL, would be an adequate solution. But I'm planning to do it so I can use rdb's interface to set a breakpoint, so it doesn't have to be at a certain time. It just has to not stop the program. – Benjamin Atkin Jan 06 '12 at 00:02
  • possible duplicate of [How do I configure ruby to enter the debugger on Ctrl-C (SIGINT)?](http://stackoverflow.com/questions/15278134/how-do-i-configure-ruby-to-enter-the-debugger-on-ctrl-c-sigint) – kenorb Aug 01 '15 at 19:04
  • @Tigraine methods are often very slow if there's something wrong. One common reason to break into a debugger is to find out why a method is taking a long time (often in library code). – James Moore Jan 28 '17 at 19:21
  • in case you are actually looking for a performance problem in your code I'd recommend using a actual profiler instead of a debugger. Debugger is only useful if you know something isn't working and want to get in there and look at the scope to debug what's wrong. – Tigraine Jan 30 '17 at 13:36

2 Answers2

3

I recommend pry over ruby-debug. Install the gem and then you can just stick this into your code where you want to debug:

binding.pry
klochner
  • 8,077
  • 1
  • 33
  • 45
1

you should just drop a debugger line in your code, this will automatically create a debugging session.

apneadiving
  • 114,565
  • 26
  • 219
  • 213