This tutorial shows how to import Linux CMake projects to VisualGDB. We will demonstrate this by downloading the MySql database engine source code, building it with VisualGDB, debugging the client application and using Code Map and other IntelliSense features to explore the code.
Before you begin, download MySql source code to your Linux machine and unpack it.
- Start Visual Studio and launch the VisualGDB Linux Project Wizard:
- In the Linux Project wizard select “Import a project -> Import a CMake project”:
- On the next page select the computer where you have unpacked the MySql source code:
- Then select “The sources are already on the Linux computer” and enter the source directory:
- In this tutorial we will keep the source files directly on the Linux machine and access them from Windows via shared folders. To setup this automatically, select the first item on the Source Code Access page and click “Setup”:
- Select the directory you want to share on the Linux machine and provide the share name, user name and password:
- Once you click OK, VisualGDB will create the share and display the overview of the Windows and Linux paths:
- On the last page specify build subdirectories for Debug and Release configurations. You can use the ../subdir syntax to specify directories outside the source directory:
- Click “Finish” to build the project then build it with Ctrl-Shift-B:
- If you don’t have MySql installed on that machine, install it manually by running the following commands in the build directory:
123456789sudo make installadduser mysqlcd /usr/local/mysqlchown -R mysql .chgrp -R mysql .bin/mysql_install_db --user=mysqlchown -R root .chown -R mysql varsudo mysqld
- Now we can debug the MySql client. Open VisualGDB Project Properties and go to the Debug Settings page. Then check the “Run debugger as root” checkbox:
- Hit F10 to step into the main() function:
- As the MySql project is large and has a lot of targets distributed among multiple CMake files, VisualGDB won’t auto-detect the executable to debug. Instead it allow selecting one explicitly. Specify the mysql client binary and press OK:You can change the primary executable later on the CMake page of VisualGDB Project Properties.
- The debugging will start at the main() function:
- You can use the normal Visual Studio debugging functionality to debug the code. If you are using the Clang IntelliSense engine, you can right-click in your code and select “Preprocess Selected Lines” to automatically see behind non-trivial preprocessor macros:
- When importing CMake projects, VisualGDB will configure CMake to generate a <project directory>\VisualGDBCache\<project>-<config>\compile_commands.json file with all build command lines and will configure IntelliSense based on that file. If you encounter strange IntelliSense errors, check that file to see whether the command line mentioned in it is up to date:
- You can also use Code Map provided by the Clang IntelliSense engine to quickly visualize the relations between different parts of your code: