首页 > 代码库 > Gdb+Coredump learning
Gdb+Coredump learning
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 |
[root@os-t1 ~]# ulimit -a | grep core core file size (blocks, -c) 0 [root@os-t1 ~]#
|
Use the following command to set the limit of coredump file size:
ulimit -c unlimited |
[root@os-t1 ~]# ulimit -c unlimited [root@os-t1 ~]# ulimit -a | grep core core file size (blocks, -c) unlimited [root@os-t1 ~]#
|
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.
Gdb+Coredump learning