[英]Visual Studio Code: Attach to Unity process for debugging C++ based dll
I have a Unity project that uses some C++ code via a DLL compiled in a separate project.我有一个 Unity 项目,它通过在单独项目中编译的 DLL 使用一些 C++ 代码。 Can I attach the visual studio code debugger to my Unity project such that I can debug the DLL's source code using break points?
我可以将 Visual Studio 代码调试器附加到我的 Unity 项目,以便我可以使用断点调试 DLL 的源代码吗?
Here are some things I tried so far:以下是我到目前为止尝试过的一些事情:
launch.json
like thislaunch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to process",
"type":"clr",
"request": "attach",
"processId": "${command:pickProcess}"
}]
}
--> this should allow me to pick the process I want to connect to interactively --> 这应该允许我选择我想以交互方式连接的进程
my/path/to/Unity.exe
--> attaching seems to work, but when I "unpause" my Unity game it never hits a break point. my/path/to/Unity.exe
返回一个进程-> 附加似乎有效,但是当我“取消暂停”我的 Unity 游戏时它永远不会达到断点。 Is my launch.json wrong?我的launch.json错了吗?
Some additional info:一些附加信息:
sourceMap
which directs the debugger to the root of my source files.sourceMap
,它将调试器定向到我的源文件的根目录。 Not sure if anything similar would be needed here as well? Moving forward向前进
Meanwhile I've refactored my launch.json a bit.同时我重构了我的launch.json。 Thanks to a comment I assume
"type": "clr"
stand for Common Language Runtime which seems to be for debugging scripting languages but not C/C++.感谢评论,我假设
"type": "clr"
代表公共语言运行时,它似乎用于调试脚本语言而不是 C/C++。 So I changed it to "type":"cppdbg"
.所以我把它改成了
"type":"cppdbg"
。 After installing gdb via Msys2, I'm referencing the path to that gdb in the launch.json.通过 Msys2 安装 gdb 后,我在 launch.json 中引用了 gdb 的路径。 This is an updated version of my launch.json:
这是我的launch.json的更新版本:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to process",
"type":"cppdbg",
"request": "attach",
"processId": "${command:pickProcess}",
"program": "${workspaceRoot}/Packages/com.github.homuler.mediapipe/Runtime/Plugins/mediapipe_c.dll",
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
}]
}
Spoiler: It's still not working, but inside VS Code debug console / terminal I see some output when I start the game in Unity editor.剧透:它仍然无法正常工作,但在 VS Code 调试控制台/终端中,当我在 Unity 编辑器中启动游戏时,我看到了一些 output。 So there seems to be some traffic between VS Code and Unity at least.
因此,至少 VS Code 和 Unity 之间似乎存在一些流量。
One new problem:一个新问题:
While I couldn't figure out a solution for VS Code, I found a solution for虽然我无法找到 VS Code 的解决方案,但我找到了解决方案
the solution goes roughly like this解决方案大致是这样的
--> the game should now break when hitting the breakpoint --> 游戏现在应该在到达断点时中断
The C++ DLL library Project in VS be compiled debug first, also need add the /Zi parameter. VS中的C++ DLL库项目先编译调试,还需要添加/Zi参数。
Follow steps:遵循以下步骤:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.