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

2

6

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?

Ami answered 21/12, 2012 at 0:55 Comment(1)
If it's a race condition or other multi-threading issue, the very slow execution by valgrind might well change the outcome. Do you use multithreading?Izy
K
8

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.

Kicker answered 7/1, 2013 at 14:31 Comment(0)
B
2

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.

Bergren answered 21/12, 2012 at 1:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.