Wednesday, November 10, 2010

Crash, core dump and gdb


When a linux program crashes, a core file could be generated under the directory where you ran the file. A core file contains very useful information to help you debug the program. If there is no such a file named core.XXXX, it may be that the parameter of the maximum size of core files is set as 0. Check it with this command:

    $ ulimit -c

If the result is 0, set a size for it, e.g.

    $ ulimit -c 100000

If the core file is generated, you can run gdb to exam the core file and see why and where the crash happened.

    $ gdb /path/to/your/program core.XXXX

If your source code is somewhere else, include the location of the source code in the gdb command line.

    $ gdb -d /path/to/source-code /path/to/program core.XXXX

It brings you to the crash location in your source code. If you want to see a back trace, run the gdb command bt.

    (gdb) bt

No comments:

 
Get This <