[英]Cannot Debug Unmanaged Dll from C#
I have a DLL that was written in C++
and called from a C#
application. 我有一个用C++
编写并从C#
应用程序调用的DLL。 The DLL
is unmanaged code. DLL
是非托管代码。
If I copy the DLL
and its .pdb
files with a post build event to the C#
app's debug execution dir
I still can't hit any break points I put into the DLL
code. 如果我将带有post build事件的DLL
及其.pdb
文件复制到C#
app的调试执行dir
我仍然无法点击我放入DLL
代码的任何断点。 The break point has a message attached to it saying that "no symbols have been loaded for this document". 断点附有一条消息,称“没有为此文档加载符号”。
What else do I have to do to get the debugging in the dll
source? 还有什么办法可以在dll
源代码中进行调试?
I have " Tools
-> Options
-> Debugging
-> General
-> Enable
only my code" Disabled. 我有“ Tools
- > Options
- > Debugging
- > General
- >仅Enable
我的代码”已禁用。 The DLL
is being compiled with "Runtime tracking and disable optimizations (/ASSEMBLYDEBUG)" and Generate Debug Info to "Yes (/DEBUG)" DLL
正在使用“运行时跟踪和禁用优化(/ ASSEMBLYDEBUG)”编译,并生成调试信息为“是(/ DEBUG)”
To debug into your C++ DLL you need to enable mixed mode debugging on the startup application in your solution. 要调试C ++ DLL,您需要在解决方案中的启动应用程序上启用混合模式调试。
This will allow you to debug into native code for an F5 style scenario. 这将允许您调试F5样式场景的本机代码。 If you want to enable it for attaching to the process then do the following in the "Attach to Process" Dialog 如果要将其启用以附加到进程,请在“附加到进程”对话框中执行以下操作
You need to enable unmanaged (Native) debugging. 您需要启用非托管(本机)调试。
If you are attaching to the process after it is started: 如果您在启动后附加到该进程:
Go to the Tools menu, and then attach to process, make sure you have native debugging enabled. 转到“工具”菜单,然后附加到进程,确保已启用本机调试。
You will see a read only edit box: 您将看到一个只读编辑框:
Attach to: Managed code, Native code [Select] 附加到:托管代码,本机代码[Select]
Make sure Native code is listed there. 确保在那里列出本机代码。 If not add it. 如果没有添加它。
If you are starting your project from within visual studio: 如果您从visual studio中启动项目:
On your project properties that you are starting in debug mode. 在您以调试模式启动的项目属性上。 Go to the project Properties, and then select the debug tab. 转到项目“属性”,然后选择“调试”选项卡。
Make sure this checkbox is checked on: 确保选中此复选框:
Enable unmanaged code debugging 启用非托管代码调试
When you attach to a process to debug, you have to specify how you want to attach. 附加到要调试的进程时,必须指定要附加的方式。 You have a few options, namely Managed, and Native. 您有几个选项,即Managed和Native。 In order to debug C# code with unmanaged C++, you have to attach to a process as Managed and as Native (both can be selected at the same time). 为了使用非托管C ++调试C#代码,您必须将进程作为Managed和Native附加(两者都可以同时选择)。
Had faced the same issue and did all that was suggested in the accepted answer but the breakpoints in the unmanaged DLL was not getting hit! 面对同样的问题并完成了所接受的答案中提出的所有问题,但非托管DLL中的断点没有被击中!
However, when i did the following i could finally debug the DLL! 但是,当我做了以下我可以最终调试DLL!
Select solution in Solution Explorer 在Solution Explorer中选择解决方案
Select from Menu
>> Tools
>> options
>> Debugging
>> General
从Menu
>> Tools
>> options
>> Debugging
>> General
Uncheck " Require source files to exactly match the original version " 取消选中“ 要求源文件与原始版本完全匹配 ”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.