简体   繁体   English

在应用程序运行时随时启动Visual Studio调试器

[英]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,因此它应该很简单:

  1. Run the application 运行应用程序
  2. Load the project in Visual Studio 在Visual Studio中加载项目
  3. Go to DEBUG -> Attach to process... 转到DEBUG- > Attach to process ...
  4. 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排序,则很有可能接近最高端)

  5. 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.

相关问题 使Visual Studio调试器目标正确应用程序 - Make Visual Studio Debugger Target Correct Application 在 Visual Studio 2019 调试器中运行时,为什么控制台应用程序在最后一条语句后不退出? - Why doesn't console application exit after last statement when running in Visual Studio 2019 debugger? 在Visual Studio中,可以在运行时编写代码或调试应用程序吗? - Is it possible in Visual Studio to write code or debug an application while it is running? 在visual studio中运行.Net 1.1应用程序时出错 - Error while running .Net 1.1 Application in visual studio 无法在Visual Studio Code上启动c#debugger - Can't start c# debugger on Visual Studio Code Visual Studio 2012随机调试器启动失败:无法启动程序 - Visual Studio 2012 random debugger startup failure: Unable to start program Visual Studio 2022 17.2 和 17.3 无法启动调试器 - Visual Studio 2022 17.2 and 17.3 cannot start debugger Visual Studio:部署后调试器无法启动应用 - visual studio: debugger doesn't start app after deploy Visual Studio错误:“调试器无法放松到此帧。”任何异常 - Visual Studio error: “The debugger cannot unwind to this frame.” on any exceptions 在Visual Studio 2013中的应用程序中运行应用程序? - Running an application within an application in Visual Studio 2013?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM