如何在 Visual Studio 中无断点调试 C#?

发布于 2024-10-07 03:11:40 字数 163 浏览 1 评论 0原文

我无法找到导致给定副作用的语句。我在每个类成员中放置了一个断点,但仍然无法在罪魁祸首行上暂停执行。

  • 是否有一个调试器选项可以使执行在每一行暂停,而不管断点如何?

或者

  • 如何使每一行都成为断点,而无需手动标记它们?

I'm having trouble to find the statement that causes a given side-effect. I put a breakpoint in every class member and I still can't make the execution pause on the culprit line.

  • Is there a debugger option that makes the execution to pause at every line regardless of breakpoints?

or

  • How to make every line a breakpoint without the effort of marking them manually?

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

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

发布评论

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

评论(6

暮色兮凉城 2024-10-14 03:11:40

您可以暂停执行,然后开始逐行跟踪(例如按 F10)。这会给你带来与在每一行都中断完全相同的效果。

编辑:如果使用“trace into”(在默认设置中按 F11),则不必在每个方法中放置断点。然后调试器将停在被调用方法的第一行。

如果您在调试时遇到困难,也许在设置断点之前需要进行更多静态分析...您能描述一下您试图寻找的副作用吗?也许人们可以提供有关如何找到它或至少缩小搜索范围的建议。

编辑2:我认为您不会通过断点发现您所描述的副作用。当您加载签名的程序集时,CLR 会完成签名代码的验证。它必须访问网络才能更新撤销列表。

要解决此问题,您可以禁用 CRL 检查。以下是有关如何执行此操作的一些信息:
http://technet.microsoft.com/en-us/ library/cc738754(WS.10).aspx

当然,您应该意识到安全隐患(如果您正在运行的代码的证书真的被吊销了怎么办?)

You can pause execution, and then start tracing line by line (e.g. by pressing F10). This would give you the exact same effect of breaking at every line.

Edit: You won't have to put a breakpoint in each method is you use "trace into" (by pressing F11 in default settings). Then the debugger will stop in the first line of the method being called.

If you're having trouble debugging it, maybe before going for breakpoints some more static analysis is required... Can you describe the side effect you are trying to hunt down? Maybe then people can offer suggestions on how to find it or at least narrow the search.

Edit 2: I don't think you will find the side effect you described through a breakpoint. The verification of signed code is done by the CLR when you load a signed assembly. It has to access the network in order to update revocation lists.

To workaround this problem you can disable CRL checking. Here's some info on how to do it:
http://technet.microsoft.com/en-us/library/cc738754(WS.10).aspx

Of course, you should be aware of the security implications (what if the certificate for the code you are running really was revoked?)

枕花眠 2024-10-14 03:11:40

在执行的代码的第一行放置一个断点(例如,如果您是控制台应用程序,则在 main 函数的第一行)。然后只需使用单步命令(默认情况下为 F10 和 F11)即可逐步执行。

Put a breakpoint on the first line of your code that gets executed (e.g. the first line of your main function, if you're a console application). Then just use the single-step commands (F10 and F11, by default) to walk through the execution.

还给你自由 2024-10-14 03:11:40

这很简单,但前提是您知道发生了什么。这是该怎么做。

  1. 在打开项目的 Visual Studio 中,按住 ctrl-alt-E 加载“异常”对话框。
    这为您提供了何时中断的选择。您将选择“公共语言运行时异常”抛出列。
  2. 现在继续运行您的应用程序。现在,抛出的任何 CLR 异常都会将您带到损坏的代码行。

完成后不要忘记按 ctrl-alt-E 并取消选中!

屏幕截图!

This one is pretty easy but only if you know what is going on. Here is what to do.

  1. In Visual Studio with your project open hold ctrl-alt-E to load the Exceptions dialog.
    This gives you options for when to break. You will select "Common Language Runtime Exceptions" Thrown column.
  2. Now go ahead and run your application. Now any CLR exceptions that are thrown will take you to the line of code that broke.

Don't forget to ctrl-alt-E and uncheck when your done!

screenshot here!

财迷小姐 2024-10-14 03:11:40

最简单的方法是使用调试器内置的 Break All 功能。它并不适用于所有情况,但如果它适用于您的情况,那么使用起来就非常简单。调试>>全部中断(或 CTRL + ALT + Break

请参阅本页标题为“使用断点或全部中断来中断代码”的部分详细信息:在 Visual Studio 中开始、中断、单步执行、运行代码和停止调试

The simplest way is to use the built in Break All feature of the debugger. It doesn't apply to every situation, but if it applies to yours, then it's very simple to use. Debug >> Break All (or CTRL + ALT + Break)

See the section titled "Break into code by using breakpoints or Break All" on this page for more information: Start, Break, Step, Run through Code, and Stop Debugging in Visual Studio

穿越时光隧道 2024-10-14 03:11:40

您可以尝试使用 F10 跳过代码,直到遇到问题为止,它会产生相同的结果。

You could try just stepping over the code with F10 until you hit the problem, it would have the same outcome.

〆凄凉。 2024-10-14 03:11:40

我不确定我是否理解你的问题。
您可以使用一个断点,然后按 F10(步过)或 F11(步入)进入下一条指令。这与每行都有一个断点并在每次断点后按 F5(继续)相同。
或者,您可以在罪魁祸首行设置断点并调查调用堆栈窗口以查看到该点的控制流。

I'm not sure if I understand your problem.
You can use one breakpoint and then hit F10 (Step over) or F11 (Step into) to go the next instruction. That would be the same as having a breakpoint on every line and hitting F5 (continue) after each break.
Or you can set a breakpoint at the culprit line and investigate the callstack window to see the control flow up to that point.

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