Sometimes running program in Unix will fail without any debugging info or warnings because of the laziness of programmer.. So if need to find the right place will the program stops and start debugging right from there, set the coredump file size to some desired size by first checking ..:
udump -a | grep core |
[[email protected] ~]# ulimit -a | grep core core file size (blocks, -c) 0 [[email protected] ~]# |
Use the following command to set the limit of coredump file size:
ulimit -c unlimited |
[[email protected] ~]# ulimit -c unlimited [[email protected] ~]# ulimit -a | grep core core file size (blocks, -c) unlimited [[email protected] ~]# |
Make sure the program is generated by gcc/g++ using flags of -O0 and -g. After running the program that will fail will generate the Core.[0-9]+ file after exit, this file contains the stack/mem/register infos.
use gdb to restore the environment when the bug appears and program exits:
gdb program core.[0-9]+ |
gdb will point to the line will the program exits, use bt to view the stack infos, use up to get to the upper entry of the stack. Easy to find the problem in the program we write.