Debugging Linux Core Dumps with VisualGDB

This tutorial shows how to debug core dumps created by Linux systems when an application crashes. We will first create a program that causes SIGSEGV at a certain point in time, then run it without debugger to let it crash and produce a dump, and finally open the dump file with VisualGDB to analyze the crash.

Note that you don’t have to build an application with VisualGDB in order to debug its core dumps. If you already have a core dump, you can skip the steps 1-7.

Warning: the core debug functionality relies on the Quick Debug command and requires VisualGDB Custom Edition and higher.

  1. Follow this tutorial to create a simple ‘Hello, World’ application for Linux. We will use CrashDumpTest as the project name.
  2. Replace the contents of the main cpp file with the following:
  3. Build the project by selecting Solution->Build All:01-build
  4. Open a shell on your Linux computer. Before we can test debugging the core dumps, we need to ensure that they are enabled. Run the ‘ulimit -c‘ command. If the reply is not ‘unlimited’, the core dumps are disabled or limited. Run ‘ulimit -c unlimited‘ to enable creation of core dumps from the current shell session:02-ulimit
  5. Now we need to figure out the location where your Linux system will save the core dumps. Run the following command:
  6. If the output starts with a ‘|’, the core dumps will be redirected to the specified program instead of being saved to the disk. In that case you need to modify the core file pattern. E.g. to write core dumps to files called <binary name>_<PID>.core in the directory where the binary was launched, run the following commands:

    You can verify that the changes have been accepted by viewing the contents of core_pattern pseudofile:03-corepattern
  7. Now we will run our program and let it crash. Go to the directory containing the program binary and run it:04-dumpfileVerify that the dump file has been created by running the ‘ls’ command. In this tutorial we used the
    ‘%e_%p.core’
    pattern, so the core dump file is called ‘CrashDumpTest_9346.core’. If the file is missing, ensure that the ‘ulimit -c’ is set to ‘unlimited’ and double-check the core pattern setting.
  8. Now we will open the Linux core dump file with VisualGDB. In any Visual Studio window (your project does not have to be open) select Debug->Quick Debug with GDB:05-quickdebug
  9. In the Quick Debug dialog click at ‘Debug a Linux App’, select your Linux computer and specify program to debug (the main binary) and the core dump path (located in the same directory in this example). 06-debugsetings
  10. If you want to reopen this core file (or similarly named files) later, enable the ‘save preset’ checkbox and specify a name. You will be able to quickly load your previous settings next time you open the Quick Debug window by selecting the preset from the list above. Press ‘Debug’ when done.
  11. VisualGDB will start a debugging session you can hover the mouse over the variables to see their values, see the call stack, use memory, locals and watch windows:07-debug
  12. As the core dump represents the state of the program when it crashed, you cannot step or resume execution. Press Shift-F5 when done examining the core dump.