Note that there are some explanatory texts on larger screens.

plurals
  1. POProgram terminates early with valgrind memcheck
    primarykey
    data
    text
    <p>I have a C-programm (a lot of numerics and too long to post) which I compile with </p> <pre><code>gcc -g -O0 program.c -o program </code></pre> <p>I am trying to debug it using gdb and valgrind memcheck. After some changes on the code I found that </p> <pre><code>valgrind --tool=memcheck --log-file=output.log ./program </code></pre> <p>gives</p> <pre><code>==15866== Memcheck, a memory error detector ==15866== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. ==15866== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==15866== Command: ./program ==15866== Parent PID: 3362 ==15866== ==15866== Warning: client switching stacks? SP change: 0xbe88bcd8 --&gt; 0xbe4e1f70 ==15866== to suppress, use: --max-stackframe=3841384 or greater ==15866== Invalid write of size 4 ==15866== at 0x804B7BE: main (program.c:1396) ==15866== Address 0xbe4e1f74 is on thread 1's stack ==15866== ==15866== Invalid write of size 4 ==15866== at 0x804B7C2: main (program.c:1396) ==15866== Address 0xbe4e1f70 is on thread 1's stack ==15866== ==15866== Invalid read of size 4 ==15866== at 0x4320011: on_exit (on_exit.c:34) ==15866== by 0x43064D2: (below main) (libc-start.c:226) ==15866== Address 0xbe4e1f70 is on thread 1's stack ==15866== ==15866== Invalid read of size 4 ==15866== at 0x4320022: on_exit (on_exit.c:37) ==15866== by 0x43064D2: (below main) (libc-start.c:226) ==15866== Address 0xbe4e1f74 is on thread 1's stack </code></pre> <p>and many more of this kind. </p> <pre><code>valgrind --tool=memcheck --max-stackframe=3841384 --log-file=output.log ./program </code></pre> <p>does not print any errors. But what puzzles me is that with both valgrind calls the program exits early (without error messages) and does not do the computation it is supposed to do. The behaviour with same compiler options but run without valgrind is entirely different and looks pretty normal. I suspect a memory error however and want to use valgrind to find it. My question therefore: What kind of error can make a program bahave so differently when executed with valgrind? And if these are memory related errors how can I identify it? Note that it is clear to me that I can "debug by hand" to locate it. But can I maybe run gdb with valgrind to see where it exits.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload