Gdb+Coredump learning
Posted 三叁
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 |
[[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.
以上是关于Gdb+Coredump learning的主要内容,如果未能解决你的问题,请参考以下文章