You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VS Code中同时调试GDScript与Rust编写的Godot扩展

同时调试Godot的GDScript与Rust GDNative扩展(VS Code)

问题背景

在Linux环境下开发Godot游戏,使用Rust编写GDNative扩展,希望在VS Code中一键启动游戏,同时对GDScript和Rust代码设置断点调试。当前核心问题:Godot会启动两个进程(VS Code Godot插件的编辑器进程、游戏运行进程),直接用复合调试时,LLDB需要游戏进程的PID,但启动时PID尚未生成,导致复合启动失败;分开启动两个调试器可行,但希望实现一键同时启动。

当前已有基础配置:

  • GDScript调试配置可正常启动游戏并调试
  • 借助shellCommand.execute插件和pgrep,可手动附加LLDB到游戏进程

解决方案:复合调试+循环等待进程检测

通过VS Code的**复合调试(compounds)**功能,结合循环等待的进程PID获取命令,实现一键启动两个调试器。

完整launch.json配置

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "GDScript Debug",
            "type": "godot",
            "request": "launch",
            "project": "${workspaceFolder}",
            "port": 6007,
            "address": "127.0.0.1",
            "launch_game_instance": true,
            "launch_scene": false
        },
        {
            "name": "Attach Rust Debug",
            "type": "lldb",
            "request": "attach",
            "pid": "${input:GodotGamePID}"
        }
    ],
    "compounds": [
        {
            "name": "GDScript + Rust Debug",
            "configurations": ["GDScript Debug", "Attach Rust Debug"],
            "stopAll": true
        }
    ],
    "inputs": [
        {
            "id": "GodotGamePID",
            "type": "command",
            "command": "shellCommand.execute",
            "args": {
                "command": "until pgrep --full 'godot.*remote-debug'; do sleep 1; done; pgrep --full 'godot.*remote-debug'",
                "description": "等待并获取Godot游戏进程的PID",
                "useFirstResult": true
            }
        }
    ]
}

配置说明

  1. 复合调试逻辑:

    • compounds中的GDScript + Rust Debug会按顺序启动GDScript调试器,再启动Rust附加调试器
    • stopAll: true确保停止调试时两个进程都会被终止
  2. PID获取优化:

    • 使用until pgrep ...; do sleep 1; done循环等待,直到游戏进程启动并匹配到godot.*remote-debug(GDScript调试启动的游戏进程会携带该参数,与编辑器进程区分)
    • 相比固定时长sleep,循环等待更可靠,避免因机器性能差异导致的PID获取失败
  3. 前置检查项:

    • 确保Rust GDNative扩展以Debug模式编译,否则LLDB无法识别调试符号
    • 已安装并启用VS Code的Godot Tools和CodeLLDB插件
    • 若pgrep匹配不准确,可通过ps aux | grep godot查看游戏进程的完整命令行,调整正则表达式

使用方法

在VS Code的调试面板中,选择GDScript + Rust Debug,点击启动按钮即可同时启动两个调试器,GDScript和Rust代码中的断点均可正常触发。

内容的提问来源于stack exchange,提问作者nathan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 12:40:13