Oct
13
2023
--

Debugging MySQL Core File in Visual Studio Code

Debugging MySQL Core File

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.

ext install ms-vscode.cpptools

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.

shell> which mysqld
/usr/sbin/mysqld

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.

wget https://github.com/mysql/mysql-server/archive/refs/tags/mysql-8.0.34.tar.gz
tar xf mysql-8.0.34.tar.gz

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.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "cppdbg",
            "request": "launch",
            "name": "core dump",
            "program": "/usr/sbin/mysqld",
            "coreDumpPath": "/tmp/corefiles/core.9708",
            "cwd": "${workspaceFolder}",
            "MIMode": "gdb"
        }
    ]
}

  • 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.

Could not load source './obj/sql/../storage/innobase/../../../mysql-8.0.34/storage/innobase/row/row0sel.cc': 'SourceRequest' not supported..

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.

"sourceFileMap":{
    "./obj/sql/../storage/innobase/../../../mysql-8.0.34/": "${workspaceFolder}"
}

The new configuration will be:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "cppdbg",
            "request": "launch",
            "name": "core dump",
            "program": "/usr/sbin/mysqld",
            "coreDumpPath": "/tmp/corefiles/core.9708",
            "cwd": "${workspaceFolder}",
            "MIMode": "gdb",
            "sourceFileMap":{
                "./obj/sql/../storage/innobase/../../../mysql-8.0.34/": "${workspaceFolder}"
            }
        }
    ]
}

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!

Mar
30
2022
--

MySQL Shell For VS Code – Your New GUI?

MySQL Shell For VS Code

MySQL Shell For VS CodeMySQL Shell For VS Code integrates the MySQL Shell directly into VS Code development workflows and was released last week. This extension to the popular VS Code platform enables interactive editing and execution of SQL for MySQL Databases and optionally the MySQL Database Service for several simultaneous sessions.  It is a preview release and not ready for production but it does have several features that may make the MySQL GUI of choice.

Installation

The installation itself is easy but you will need to download the code from here and not the usual places for MySQL products.  You will, of course, have to have VS Code installed first, and be warned that some of the more tantalizing links for things like documentation are not connected.

install screen

MySQL Shell for VS Code installation screen and yes, you will need VS Code installed first.

Usage

The interface is familiar to that of MySQL Workbench but seems more intuitive.  You will need to set up a connection to your server with all the usual host, user, and password information. From there you can create a session to that server.

The big change is to remember to use Control-ENTER to send commands to the MySQL instance.  The GUI allows easy SQL query editing. But be warned there are problems with the preview.  A familiar query to the world database did not work with the GUI but ran perfectly with the stand-alone version of MySQL Shell.  Other queries worked well.

The first query is wrong

The first query was not correct. The second query went a little better.

For some reason, the first query did not get sent correctly to the server.

correct answer

The correct answer to the first query.

Quick Take

This is an impressive product even though it is a preview.  This is far better than the old MySQL CLI and the GUI editing makes the very good MySQL Shell features extremely useful.

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com