无法从 C# 调试非托管 Dll
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1744888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot Debug Unmanaged Dll from C#
提问by QueueHammer
I have a DLL that was written in C++
and called from a C#
application. The DLL
is unmanaged code.
我有一个 DLL,它是C++
从C#
应用程序中编写和调用的。该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. The break point has a message attached to it saying that "no symbols have been loaded for this document".
如果我将带有构建后事件的文件DLL
及其.pdb
文件复制到C#
应用程序的调试执行中,dir
我仍然无法命中我放入DLL
代码中的任何断点。断点附有一条消息,说明“没有为此文档加载任何符号”。
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.
The DLL
is being compiled with "Runtime tracking and disable optimizations (/ASSEMBLYDEBUG)" and Generate Debug Info to "Yes (/DEBUG)"
我已禁用“ Tools
->-> Options
-> Debugging
-> General
->Enable
仅我的代码”。将DLL
被编译为“运行时跟踪和禁用优化(/ ASSEMBLYDEBUG)”,并生成调试信息为“Yes(/ DEBUG)”
采纳答案by JaredPar
To debug into your C++ DLL you need to enable mixed mode debugging on the startup application in your solution.
要调试到 C++ DLL,您需要在解决方案中的启动应用程序上启用混合模式调试。
- Right click on project -> Properties
- Go to Debug Tab
- Check "Enable unmanaged code debugging"
- 右键单击项目-> 属性
- 转到调试选项卡
- 勾选“启用非托管代码调试”
This will allow you to debug into native code for an F5 style scenario. If you want to enable it for attaching to the process then do the following in the "Attach to Process" Dialog
这将允许您调试到 F5 样式场景的本机代码。如果要启用它以附加到进程,请在“附加到进程”对话框中执行以下操作
- Select the process to debug
- Click on the "Select ..." button above the process list
- Click "Debug these code types"
- Check both Managed and Native
- 选择要调试的进程
- 单击进程列表上方的“选择...”按钮
- 点击“调试这些代码类型”
- 检查托管和本机
回答by Brian R. Bondy
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]
附加到:托管代码、本机代码 [选择]
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
启用非托管代码调试
回答by Joseph
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. 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# 代码,您必须将进程附加为托管和本机(两者都可以同时选择)。
回答by Martin
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
Select from Menu
>>Tools
>>options
>>Debugging
>>General
Uncheck "Require source files to exactly match the original version"
在解决方案资源管理器中选择解决方案
从Menu
>> Tools
>> options
>> Debugging
>>General
取消选中“要求源文件与原始版本完全匹配”