Vanfanel wrote: ↑
Fri Mar 30, 2018 4:46 pm
@jamesh: I used GDB already to determine the locations where the Pi-only segfaults happen. How could Valgrind help here? I never used it, only GDB to do C programming.
valgrind takes the executable and executes each instruction one by one, checking absolutely everything as it goes.
It checks every single memory reference is valid, common library calls are correct, uninitialized memory is not being referenced, etc etc etc. It is normally very slow, for obvious reasons. An alternative are the sanitizers available with gcc and clang which are faster but not so thorough.
I suggest running your programs with valgrind on the x86 machine which is (a) faster, and (b) I find valgrind works better on x86.
Although your program crashes on the Pi, the cause of the problem may be visible on the x86 machine too its just that by chance, say, a memory corruption is not corrupting anything important on x86 but it is on the Pi. If it finds nothing on x86, then try valgrind on the Pi.
If you compile your program for debug, then any messages from valgrind will have source line numbers in, but you can just run valgrind on your plain release executable for a quick check if you want.
The advantage of valgrind is that it finds problems as they happen - at the root cause. GDB helps afterwards.
Your problem with free is common, but it could have been caused long ago - and valgrind might find when.
To use all the sanitizers:
Code: Select all
SAN = -fno-sanitize-recover=all \
Another thing you can do is to turn on every single warning flag in the compiler!
Code: Select all
WARN = -Wfatal-errors -Wall -Wextra -Wconversion -Wunused -Wundef -Wcast-qual \
-Wredundant-decls -Wunreachable-code -Wwrite-strings -Warray-bounds \
-Wstrict-aliasing=3 -Wstrict-overflow=1 -Wstrict-prototypes -Winline \
-Wshadow -Wswitch -Wmissing-include-dirs -Woverlength-strings -Wpacked \
-Wdisabled-optimization -Wmissing-prototypes -Wformat=2 -Winit-self \
-Wmissing-declarations -Wunused-parameter -Wlogical-op -Wuninitialized \
-Wnested-externs -Wpointer-arith -Wdouble-promotion -Wunused-macros \
-Wunused-function -Wunsafe-loop-optimizations -Wnull-dereference \
-Wduplicated-cond -Wshift-overflow=2 -Wnonnull -Wcast-align -Warray-bounds=2