我希望在按下ctrl-C(或发送SIGINT)时进入调试器。我已经安装了调试器(我正在运行Ruby 1.9.3),并验证了它的工作。我已将此添加到我的设置文件中(这是为Padrino准备的,但我认为Rails也类似):
# file: config/boot.rb
Padrino.before_load do
trap("SIGINT") { debugger } if Padrino.env == :development
end
...但是按下Ctrl-C并不会调用调试器。事实上,如果我将debugger
替换为puts "saw an interrupt!"
,按下Ctrl-C也不会发生打印。
更新
根据Mike Dunlavey的建议,我尝试在调试器中显式调用catch Interrupt
:
$ rdebug `which padrino` console
^Z^Z$HOME/usr/bin/padrino:9
require 'rubygems'
(rdb:1) catch Interrupt
Catch exception Interrupt.
(rdb:1) c
=> Loading development console (Padrino v.0.10.7)
=> Loading Application BlueDotAe
=> Loading Application Admin
irb(main):001:0> C-c C-c^C
irb(main):001:0>
没有进入调试器 -- 中断未产生任何结果。
我错过了什么?
SIGINT
时的代码执行点进入调用堆栈? - Matt Sanders