表面问题是:rubymine可以运行ruby程序,但无法调试它们,也没有远程调试,我得到了:
>> DIALOG: Connecting to debugger using 10 seconds
经过一段时间约10秒
>> DIALOG: Cannot connect to the debugged process at port 57000 [a random port]
>>> Dumping and destroying...
>>> Error Output:
>>> Fast Debugger(ruby-debug-ide 0.4.17.beta14, ruby-debug-base19 0.11.30.pre10) listens on 127.0.0.1:57000
>> Please try increase timeout settings...(a long bullshit)
我尝试通过阅读ruby-debug-ide和ruby-debug-base19代码找到根本原因,发现:
run_prog_script
telnet 127.0.0.1 57000
,然后调试线程说:从127.0.0.1连接......
如果我在telnet中输入一个单词'start \ n',那么rdebug-ide将启动我的真实程序。我深入了解idea.log:
Fast Debugger (ruby-debug-ide 0.4.17.beta14, ruby-debug-base 0.11.30.pre10) listens on 127.0.0.1:59598
at org.rubyforge.debugcommons.RubyDebuggerProxy.a(RubyDebuggerProxy.java:647)
at org.rubyforge.debugcommons.RubyDebuggerProxy.d(RubyDebuggerProxy.java:619)
at org.rubyforge.debugcommons.RubyDebuggerProxy.getCommandSocket(RubyDebuggerProxy.java:381)
at org.rubyforge.debugcommons.RubyDebuggerProxy.b(RubyDebuggerProxy.java:151)
at org.rubyforge.debugcommons.RubyDebuggerProxy.attach(RubyDebuggerProxy.java:112)
at org.jetbrains.plugins.ruby.ruby.debugger.impl.RubyDebugProcess.attachToProxy(RubyDebugProcess.java:190)
然后我读了debug-commons代码(不像rubymine那样准确,我引用https://github.com/ruby-debug/debug-commons-java/blob/master/src/org/rubyforge/debugcommons/RubyDebuggerProxy.java
private Socket attach() throws RubyDebuggerException {
int port = debugTarget.getPort();
String host = debugTarget.getHost();
Socket socket = null;
for (int tryCount = (timeout*2), i = 0; i < tryCount && socket == null; i++) {
try {
socket = new Socket(host, port);
...
}
}
}
似乎rubymine无法使用debug-commons lib在localhost上打开套接字连接,我无法挖掘更多:(
BTW,即使我们在shell中通过以下命令启动ruby调试会话:
rdebug-ide --port 51202 - path / to / my / script
rubymine也无法连接到插座。
* 不要告诉我我应该使用另一个ruby-debug-xxx gem或删除一些其他宝石,如ruby-debug,我试过这些解决方案。 *
我试过以下小组:
组别1:
组2:
我的笔记本电脑是OSX Lion的mac air
答案 0 :(得分:2)
我有同样的问题。我尝试了所有的建议(删除ruby-debug,行缓存等),但没有一个工作。就我而言,我的macbook的主机名设置为localhost。我更改了我的主机名sudo scutil --set HostName newHostName
,现在它完美无缺。
答案 1 :(得分:0)
我应该使用远程调试器而不是本地调试。
首先,比较本地调试错误:
Error:
Cannot connect to the debugged process at port 57000 [a random port]
Dumping and destroying...
Error Output:
Fast Debugger(ruby-debug-ide 0.4.17.beta14, ruby-debug-base19 0.11.30.pre10) listens on 127.0.0.1:57000
Please try increase timeout settings...(a long bullshit)
使用debug-commons-java'代码:
private void failWithInfo(ConnectException e) throws RubyDebuggerException {
String info = debugTarget.isRemote()
? "[Remote Process at " + debugTarget.getHost() + ':' + debugTarget.getPort() + "]"
: Util.dumpAndDestroyProcess(debugTarget);
throw new RubyDebuggerException("Cannot connect to the debugged process at port "
+ debugTarget.getPort() + " in " + timeout + "s:\n\n" + info, e);
}
我在上面的错误输出中看不到任何debugTarget.getHost(),但如果我们远程调试它会告诉主机。
所以我写了一个最简单的ruby脚本(test.rb):
i = 10
begin
puts "echo ok #{i}"
i += 1
sleep 1
end until i > 600
然后在默认配置中在Ruby mine中启动远程调试会话:
我发现rubymine显示异常为:
Error:
Cannot connect to debugged process at port 54321 in 10s:
[Remote Process at **localhost**:54321]
然后我将远程主机更改为“127.0.0.1”,完成!
所以我猜Rubymine会尝试使用“localhost”作为主机名来连接调试目标,但它失败了!
我试图找到debugTarget的主机初始化的位置,我在调试公共RubyDebuggerFactory中获得了这些代码:
private static RubyDebuggerProxy startDebugger(final Descriptor desc, final List<String> args, final int timeout)
throws IOException, RubyDebuggerException {
...
// 127.0.0.1 seemingly works with all systems and with IPv6 as well.
// "localhost" and InetAddress.getLocalHost() have problems on some systems.
// cf. http://www.netbeans.org/issues/show_bug.cgi?id=143273 for one case
RubyDebugTarget target = new RubyDebugTarget(proxy, "127.0.0.1", desc.getPort(),
pb.start(), desc.getDebuggeePath(), desc.getBaseDirectory());
proxy.setDebugTarget(target);
RubyDebuggerProxy.PROXIES.add(proxy);
return proxy;
}
为org.rubyforge.debugcommons.RubyDebuggerFactory反编译rubymine.jar,虽然它是混合的,但我们可以找到:
RubyDebugTarget rubydebugtarget = new RubyDebugTarget(rubydebuggerproxy, "127.0.0.1", descriptor.getPort(), processbuilder.start(), descriptor.getDebuggeePath(), descriptor.getBaseDirectory());
我认为rubymine连接到127.0.0.1但未经许可,所以我尝试通过follow命令启动ruby mine:
sudo /Applications/Rubymine.app/Contents/MacOSX/rubymine
但它仍然失败,所以这是一个rubymine的错误,如果你有像我这样糟糕的经历,使用远程调试器来避免它。
感谢您提醒Dennis Ushakov
的计算机名称