Question

I want to determine what's causing a segfault, and I'm trying to use valgrind to do this.

https://gist.github.com/4349869 is a gist where I'm getting a segfault when I run something without valgrind, but I don't get a segfault when I use valgrind. (I've repeated this several times, with the same result)

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?

Was it helpful?

Solution

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.

OTHER TIPS

It is possible that the segmentation fault is hidden when compiled with debugging information or when memory placement is changed when running under valgrind. Of course this doesn't mean you cannot use valgrind to debug your application. You should fix all errors that valgrind reports such as invalid read/write errors. Fixing these errors should fix your segmentation fault problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top