简体   繁体   English

如何将 Visual Studio 附加到 Unity 以调试本机 dll?

[英]How to attach Visual Studio to Unity in order to debug a native dll?

I have a native dll which is used by a project in Unity 2019.4.35f1.我有一个原生的 dll,它被 Unity 2019.4.35f1 中的一个项目使用。 Since the logic in the dll is complicated I would like to be able to debug it.由于 dll 中的逻辑很复杂,我希望能够调试它。

From the main answer here从这里的主要答案
https://answers.unity.com/questions/30620/how-to-debug-c-dll-code.html https://answers.unity.com/questions/30620/how-to-debug-c-dll-code.html
I was able to log debug from inside the dll.我能够从 dll 内部记录调试。

From the answer from this thread by Tomas1856, a Unity Technologies superuser, I get that the only way to really debug the native dll code line by line is to attach a debugger to the executable.从 Unity Technologies 超级用户 Tomas1856 的这个帖子的回答中,我了解到真正逐行调试本机 dll 代码的唯一方法是将调试器附加到可执行文件。
https://forum.unity.com/threads/how-to-step-into-a-native-c-dll-in-visual-studio.413387/ https://forum.unity.com/threads/how-to-step-into-a-native-c-dll-in-visual-studio.413387/

The problem is that I am not able to.问题是我做不到。 I have the dll Visual Studio 2019 project.我有 dll Visual Studio 2019 项目。 It is build in debug mode.它是在调试模式下构建的。 It's pdb file is here.它的 pdb 文件在这里。 I have tried changing many project settings from advices I have read on the inte.net including on stackoverflow.我已经尝试根据我在 inte.net 上阅读的建议更改许多项目设置,包括在 stackoverflow 上。 But still when I press the play button in Unity and press the Attach to Process in Visual Studio the breakpoints I have put in the dll code all turn white with an error message "The breakpoint will not be hit. No symbols have been loaded for this document".但是,当我在 Unity 中按下播放按钮并在 Visual Studio 中按下 Attach to Process 时,我在 dll 代码中放置的断点全部变成白色并显示错误消息“断点不会被击中。没有为此加载任何符号文档”。
I am attaching to the Unity.exe process.我附加到 Unity.exe 进程。 I have tried changing the output path for the dll and the pdb.我尝试更改 dll 和 pdb 的 output 路径。

I am pretty sure I am missing something obvious.我很确定我错过了一些明显的东西。
Can someone provide any guidance, please?有人可以提供任何指导吗?

After a month I have accidently found the reason.一个月后,我无意中找到了原因。 Error Pause was activated.错误暂停已激活。 I have logged an error so the Game has paused which makes it impossible to attach to the Unity process.我记录了一个错误,因此游戏已暂停,这使得无法附加到 Unity 进程。 I hope this helps anyone.我希望这对任何人都有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM