I'm trying to debug a segfault in my C program. I added a few printf()
, but it generates a lot of text, so I tried to redirect the output:
./a.out > log
It didn't work, it printed Segmentation fault (core dumped)
in the terminal and didn't print anything to the log file.
Is there some way to fix this?
CodePudding user response:
fflush(stdout)
will force output to be written.
The much more powerful approach is to ensure your program is compiled with debugging information (gcc -g3
) then use a debugger gdb ./a.out core
. bt
will now tell you were your program crashed.
You can often use strace
, ltrace
, eBPF (Linux) or similar tracing utilities to learn something useful.