6

セグメンテーション違反の原因を特定したいので、valgrind を使用してこれを実行しようとしています。

https://gist.github.com/4349869は、valgrind なしで何かを実行すると segfault が発生する Gist ですが、valgrind を使用すると segfault が発生しません。(何度か繰り返しましたが同じ結果でした)

これは、このバグが valgrind を使用すると発生しない heisenbug であり、したがって valgrind はここでは役に立たないということですか?

4

2 に答える 2

7

Does this mean that the bug is a heisenbug that won't occur when I use valgrind, and therefore valgrind isn't any use here?

No, you should still use Valgrind and fix all reported errors. The behavior you described is rather common and it is documented in Valgrind FAQ:

When a program runs under Valgrind, its environment is slightly different to when it runs natively. For example, the memory layout is different, and the way that threads are scheduled is different.

Most of the time this doesn't make any difference, but it can, particularly if your program is buggy. For example, if your program crashes because it erroneously accesses memory that is unaddressable, it's possible that this memory will not be unaddressable when run under Valgrind. Alternatively, if your program has data races, these may not manifest under Valgrind.

于 2013-01-07T14:31:34.757 に答える
2

デバッグ情報を使用してコンパイルした場合、または valgrind で実行しているときにメモリ配置が変更された場合、セグメンテーション違反が隠される可能性があります。もちろん、これは valgrind を使用してアプリケーションをデバッグできないという意味ではありません。無効な読み取り/書き込みエラーなど、valgrind が報告するすべてのエラーを修正する必要があります。これらのエラーを修正すると、セグメンテーション違反の問題が修正されます。

于 2012-12-21T01:03:24.247 に答える