我在 Mac Big Sur 上使用 VSCode 1.61.1 和 Rails 4.2 应用程序(ruby-debug-ide 0.7.3,debase 0.2.2.beta10),与 Unicorn 应用程序服务器一起运行。Rails 应用程序在虚拟服务器上运行(通过 Vagrant 构建)。我已经暴露了所有必要的端口。我在我的 launch.json 中配置了这个
"configurations": [
{
"name": "Listen for rdebug-ide",
"type": "Ruby",
"request": "attach",
"cwd": "${workspaceRoot}",
"remoteHost": "127.0.0.1",
"remotePort": "1234",
"remoteWorkspaceRoot": "/home/my-app",
"showDebuggerOutput": true
},
然后在我的虚拟服务器中,我使用
rdebug-ide --debug --host 0.0.0.0 --port 1234 -- bin/rails s -p 3000 -b 0.0.0.0
从 VS Code 中,然后我通过单击附加调试器
在我的 Rails 服务器上,我可以看到这个调试输出
15:08:31 rails.1 | Connected from local client
15:08:31 rails.1 | 5360: Starting control thread
15:08:31 rails.1 | 5360: Processing in control: start
15:08:31 rails.1 | 5360: Starting: running program script
15:08:31 rails.1 | 5360: Processing in control: thread list
15:08:31 rails.1 | 5360: <threads>
15:08:31 rails.1 | 5360: <thread id="1" status="sleep" pid="5360" />
15:08:31 rails.1 | 5360: </threads>
15:08:39 rails.1 | => Booting Unicorn
15:08:39 rails.1 | => Rails 4.2.10 application starting in development on http://0.0.0.0:3000
15:08:39 rails.1 | => Run `rails server -h` for more startup options
15:08:39 rails.1 | => Ctrl-C to shutdown server
15:08:39 rails.1 | W, [2021-10-18T15:08:39.643324 #5360] WARN -- ddtrace: [ddtrace] Unable to patch Datadog::Contrib::Faraday::Integration (Available?: true, Loaded? true, Compatible? false, Patchable? false)
15:08:41 rails.1 | I, [2021-10-18T15:08:41.538531 #5360] INFO -- : unlinking existing socket=/home/my-app/tmp/sockets/unicorn.sock
15:08:41 rails.1 | I, [2021-10-18T15:08:41.538665 #5360] INFO -- : listening on addr=/home/my-app/tmp/sockets/unicorn.sock fd=14
15:08:41 rails.1 | I, [2021-10-18T15:08:41.538782 #5360] INFO -- : listening on addr=0.0.0.0:3000 fd=15
15:08:41 rails.1 | Disconnected from Redis
15:08:41 rails.1 | I, [2021-10-18T15:08:41.544540 #5360] INFO -- : master process ready
15:08:41 rails.1 | Connected to Redis
15:08:41 rails.1 | I, [2021-10-18T15:08:41.551381 #6487] INFO -- : worker=0 ready
然后从 VSCode,当我添加断点时,我在我的 Rails 应用程序上看到了这个输出
15:09:16 rails.1 | 5360: Processing in control: break /home/my-app/app/controllers/api/v1/products_controller.rb:10
15:09:16 rails.1 | 5360: <breakpointAdded no="1" location="/home/my-app/app/controllers/api/v1/products_controller.rb:10"/>
但是当我真正访问应该达到断点的网页时,什么也没有发生。我现在调用代码是因为我看到“打印”语句输出到日志。但不确定我还需要做什么才能让 VSCode 的调试器在适当的断点处进行操作。