The corefile shows an application's state when it terminated abnormally. STWorkbench can be used as a remote debugger to find out the state of the application when it terminated. When debugging a corefile, the following questions are raised:

  • At what point did the application fail and why?
  • How did the application get to that point?
  • Is the culprit thread the only one executing that function?
  • What were the variable and register values at the point of termination?

Create a project to dump a corefile

  1. Click File > New > Project.... The New Project window appears.

  2. Select C > C Project from the Wizards tree/list and click Next. The C Project dialog appears.

  3. Enter 'Crash' into the Project name text box

  4. Select Executable from the Project types list

  5. Select ST40 Linux GCC from the Toolchain list.

  6. Click Finish. If a confirmation appears, click Yes.

  7. Select File > Open File and navigate to the Crash folder. Click OK

  8. Click File > New > File. The New File window appears.

  9. Enter 'crash.c' into the File name text box and click Finish.

  10. ulimit limits the corefile dump size; the -c switch limits it to 120000.
    Edit /root/.bashrc (on the target) and change the last line from ulimit -c 120000 to ulimit -c unlimited.

  11. Copy the following into the editor.

    #include <stdio.h>
     
    int main(void)
    {
        int *ptr = 0;
        printf("About to crash and dump core\n");
        printf("This is a really bad idea... %d\n", *ptr);
        return 0;
    }

  12. Select File > Save.

  13. Select Project > Build Project. The application is built.

    If the console output is not displayed automatically, select HelloWorld from the STWorkbench Navigator window.

  14. Run the application to dump the corefile.

Debugging the application

  1. From the STWorkbench Navigator window, select Crash

  2. Click Run > Debug. The Create, manage, ans run configurations window appears.

  3. From the Configurations list, select STLinux Corefile and click New. A configuration called Crash is automatically created from the selected project, showing the Main tab.

  4. In the C/C++ Application field, click Browse to find crash.c.

  5. Select the Debugger tab.

  6. Check that ST40 Linux GDB Debugger is selected in the Debugger list.

  7. Enter the name or IP address of the target board into the Target name or IP address text box.

  8. Confirm the path to the corefile (/root/core).

  9. Click Debug and the debugger stops at the point at which the application terminated. If an alert is displayed to confirm a perspective switch, click Yes.

  10. Note the value of ptr in the Variables view.