简体   繁体   English

无法调试 C# 中加载的 C++ dll

[英]Cannot debug C++ dll loaded in C#

I wanna debug a dll made in C++ while it is inside an executable built from C# with Release mode.我想调试在 C++ 中制作的 dll,而它位于从 C# 构建的可执行文件中,具有发布模式。 The C# app is supposed to not be aware. C# 应用程序应该不知道。 After I run the C# app I'm able to inject the dll manually which currently opens another window (so I know it was a success)在我运行 C# 应用程序后,我可以手动注入 dll,它目前打开另一个 window(所以我知道它是成功的)

I built the dll in Debug mode in VS2019.我在 VS2019 的调试模式下构建了 dll。 I go Debug > Attach to Process .我 go Debug > Attach to Process When I put a breakpoint it says me that it won't be hit as the symbols are not loaded.当我放一个断点时,它说我不会因为未加载符号而被击中。 After injecting they indeed are not hit.注射后他们确实没有被击中。 The dll does not appear in Debug > Windows > Modules dll 未出现在Debug > Windows > Modules

I tried the same tasks but this time with notepad.exe as target rather than my C# app.我尝试了相同的任务,但这次使用notepad.exe作为目标,而不是我的 C# 应用程序。 It worked flawlessly.它完美无缺。 I guess Notepad is built with C++ or C rather than C#我猜记事本是用 C++ 或 C 而不是 C# 构建的

Is it impossible to debug my injected C++ dll without touching the C# project?如果不触及 C# 项目,就无法调试我注入的 C++ dll 吗?

The dll does not appear in Debug > Windows > Modules dll 未出现在Debug > Windows > Modules

Look in the output window, it will tell you every library it's loading at run-time and whether or not it found symbols for it.查看 output window,它会告诉你它在运行时加载的每个库以及它是否找到了符号。

If it says symbols aren't there, make sure the .pdb file is in the same folder with the same name a the .dll , and try again.如果它说符号不存在,请确保.pdb文件位于与.dll同名的同一文件夹中,然后重试。

Also since you're debugging a.Net application, make sure you set your debugger to also debug native code (the C++ library), because by default the VS debugger will only attach the managed debugger to the application:此外,由于您正在调试 a.Net 应用程序,请确保将调试器设置为也调试本机代码(C++ 库),因为默认情况下 VS 调试器只会将托管调试器附加到应用程序: 在此处输入图像描述

As a last thing to check, make sure "Just My Code" debugging isn't selected in VS's options, since the library you want to debug isn't considered "my code" from the point of view of the.Net host application.最后要检查的是,确保在 VS 的选项中未选择“仅我的代码”调试,因为从 .Net 主机应用程序的角度来看,您要调试的库不被视为“我的代码”。

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

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