I'm getting segfaults when I run my project. Every time I run the program in gdb, the segfaults disappear. This behavior is not random: each time I run it in my shell it segfaults, each time I run it in gdb, the segfaults disappear. (I did recompile using -g).
So before I start adding printfs frantically everywhere in my code, I would like to know a few things:
- Is this behavior common?
- What's the best way to approach the issue?
I don't know if tests can be scripted since my application is interactive and crashes on a particular user input.
I didn't paste my code here because it'd be way too long. But if anyone is interested in helping out, here it is: https://github.com/rahmu/Agros
valgrindif that's available on your platform.-gbut not run within GDB?gcc -g -Wall -Werror'? If not, get your code to a point where you can. Consider adding '-Wextra' to that command line. Did you get a core dump? If not, re-enable them (ulimit -c unlimited) and at least get gdb to tell you where the crash occurs.-Wextra -pedanticas well as-Wall/-Wextra, it might pick something up. Failing that set yourself up to get a core dump (useulimit -c <size>if you dont get them by default - on ubuntu anyway) and load that in gdb withgdb myprogram mycore.