我怎样才能解决Heisenbugs [英] How can I solve a Heisenbugs

查看:143
本文介绍了我怎样才能解决Heisenbugs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个随机发生的错误。有时当我运行程序时,会发生错误,而不会发生错误。大多数情况下,10次中有9次不会发生错误。我在网上做过一些研究,我发现它是Heisenbugs。但是对于在大多数情况下不会发生的错误,无论我如何调试它都不会出现。我该如何解决海森堡?任何想法将不胜感激。谢谢。

Hi, I have a bugs that will happen at random. Sometime when I run the program, the bugs will occur and suometime it does not. Mostly 9 out of 10 times the bugs would not occur. I have done some research online and I have found out that it is Heisenbugs. But for a bugs that would not happen at most of the time, no matter how I debug it wont appear. How can I solve the Heisenbugs? Any idea would be appreciated. Thank you.

推荐答案

像任何类型的侦探工作一样,您需要先收集有关正在运行的系统的信息。



尝试添加异常日志记录以跟踪要调查的点数,例如:

https:/ /www.nuget.org/packages/log4net/ [ ^ ]

或我的文章: log4net的迷你插件替换 [ ^ ]
Like any kind of detective work you need to gather information about your running system first.

Try adding exception logging to track down the points to investigate more, like :
https://www.nuget.org/packages/log4net/[^]
or my article : Mini Drop-in Replacement for log4net[^]


1。维基 - http://en.wikipedia.org/wiki/Heisenbug [ ^ ]

1. Wiki - http://en.wikipedia.org/wiki/Heisenbug[^]
引用:

Heisenbugs通常通过非常仔细的调试来解决。如果能够识别出现错误的代码中的近似点,则效果最佳。从那里,可以通过检查附近的陈述或过程转储的分析来寻求解决方案。

Heisenbugs are usually resolved through very careful debugging. This works best if one is able to identify the approximate point in code where the bug is occurring. From there, solutions may be sought from inspection of nearby statements or analysis of process dumps.

另一种技术是检查日志,尤其是那些由 lint 和类似lint的工具。

Another technique is to examine logs, especially those produced by lint and lint-like tools.

对于高度持久的heisenbugs,它可能是必须使用静态分析技术分析程序的所有可能痕迹,例如抽象解释以确定其原因。

For highly persistent heisenbugs, it may be necessary to analyze all possible traces of the program using static analysis techniques such as abstract interpretation to determine their cause.



2. 反模式和最差实践 - Heisenbugs [ ^ ]


2. Anti-Patterns and Worst Practices – Heisenbugs[^]

引用:

正如我之前提到的,当试图检查对象的状态时会发生Heisenbug。存在并发问题时,这些类型的缺陷很常见。 Microsoft推出了一个库来帮助诊断这些问题: CHESS http://msdn.microsoft.com/en-us/devlabs/cc950526.aspx )。

As I mentioned before, a Heisenbug occurs when trying to check the state of an object. These types of defects are common with concurrency issues are present. Microsoft has put out a library to help diagnose these problems: CHESS (http://msdn.microsoft.com/en-us/devlabs/cc950526.aspx).



3. CHESS:在并发程序中查找并重现Heisenbugs [ ^ ]


我经历过处理中断,事件(类似于中断)和与时序相关的代码时的类似行为。例如。当你调试问题不存在时,因为你减慢了每一步。你也可以做而不是调试是使用打印命令,但这也可以减慢执行速度。另一种方法是添加变量并保存变量的某些状态或值,并仅在执行可疑问题代码​​之后检查它们(使用调试器或打印)。



调试工具也可以做一些时髦的东西......你可以在一个变量上添加一个断点,只有当它是某个值(有缺陷的值)时才会触发。退回,前进等。调试器的重要之处是在创建问题之前不妨碍执行。而是从那里开始并从那里回溯。



P.S.内存问题也可能会出现一些奇怪的错误。但我想用C#这不太可能。
I've experienced similar behaviour while working with interrupts, events (similar to interrupts) and timing related code. E.g. when you debug the issue is not there because you're slowing every step down. What you also can do instead of debugging is to use print commands, but this can also slow execution down. The other alternative is to add variables and save certain states or values of variables and only check them after the piece of suspect problem code has executed (using debugger or prints).

Debugging tools can also do some funky stuff... You can add a breakpoint on a variable to only trigger once it is a certain value (the faulty one). Step back, step forward, etc. Important with the debugger is to not hinder execution before the issue is created. Rather do it after and backtrack from there.

P.S. Memory issues can also present some strange looking bugs. But I guess with C# this is unlikely.


这篇关于我怎样才能解决Heisenbugs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆