Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is valgrind preventing a segfault I want to debug from occurring? [closed]

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?

like image 684
Andrew Grimm Avatar asked Dec 21 '12 00:12

Andrew Grimm


2 Answers

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.

like image 100
ks1322 Avatar answered Sep 28 '22 07:09

ks1322


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.

like image 27
perreal Avatar answered Sep 28 '22 08:09

perreal