在 Visual Studio 2010 中调试所有事件而不设置断点

发布于 2024-09-28 10:51:18 字数 178 浏览 0 评论 0原文

我正在尝试调试一个具有大量事件的 Windows 窗体应用程序:按钮按下、计时器等。

有没有一种方法可以捕获应用程序正在执行的每一行代码而不设置断点?

编辑: 该程序不是我写的,所以我对代码不熟悉。我希望单步执行整个程序,捕获正在执行的每一行代码。在每个事件中设置断点是不切实际的,因为各种控件是动态创建的。

I am trying to debug a windows form application which has a large number of events: button presses, timers, etc..

Is there a way to catch every line of code being executed by the application without setting a break point?

edit:
The program was not written by me, so I am unfamiliar with the code. I wish to step through the entire program, catching every line of code being executed. Setting break points in every event is impractical as various controls are created dynamically.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

夏九 2024-10-05 10:51:18

要调试按钮,请单击而不设置断点:

  1. 使用调试器启动应用程序。
  2. 立即进入预期点击之前的状态。
  3. 返回到调试器并按“暂停”然后按 F11(步入)——什么也不会发生。
  4. 转到应用程序并按下按钮——调试器应该接管并将您放入事件处理程序中。

注意:如果处理了 Paint、任何鼠标事件或可能的其他一些事件,则这将不起作用。每当您尝试上述步骤时,调试器都会将您放入这些处理程序中。

For debugging a button click without setting breakpoints:

  1. Start the app with the debugger.
  2. Get to the state immediately before the intended click.
  3. Go back to the debugger and press Pause then F11 (Step Into) -- nothing will happen.
  4. Go to the app and press the button -- the debugger should take over and drop you into the event handler.

Note: This will not work if Paint, any Mouse event, or probably some other events are handled. The debugger will drop you into those handlers any time you attempt the steps above.

燕归巢 2024-10-05 10:51:18

如果您使用的是 Visual Studio 2010 旗舰版,则可以使用其名为 IntelliTrace(以前称为历史调试器)。这将使您能够准确地执行您想要的操作 - 能够查看程序执行期间发生的所有方法调用和事件,并且您将能够跳回到您需要的事件。

要启用 IntelliTrace,请转到工具 → 选项 → IntelliTrace,然后选中“启用 IntelliTrace”复选框,然后选择两种模式之一:“仅事件”或“事件和调用信息”,然后运行使用调试器 (F5) 的应用程序。

两种模式之间的区别在于,后者使用探查器来收集所有运行时信息,因此您可以获得完整的调用堆栈,但是您将无法使用调试器。

您可以在系列中找到更多信息文章,当然还有 MSDN 上的文章。

If you're using the Ultimate edition of your Visual Studio 2010 you can use its new feature called IntelliTrace (previously Historical Debugger). This will allow you to do exactly what you want - be able to see all method calls and events that happened during execution of your program, and you'll be able to jump back to the event which you need.

To enable IntelliTrace, go to Tools → Options → IntelliTrace, and check the "Enable IntelliTrace" checkbox, and select one of two modes: "events only" or "events and call information", then run your application with a debugger (F5).

The difference between the two modes is that the latter uses the profiler to collect all runtime information, so you get a complete call stack, however you won't be able to use edit-and-continue features of the debugger.

You can find more in this series of articles, and of course, on MSDN.

撩起发的微风 2024-10-05 10:51:18

您还可以尝试代码覆盖率工具。

例如,如果您有 ResharperdotCover,您可以运行您的应用程序(通过 dotCover->Cover Application... 菜单项),当应用程序完成时,dotCover 将显示哪些代码行通过以绿色突出显示它们在 VS IDE 中运行。未运行的代码行显示为红色。

我不知道是否有其他工具可以做到这一点,但这是一个选择。

You could also try a code coverage tool.

For example, if you have Resharper and dotCover, you can run your application (via the dotCover->Cover Application... menu item) and when the application finishes, dotCover will show you which lines of code were run in the VS IDE by highlighting them in green. Lines of code which where not run are coloured in red.

I don't know if there are other tools which do this, but it's an option.

九八野马 2024-10-05 10:51:18

我开发了 Runtime Flow 工具来解决这个问题 - 理解一个大的不熟悉的问题.NET 代码库通过实时函数调用监控。它与 IntelliTrace 类似,但更注重控制流而不是调试。

I developed the Runtime Flow tool to solve exactly this problem - to understand a large unfamiliar .NET codebase via realtime function calls monitoring. It's similar to IntelliTrace, but places more emphasis on control flow than on debugging.

多情出卖 2024-10-05 10:51:18

为什么你要在每一行都打断?这将是非常繁重和耗时的。如果您想在程序执行时查看程序的活动,请使用日志记录机制或 Debug.Writeline 将信息输出到“立即”窗口。

Why would you want to break on every line? This would be very onerous and time consuming. If you want to see the activity of your program as it executes, use a logging mechanism or Debug.Writeline to output information to the Immediate window.

信仰 2024-10-05 10:51:18

您无法跟踪代码行,但可以使用 Trace.TraceInformation 调用来了解执行的内容。还有Debug.Write。两个输出都将写入 Visual Studio 的输出窗口中。

另一个解决方案是向您的应用程序添加日志记录,例如使用 log4net,但这对于您的需求来说可能有点过头了。

You cannot trace lines of code, but you can use Trace.TraceInformation calls where you want to have an idea of what's executed. There's also Debug.Write. Both output will write in the output window of Visual Studio.

Another solution would be to add logging to your application, for example with log4net, but that may be overkill for your needs.

贪恋 2024-10-05 10:51:18

这并不完全是您所要求的,但如果您不知道,您可以打开或关闭现有断点。对于您的情况,您可以在整个代码的关键位置添加断点,并在您不想调试它们时禁用它们。这样,您以后想再次使用它们时就可以重新启用它们。

可以通过“调试”>“断点”窗口中的“断点”窗口来启用/禁用。窗口>断点菜单(CTRL+D、B)。您还可以在窗口中包含“函数”和“文件”列,这可能会帮助您确定哪些断点位于您关心的事件处理程序中

This isn't exactly what you're asking for, but in case you didn't know you can toggle an existing breakpoint on or off. In your case, you could add break points at key places throughout your code and just disable them when you don't want to debug them. That way, you'll be able to re-enable them later when you want to use them again.

Enabling/disabling is available through the Breakpoints window found under the Debug > Windows > Breakpoints menu (CTRL+D, B). You can also include "Function" and "File" columns in the window, which might help you identify which breakpoints are in the event handlers that you care about

浸婚纱 2024-10-05 10:51:18

并非如此,但您可以设置一个断点并单步执行 (F10/F11) 其余代码。

Not really, but you can set one breakpoint and single-step (F10/F11) through the rest of the code.

盛装女皇 2024-10-05 10:51:18

不,恐怕不是 - 您需要自己设置每个断点。

如果有帮助的话,F9 是分配断点的快捷键 - 只需在每个方法的开头设置一个断点,然后使用单步执行 (F10)/单步执行 (F11) 从那里开始。

Nope 'fraid not - you need to set each breakpoint yourself.

If it helps F9 is the shortcut key for assigning a breakpoint - just set a breakpoint on the start of each method and use step through (F10) / step into (F11) from there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文