我在使用Linux。我有一个使用GDNative扩展的游戏,我正在用Rust编写这个扩展,但是这个扩展叫做GDScript。我希望能够从Visual代码中启动游戏,并从同一个编辑器在Rust和GDScript中设置断点。
一个问题是戈多可执行文件多次运行,一次用于VSCode戈多插件,然后再次运行我的程序。
我试着用LLDB连接正在运行的进程。不幸的是,GDScript调试器和LLDB调试器的复合启动无法启动。这是因为LLDB需要用于godot的PID,但是复合启动拒绝启动Godot可执行文件,直到LLDB有了它的所有参数--包括进程的PID。可以单独启动两个调试器,但我想一起启动它们。
我的launch.json:
{
"name": "GDScript Debug",
"type": "godot",
"request": "launch",
"project": "${workspaceFolder}",
"port": 6007,
"address": "127.0.0.1",
"launch_game_instance": true,
"launch_scene": false
},
{
"name": "Rust Only Debug",
"type": "lldb",
"request": "launch",
"program": "/home/nathan/bin/godot",
"args": ["--position","3840,144", "res://Main.tscn"],
"cwd": "${workspaceFolder}"
}可以使用戈多编辑器进行调试,然后将LLDB附加到正在运行的进程中。通过使用Tasks输入扩展,我可以使用pgrep找到正确的PID。
"configurations": [
{
"name": "Attach Rust Debug",
"type": "lldb",
"request": "attach",
"pid": "${input:GodotNotEditingPID}"
}
],
"inputs": [
{
"id": "GodotNotEditingPID",
"type": "command",
"command": "shellCommand.execute",
"args": {
"command": "pgrep --full godot.\\*remote-debug",
"description": "Ignore the editor, select the program we're debugging",
"useFirstResult": true,
}
}
],如何从VS代码同时启动GDScript调试和GDNative调试?
发布于 2022-12-01 09:51:25
您的程序还可以使用调试信息调用Visual代码,以要求LLDB连接如前所述。这在Linux上用GDScript/Rust GDNative进行了测试,但也适用于GDExtensions & C++或C#。选项1应适用于任何Windows、MacOS或Linux。选项2更优雅,但它可能只适用于Linux和MacOS。
备选案文1
从GDNative二进制文件中添加一个回调
生锈:
#[cfg(debug_assertions)]
{
let url = format!("vscode://vadimcn.vscode-lldb/launch/config?{{'request':'attach','pid':{}}}", std::process::id());
std::process::Command::new("code").arg("--open-url").arg(url).output().unwrap();
std::thread::sleep_ms(1000); // Wait for debugger to attach
}C:
char command[256];
snprintf(command, sizeof(command), "code --open-url \"vscode://vadimcn.vscode-lldb/launch/config?{'request':'attach','pid':%d}\"", getpid());
system(command);
sleep(1); // Wait for debugger to attach选项2
对于Linux或MacOS,使用preLaunchTask启动一个后台任务,该任务使用pgrep查找正确的戈多进程并调用VS代码。虽然它被称为预启动,但它实际上只睡了几秒钟,等待Godot启动并获得它的进程ID。
将其添加到launch.json中:
// This waits a second and calls VS code to attach lldb
"preLaunchTask": "Attach LLDB Later"然后将其添加到tasks.json中:
{
"label": "Attach LLDB Later",
"type": "shell",
"command": "/bin/bash",
// Called from a preLaunchTask. First wait for it to start up.
// Then call VS code and tell it to attach with the LLDB debugger.
"args": ["-c", "echo Waiting for launch...;sleep 2; code --open-url \"vscode://vadimcn.vscode-lldb/launch/config?{\\\"request\\\":\\\"attach\\\",\\\"pid\\\":$(pgrep --full --newest godot.\\*remote-debug)}\";echo LLDB attached."],
"isBackground": true,
// All this is needed so VSCode doesn't complain about the background task.
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": ".",
}
}
]
},"pgrep -完全-最新的戈多。\*远程调试“将搜索正确的戈多进程。VSCode戈多插件也运行编辑器,但在完整的命令行中没有“远程调试”。通过使这成为一个背景任务,它解决了捕获-22。问题匹配器寻找任何输出,即使它只是说它在等待。
现在,我可以在同一个GDScript编辑器中在GDNative插件和VSCode插件中设置一个断点,这两个断点都可以工作。
https://stackoverflow.com/questions/74639913
复制相似问题