Valgrind Memcheck is a tool that detects memory usage problems such as leaks, invalid memory access-s, incorrect memory releases, and undefined value references.
Valgrind integration in CLion works on Linux, macOS, and Windows with WSL (refer to Valgrind on WSL).
If you are working with WSL, install Valgrind on your WSL instance (sudo apt-get install valgrind) and provide CLion with the path to the executable (see step 3).
In CLion, go to Settings | Build, Execution, Deployment | Dynamic Analysis Tools | Valgrind.
CLion will attempt to detect the Valgrind binary as set in system PATH.
In case of a non-standard Valgrind location, provide the path manually in the Valgrind executable field.
For example, a suppression file can be used to turn off Valgrind checks for particular libraries.
Configure Valgrind on WSL
In Settings | Build, Execution, Deployment | Dynamic Analysis Tools | Valgrind, provide the 'subsystem' path to Valgrind, which is /usr/bin/valgrind by default, instead of the actual Windows location of the Valgrind binary.
Activate a CMake profile connected to the WSL toolchain.
For this, do one of the following:
Set the WSL toolchain as default. This way, it will automatically connect to the default CMake profile:
Create a separate CMake profile, connect it to the WSL toolchain, and select this profile in the configurations switcher:
Run targets
note
Make sure to run Valgrind on a build with debug information. Otherwise, the Valgrind report might be incomplete or inaccurate.
To run a target (application or test) with Valgrind Memcheck, do one of the following:
Click the gutter icon and select Run 'your_target_name' with Valgrind Memcheck option from the menu:
Select the desired Run/Debug configuration and call Run | Run 'your_target_name' with Valgrind Memcheck from the main menu or click the dedicated toolbar icon:
If Valgrind was not configured previously, CLion will open the configuration dialog.
tip
Valgrind might not work correctly when run on a project with Google sanitizers. CLion will warn you about that:
Explore results
When the launch is finished, open the Valgrind tab in the Run tool window.
The left-hand pane shows the list of all problems found by Valgrind Memcheck. Each entry includes the instruction pointer, problematic function name, and (if possible) the source file where the problem is located.
In the right-hand pane, you can find full stack frame description and the corresponding code preview (when possible).
tip
Press F4 to jump back to the source code.
Use the context menu action to copy the warning data to clipboard:
Export and import results
To export the results, click the Export icon in the left pane of the Valgrind tab and specify the destination XML file:
Note that the Export button is unavailable during execution.
To import the results, select Run | Import Valgrind XML Results from the main menu and choose the XML file to import from.
Thanks for your feedback!
Was this page helpful?
Cookie Settings
Our website uses some cookies and records your IP address for the purposes of accessibility, security, and managing your access to the telecommunication network. You can disable data collection and cookies by changing your browser settings, but it may affect how this website functions. Learn more.
With your consent, JetBrains may also use cookies and your IP address to collect individual statistics and provide you with personalized offers and ads subject to the Privacy Notice and the Terms of Use. JetBrains may use third-party services for this purpose. You can adjust or withdraw your consent at any time by visiting the Opt-Out page.