Make valgrind stop immediately after first error

shuhalo picture shuhalo · May 12, 2011 · Viewed 9.9k times · Source

my program processes large errors and during development in produces large amount of output on the console. It suffers from memory corruption and I try to use valgrind to locate the error.

Unfortunately, i can't find the error messages among the output lines, and they flushing by too fast to cancel execution when they pop up. They have to be there in order to locate the error ( which element does cause the error and so on ). Redirecting then within my program doesn't work, just like piping the output does only redirect the program output, not the valgrind output.

Can you give me a hint how to solve this.

Answer

Employed Russian picture Employed Russian · May 16, 2011

In addition to redirecting both program and Valgrind output to a file (as already suggested), you can use --db-attach=yes flag, which will cause your program to stop in the debugger right at the error.

This has the advantage that in addition to looking at the log your program produced, you can also look at other program state (that you are not logging).