 |
Forums |
Admin Start New Thread
By: Eric Promislow
RE: Pause execution [ reply ] 2009-02-05 00:03
|
One of the issues with debugging a Rails app (and probably a Merb app as well), is that due to the multi-threadedness of it, you don't know which thread is going to handle your handler, and chances are it's one of the threads that's waiting for a request, and not the thread that's actually doing the processing.
- Eric
|
By: Rocky Bernstein
RE: Pause execution [ reply ] 2009-02-01 16:28
|
Some thoughts since you asked ;-)
One probaby needs to find out the Rails or Rails+server understanding of what's with interrupts.
Another completely different approach might be to run ruby-debug using the remote/client protocol via TCP sockets -- if that's not already the case. I think in some contexts this may be the default. There may be some mechanism here (or probably should be if not) for sending an interrupt.
But if you are using the remote/client TCP socket connection, the then try *without* the remote/client protocol.
It's possible and even likely that ruby-debug could be improved to facilitate the kind of thing you are doing.
If you find a solution let us know. :-)
|
By: Steve V
RE: Pause execution [ reply ] 2009-01-23 22:47
|
|
I also tried trapping a different signal. I used ALRM since I was just messing around since both USR1 and USR2 are already in use. With ALRM I got some peculiar behavior. I sent the signal and it looked like nothing happened. When I went to kill the server with ^C it dropped me to an rdb prompt, but as soon as I went to continue it just exited.
|
By: Steve V
RE: Pause execution [ reply ] 2009-01-23 22:23
|
|
Do you have any thoughts on how that could be made to work with rails/mongrel? I tried trapping the signal in the development.rb config file, but it didn't have any effect. In mongrel.rb server file that rails uses to startup, there is a trap(:INT) {exit} just a few lines below where it starts the debugger. Even if I comment out this line, the server still shuts down when INT is received.
|
By: Rocky Bernstein
RE: Pause execution [ reply ] 2009-01-23 16:34
|
Ah, ok. Perhaps what you want to do is install a signal handler.
For example:
require 'rubygems'
require 'ruby-debug'
Debugger.start
Signal.trap('INT') { debugger; }
puts Process.pid
while true do
puts 'Sleeping 10'
sleep(10)
end
$ ruby test.rb
ruby /tmp/test.rb
10136
Sleeping 10
tmp/test.rb:7
puts 'Sleeping 10'
(rdb:1)
# From another shell: 'kill -INT 10135'
|
By: Steve V
RE: Pause execution [ reply ] 2009-01-23 14:32
|
Sorry, let me try and clear it up. My use case is more along the lines of debugging rails/merb applications. So in rails as you probably know, you can start a) "script/server -u" or b)"rdebug script/server". In 'a' it just drops right in and waits, 'b' brings you to a rdb prompt where you can do whatever you want, and then continue to actually let the server get going.
At that point you lose all control over rdb(no prompt). You can't arbitrarily set breakpoints or anything until some other breakpoint is hit; either by placing a "debugger" statement is hit, or some previously set breakpoint.
(rdb:24) c
...snip log statements...
Completed in 131ms (View: 56, DB: 8) | 200 OK [http://localhost/articles/2]
<blinking cursor, no prompt>
So if you want to debug a new page you have to either start throwing in "debugger" statements in your code, or you have to restart the rdb server and set the breakpoints there, then rinse and repeat every time you want to debug a new page.
I'm assuming that rdb is still doing something while waiting for the next request to come in, and is still listening in some fashion, because when another "debugger" point is hit it still has all of its state from previous runs. So I was wanting a way to pause execution wherever it may be and be given back a prompt. Maybe ctrl-c once to drop to a prompt(maybe it sets some kind of immediate breakpoint?), and again to quit?
ctrl-c
(rdb:25) b somefile.rb:32
(rdb:25) c
<back to waiting>
This could also be useful if you have some piece of code that appears to have fallen off a cliff, and isn't coming back, and you could just pause execution to see what it's doing.
|
By: Rocky Bernstein
RE: Pause execution [ reply ] 2009-01-23 01:49
|
I don't really understand what you are asking, but ruby-debug is mostly, well, Ruby. And Ruby's dynamic and pretty flexible.
So here's one way to add a command to ruby debug.
In file "/tmp/mycmd.rb":
module Debugger
class MyCommand < Command
def regexp
/^\s*me$/ # Regexp that will match your command
end
def execute
puts "hi" # What you want to happen when your command runs
end
class << self
def help_command
'me' # String name of command
end
def help(cmd)
# Some sort of help text.
%{This does whatever it is I want to do}
end
end
end
end
Now load that in after you load in ruby-debug:
require 'rubygems'
require 'ruby-debug'
require '/tmp/mycmd.rb' # or wherever
Debugger.start
x=1
debugger
y=2
### #
Now run:
ruby /tmp/testit.rb:
/tmp/testit.rb:7
y=2
(rdb:1) help
ruby-debug help v0.10.3
Type 'help <command-name>' for help on a specific command
Available commands:
backtrace delete enable help method putl set trace
break disable eval info next quit show undisplay
catch display exit irb p reload source up
condition down finish list pp restart step var
continue edit frame me ps save thread where
^^ This is you
(rdb:1) help me
This does whatever it is I want to do
(rdb:1) me
hi
(rdb:1)
Hopefully this is enough to get you started.
|
By: Steve V
Pause execution [ reply ] 2009-01-22 23:20
|
Is there any way to pause execution while the debugger is running? Not a breakpoint, but actually pause code execution mid swing through the debugger interface.
Thanks,
Steve
|
|
 |