Visual Studio Code (VS) supports memory dump debugging via C/C++ extension: https://code.visualstudio.com/docs/cpp/cpp-debug#_memory-dump-debugging. When MySQL generates a core file, the VS code simplifies the process of debugging. This blog will discuss how to debug the core file in VS code.

Installing c/c++ extension

We need to install the c/c++ extension. Here are the instructions for doing so. In Linux, you can press control-p, paste the command below, and then press enter.

Once we install the c/c++ extension, we can find it in extensions.

install c/c++ extension

Finding the binary file of MySQL

To open the core file, the GDB requires the binary file of MySQL. You can use the shell command below to find the path of the default MySQL file.

If the core file is generated by another MySQL, you should find the binary file of the MySQL.

Installing debug info

Because the release version of the MySQL package does not include symbol files, we need to install the debug info package. We can find packages at https://dev.mysql.com/downloads/mysql. You should download and install the debug info package based on the MySQL version, for example, version 8.0.34.

Downloading the source code

You can download the source code from GitHub. The shell command below will download the source code of MySQL version 8.0.34.

We can open the source code folder by clicking on the file in the menu bar and then selecting the open folder item.

Creating launch.json file

We need to create the launch.json file under the .vscode directory.

  • program is the path of the command mysqld
  • coreDumpPath is the path of the core file

Debugging the core file

In this step, we can click on the “Run and Debug icon” in the Activity Bar to enter the run view and then click on the green triangle play button to start the debugging.

Once the debug process starts, we can find the debug toolbar at the top center and threading information on the CALL STACK view.

Because the thread [9760] is paused on expectation, we can click on it on the CALL STACK to inspect the thread.


After we click on the “Show 21 More Stack Frames”, we can see the frame
row_sel_field_store_in_mysql_format_func below the frame <signal handler called>. You may see a message below in the editor when we click the frame.

The message may be different depending on your MySQL version.

This is because we have not yet mapped the compile-time path to the source code path.

Mapping source code

We can stop the debugging by clicking the red square stop button in the debug toolbar. In the launch.json file, the sourceFileMap will help us to map the path.

The new configuration will be:

Exploring the core file

After we mapped the source file, we can run the core file again. This time, the VS code will point to the location of the MySQL crash.

Conclusion

The C/C++ extension in Visual Studio Code helps us to investigate the crash issue in a modern IDE.

Percona Distribution for MySQL is the most complete, stable, scalable, and secure open source MySQL solution available, delivering enterprise-grade database environments for your most critical business applications… and it’s free to use!

 

Try Percona Distribution for MySQL today!

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments