16.2. How to View Core Dump Causes?

After a program crashes abnormally, how can I check the cause of the core dump?

16.2.1. Answer

After a program crashes abnormally, you can use the core dump file to check the specific error cause.

16.2.1.1. Core Dump File Path

Apollo’s core dump files are stored in the data/core directory. When the program crashes, the system generates a core dump file, usually named core or core.pid, where pid is the process ID.

16.2.1.2. Checking the Cause of the Core Dump

gdb (GNU Debugger) is a powerful tool for analyzing core dump files. You need to provide the executable that generated the core dump file and the core dump file itself. Here are the specific steps:

  1. Start gdb and load the executable file and core dump file:

    gdb <path-to-executable> <path-to-core-dump>
    

    For example:

    gdb ./my_program data/core/core.12345
    
  2. In gdb, view the stack information at the time of the crash:

    (gdb) bt
    

    The bt (backtrace) command will display the call stack at the time of the crash, which helps in locating the issue.

16.2.1.3. Example

Suppose the generated core dump file is core.12345, you can check it as follows:

$ gdb mainboard data/core/core.12345

At the gdb prompt:

(gdb) bt
# This will show the call stack
(gdb) info locals
# Display the local variables in the current frame
(gdb) print some_variable
# Print the value of the variable some_variable
(gdb) list
# Show the current line of code being executed
(gdb) list my_program.c:42
# View the code at line 42 of my_program.c

By following these steps, you can deeply analyze the reason for the program crash and perform corresponding debugging and fixes.