简体   繁体   English

调试由Visual Studio 2015中的本机应用程序加载的托管DLL

[英]Debug a Managed DLL loaded by Native Application in Visual Studio 2015

I am working with a particular Application that supports "extensions" as Managed C# DLL's. 我正在使用支持“扩展名”作为托管C#DLL的特定应用程序。 The Application itself is a Native Application, and I do not have the source code for it. 该应用程序本身是一个本机应用程序,我没有它的源代码。

I am able to get the Application to load the DLL, and I can verify that my functions are being called. 我能够使该应用程序加载DLL,并且可以验证是否正在调用我的函数。 What I would like is to be able to Debug my extension code in the DLL when it runs. 我想要的是能够在DLL运行时调试我的扩展代码。 I can attach to the Process of the Native Application using Visual Studio, however, I am not able to set any breakpoints as I get the "No symbols have been loaded..." error. 我可以使用Visual Studio附加到本机应用程序的进程,但是,由于出现“未加载符号...”错误,因此无法设置任何断点。 The PDB file is present next to the DLL. PDB文件位于DLL旁边。

It seems to me that the Visual Studio Debugger is not recognizing my Managed C# code, even though the DLL is clearly being used. 在我看来,即使明显使用了DLL,Visual Studio调试器也无法识别我的托管C#代码。 For example, if I browse through the "Modules" View, I cannot see my DLL in the list. 例如,如果浏览“模块”视图,则无法在列表中看到我的DLL。

Reading through some Visual Studio support pages, it sounds like there is a "Mixed Mode" that I would typically enable on the Project of the running Application. 通读一些Visual Studio支持页面,听起来好像我通常在正在运行的应用程序的项目中启用“混合模式”。 However, since I am not actually building the Application, I cannot change this setting. 但是,由于我实际上不是在构建应用程序,因此无法更改此设置。

Does anybody know if there is another way to achieve this? 有人知道是否还有另一种方法可以实现这一目标吗?

Visual studio will have your DLL in the list, if it's loaded, and the program is using a normal .net runtime. 如果已加载,Visual Studio将在列表中包含您的DLL,并且程序使用的是正常的.net运行时。 If it's using something doctored or mono for instance then it may not be there. 例如,如果使用的是经过篡改或单声道的东西,则可能不存在。

I don't think your not having the source to the unmanaged program is the problem here. 我不认为您没有非托管程序的源代码就是这里的问题。 "Mixed mode" is not something you set on the project. “混合模式”不是您在项目上设置的。 It's something you set for VS to know what debugging mode to use when starting the project from VS. 您为VS设置了一些信息,以了解从VS启动项目时要使用的调试模式。 You can choose even more options when attaching to a process, and that's what's important for you here. 在附加到流程时,您可以选择更多选项,这对您来说很重要。

I used this project to test the theory: https://code.msdn.microsoft.com/windowsdesktop/CppHostCLR-e6581ee0 我使用此项目测试了理论: https : //code.msdn.microsoft.com/windowsdesktop/CppHostCLR-e6581ee0

I built release mode and deleted the PDB and was able to hit a breakpoint in the CSClassLibrary (at static int GetStringLength ) using VS2015 by manually selecting the debugger type when attaching to the process. 我建立了发布模式并删除了PDB,并通过在连接到进程时手动选择调试器类型,使用VS2015能够在CSClassLibrary( static int GetStringLength )上达到断点。

If you let it automatically choose, and youre having a timing problem (attach vs .net startup vs dll load), then .net may not be started up when you're attaching, and it wouldn't know to attach with the .net debugger enabled. 如果您让它自动选择,并且您遇到计时问题(附加vs.net启动vs dll加载),则附加时.net可能无法启动,并且不知道附加.net调试器已启用。 So specifying it manually should help. 因此,手动指定它会有所帮助。

Furthermore, a standard trick when solving debugging timing problems is to put System.Diagnostics.Debugger.Break() in your c# code--that will make sure you get a chance to attach a visual studio right at that moment when you're sure your c# code is running in the (hopefully normal) .net runtime. 此外,解决调试时序问题时的标准技巧是将System.Diagnostics.Debugger.Break()放入您的C#代码中-这将确保您有机会在确定的那一刻附加视觉工作室您的C#代码正在(希望正常).net运行时中运行。

Visual Studio will show that error when your DLL has not been loaded by the process you attached to. 当您附加的进程尚未加载DLL时,Visual Studio将显示该错误。 Just ignore the error and set the breakpoints as usual. 只需忽略该错误并照常设置断点即可。 When the native application loads your DLL into memory, the breakpoint icons should turn red and work as expected. 当本机应用程序将您的DLL加载到内存中时,断点图标应变为红色并按预期工作。

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

相关问题 如果使用Visual Studio 2015预先加载了DLL,我如何调试 - How can I debug dll if loaded in advance using visual studio 2015 如何添加affdex-native.dll作为对Visual Studio 2015的引用? - How to add affdex-native.dll as a reference to Visual Studio 2015? Visual Studio 2015 Debug在多线程应用程序中不起作用 - Visual Studio 2015 Debug doesn't work in multithread application 模块下缺少 .dll,导致“未加载符号”错误。 C# Visual Studio 2015 - Missing .dll under Modules, causing a "no symbols loaded" error. C# Visual Studio 2015 如何从 Visual Studio.NET 或 Visual Studio 2005 中的本机 Visual C++ 代码调用托管 DLL - How to call a managed DLL from native Visual C++ code in Visual Studio.NET or in Visual Studio 2005 在Visual Studio 2010中将本机/ C ++ DLL链接到托管C ++ / CLI包装器 - Linking Native/C++ DLL to Managed C++/CLI Wrapper in Visual Studio 2010 没有版本Visual Studio 2015的参考DLL - Reference dll without version visual studio 2015 未在Visual Studio 2015中加载BuildTasks.csc - BuildTasks.csc not loaded in Visual Studio 2015 Visual Studio 2015,Resharper冻结调试UnitTests - Visual Studio 2015, Resharper freezing on debug UnitTests Visual Studio 2015调试和发布无法正常工作 - Visual Studio 2015 Debug and Release not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM