[英]Start Visual Studio Debugger at any time while application is running
I am developing an application using Visual Studio, and when I install it (via Setup Project, .msi file) in a client machine and run it, I get some "Heisenbug" exception. 我正在使用Visual Studio开发应用程序,当我在客户端计算机上安装它(通过Setup Project,.msi文件)并运行它时,出现“ Heisenbug”异常。 I am almost sure the error comes from earlier in the codepath, so I would like to debug it. 我几乎可以肯定该错误来自早期的代码路径,因此我想对其进行调试。
Fact is: when the application crashes, the following dialog is displayed (referring to my application instead of Windows Explorer, of course): 事实是:当应用程序崩溃时,将显示以下对话框(当然,是指我的应用程序而不是Windows资源管理器):
and if I choose "Debug the program", the Visual Studio Debugger (which is somehow available in the deployed machine) starts and shows details from the exception. 如果选择“调试程序”,则会启动Visual Studio调试器(在部署的计算机中以某种方式可用),并显示该异常的详细信息。
What I would like to do is to start the debugging session from the very start , so I can go on hitting F10 and F11 and check some intermediate values. 我想这样做是开始从一开始调试会话,这样我就可以继续打F10和F11和检查一些中间值。
Anyone know how can I start the Visual Studio debugging session at any time while the application is running? 有人知道如何在应用程序运行时随时启动Visual Studio调试会话吗? Not that I am running the deployed application, not starting it from Visual Studio. 不是说我正在运行部署的应用程序,不是从Visual Studio启动它。
Since you have Visual Studio up and running on the machine running the deployed application, it should be straightforward: 由于已经在运行已部署应用程序的计算机上启动并运行了Visual Studio,因此它应该很简单:
A list will pop up with all the running processes 将弹出所有正在运行的进程的列表
From the list, pick the process corresponding to the application, it should be named after your exe (if you sort by the numeric IDs, it's very likely it will be near the highest end) 从列表中选择与应用程序相对应的进程,它应以您的exe文件命名(如果按数字ID排序,则很有可能接近最高端)
Click "Attach", Visual Studio will should start debugging similarly as when you normally start with F5 . 单击“附加”,Visual Studio将应该像通常从F5开始时一样开始调试。
I also have another suggestion: implement heavy logging until you have everything figured out. 我还有一个建议:实施繁重的日志记录,直到一切都明白了。 Write down everything you have doubts about for further analysis in case something goes wrong: values, queries, etc. 写下您有疑问的所有内容,以防万一出现问题:值,查询等。
You can start the application directly under the Visual Studio Debugger using the debugexe
parameter : 您可以使用debugexe
参数直接在Visual Studio调试器下启动应用程序 :
devenv /debugexe “C:\\MyApplication\\Debug\\MyApplication.exe” devenv / debugexe“ C:\\ MyApplication \\ Debug \\ MyApplication.exe”
This will launch the application with the debugger immediately attached. 这将立即连接调试器启动应用程序。 Otherwise it's very hard to debug issues that happen at the time the application is starting. 否则,很难调试在应用程序启动时发生的问题。 You won't be able to manually attach in time to catch any events that happen during this time. 您将无法及时手动附加以捕获这段时间内发生的任何事件。
You can also place the following piece of code at the first line of you application (usually the Main(string[] args)) to force a debugger to attach and cause the application to break immediately : 您还可以将以下代码放在应用程序的第一行(通常是Main(string [] args)),以强制调试器附加并导致应用程序立即中断 :
System.Diagnostics.Debugger.Break();
If your application starts and runs fine for some time, you can use the "Attach to Program" feature as described by @Alex. 如果您的应用程序启动并且可以正常运行一段时间,则可以使用@Alex描述的“附加到程序”功能。
If you don't have the sources available on the target machine, you can either copy them over, or if you're using Source and Symbol Indexing features of TFS Team Build, you can tell the debugger where to look for your Debug Symbols (which will then resolve to TFS source control automatically). 如果目标计算机上没有可用的源,则可以将其复制过来,或者如果您使用的是TFS Team Build的源和符号索引功能,则可以告诉调试器在哪里寻找调试符号(然后将自动解析为TFS源代码管理)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.