CLion 2017.3 EAP: Valgrind memcheck integration

Posted on by Anastasia Kazakova

Hi,

Today we are rolling out a new CLion 2017.3 EAP build (173.3415.24) with support for memory check from Valgrind and some polishing of the toolchains rework.

banner_valgrind_800х400@2

Download CLion 2017.3 EAP

Valgrind: memcheck

Good news everyone! CLion now comes with Memcheck integration; this means you can detect runtime errors and memory leaks right from the IDE. We know you are eager to try it out on your project, but first let me put a few general thoughts down here:

  • This is just a first step toward the support of profiling tools in CLion
  • Memcheck is just one member of the big Valgrind family, but probably the most famous (and used) one
  • Valgrind doesn’t require a program recompilation and supports both GCC and Clang
  • There are dozens of great tools available to C and C++ developers other than Valgrind, like Google sanitizers, and gprof. If you are interested in any of these, feel free to upvote existing requests or fill out a new one in our tracker.

System requirements & settings

Valgrind works on Linux and macOS and is available in CLion on both of these platforms. CLion detects it automatically by searching for it in the standard locations defined by the system PATH variable. Or you can point CLion to Valgrind’s executable using: Settings/Preferences | Build, Execution, Deployment | Valgrind:
valgrind_settings

Options with which to run Valgrind and a list of suppression files which can be used, can also be configured on this page. For example, you may want to add a non-default suppression file to turn off Valgrind checks on some particular libraries you are using in your project. The typical case here, for example, would normally be to suppress OpenSSL or Boost.

Default Valgrind options include:

  • --read-inline-info=yes which is supported in Valgrind 3.10.0+, so if you have an earlier version remove this parameter
  • --read-var-info=yes which causes issues on macOS platform, so remove it in this case

Running targets under Valgrind

Select a Run/Debug configuration and run it under Valgrind memcheck via the Run | Run Valgrind Memcheck… or special icon in the Navigation bar located next to the Run and Debug options:
valgrind_icon

This icon is present on all three platforms, but it is disabled on Windows as Valgrind is not available there.

You’ll get a new tab called ‘Valgrind’ in the Run toolwindow. It provides the information about all the possible errors found by Valgrind, along with the source code location (use F4 on Linux and ⌘↓ on macOS to Jump to Source) and a stack trace. The results are grouped by the type of leak encountered:

modernize

In the context menu on a particular error you can:

  • Exclude the error from the current results log, error will be back on the next Valgrind run
  • Suppress the function that causes an error by adding a corresponding record to the selected suppression file

Running tests under Valgrind

Google Test, Catch and Boost.Test targets can also be run with memcheck. You can either select necessary test target and press ‘Run Valgrind Memcheck’ icon in the Navigation bar, or use test icons in the left gutter when the file with tests is opened in the editor:
test_memcheck

Check out the memcheck (Valgrind) integration into CLion and let us know what you think! Mind, UI is not final yet, so your feedback here is appreciated.

Toolchains, CMake profiles & more

Multiple toolchains support was brought in with CLion 2017.3 EAP which allowed:

  • easier compilers configuration
  • different CMake versions/debugger for different projects and configurations
  • on Windows different toolchains (MinGW, Cygwin or Microsoft Visual C++) for different projects and configurations

This EAP build polishes these changes and allows you to get several CMake profiles with the same build type. For example, you can use it if you want to build different Debug targets in your project with different toolchains. In previous CLion versions, you have to switch the toolchain in the CMake profile that corresponds to the Debug build type. Now you can configure several such profiles:

  1. In Settings/Preferences | Build, Execution, Deployment | Toolchains create several toolchains:
    toolchains_new
  2. In Settings/Preferences | Build, Execution, Deployment | CMake add several CMake profiles which use different toolchains:
    cmake_profiles_new
    Profile names should be unique. Default CMake generation path will be cmake-build-. Build options are now specified per CMake profile.
  3. Create several Run/Debug configurations with different CMake profiles:
    run_configurations_profiles

That’s it! Full release notes can be found here.

Download CLion 2017.3 EAP

Your CLion Team
The Drive to Develop

Comments below can no longer be edited.

43 Responses to CLion 2017.3 EAP: Valgrind memcheck integration

  1. Tano says:

    October 26, 2017

    Hi Anastasia,
    I noticed that the order of the articles in this page is wrong:https://blog.jetbrains.com/clion/
    The top article is from 7 sept, then the next from 26 oct, then the next from 19 oct.
    Isn’t it normal for the latest article to be the first? That’s how blogs work, to be easy to check if a new article appeared on the site.

    • Tano says:

      October 26, 2017

      For one month I often checked the site and nothing was on the top, and I thought that no news appeared…but when I scrolled now…I got a surprise, it seems that “CLion starts 2017.3 EAP” is always on top.

    • Anastasia Kazakova says:

      October 26, 2017

      The first EAP blog post is simply pinned to the top.
      If you want to be notified about the news, you can subscribe (there is a form on the right) and get all news via emails.

      • Tano says:

        October 27, 2017

        Great, thanks.
        Yes, I want to subscribe to CLion new.

        • Tano says:

          October 27, 2017

          …new blog posts 🙂

  2. Roman says:

    October 26, 2017

    Do you plan to bundle Valgrind like other tools (CMake, GDB, LLDB) ? Or there is some technical reason why end-user has to install manually?

    • Anastasia Kazakova says:

      October 26, 2017

      We don’t want to increase the size of package w/o a good reason. CMake is essential to CLion, as you can’t do anything w/o it in the IDE. But Valgrind is some extra tool that you might not need. This can be changed but now we don’t think it’s reasonable enough.

      • Ben Wiley says:

        December 7, 2017

        Making it available as a plugin would be nice!

        • Anastasia Kazakova says:

          December 7, 2017

          If you have to download the plugin to install Valgrind, wouldn’t it be easy to just install Valgrind on your system?

  3. Roman says:

    October 26, 2017

    Can you put a CMake configuration selector on toolbar? Near target selector?
    So we can easily switch between various configs like in MSVC
    http://fordiac.sourceforge.net/ehelp/html/installation/img/VSreleaseDebug.png

    Currently there is no way to know from main GUI what configuration is selected w/o going to “Edit configurations”. Very inconvenient. I have to work on cross-platform library now, and I have to switch between configurations very often.

    Another nice feature in MSVC is that they have a JSON file for Launch configurations, instead of GUI: https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/
    Really helpful when you need to run application with different command line options. Personally I would prefer to use CTest for this purpose, but JSON is already better than GUI.

    • Anastasia Kazakova says:

      October 26, 2017

      Currently we work on the easier switcher of the build type in the toolbar (i.e. Debug/Release). It’s in development, you can expect in 2017.3 EAP soon.

      Regarding the JSON configuration file, not sure I completely understand why it’s better than UI. Probably, the UI has some issues that make is hardly usable in this case?

      • Roman says:

        October 26, 2017

        I’m ok with GUI, if there is a text representation behind it, so I can (1) put it to repo and (2) run all configurations automatically. CTest ideally solves the problem, but I can write some automation around json myself too.

      • Roman says:

        October 26, 2017

        Another problem with GUI is that I can’t share my run configurations with colleagues using other IDEs.

        • Anastasia Kazakova says:

          October 27, 2017

          That’s another story. While CMake profile is a general things, it related to Toolchains and Run/Debug configurations, that is completely CLion specific. So using some common format here (to be able to share with other IDEs) is a bit tricky task. But we’ll consider the idea. Thanks!

          • Roman says:

            October 27, 2017

            CTest solves problem with run configuration just perfectly:
            Suppose I want to run my tool with option0, option1 and option 3. I just write:

            enable_testing()

            add_test(my_tool_test0 mytool -option0)
            add_test(my_tool_test1 mytool -option1)
            add_test(my_tool_test2 mytool -option2)

            Much easier then GUI! And my colleagues can run it too in case some option does not work well!

            • Anastasia Kazakova says:

              October 30, 2017

              Not sure I understand how CTest relates to CLion Run/Debug configurations.

          • Roman says:

            October 30, 2017

            CTest solves the same problems as Run/Debug configuration dialog. In Clion GUI you can set:
            1) Executable
            2) Program arguments
            3) Working directory
            4) Environment variables

            In CTest you use:
            1) add_test https://cmake.org/cmake/help/v3.0/command/add_test.html
            To set executable , working directory and command line args
            2) Environment variables can be configured by test properties
            https://cmake.org/cmake/help/v3.7/manual/cmake-properties.7.html#properties-on-tests

            It is also possible to use CTest in Continuous integration system. Clion Run/Debug configurations do not support CI afaik.

            Unfortunately Clion does not detects Ctest, so I can’t use it in IDE 🙁

  4. Tano says:

    October 27, 2017

    Please try to not break existing things, when releasing a new version please 🙁
    This worked in 2016, 2017.1 and 2017, now it’s broken…
    https://youtrack.jetbrains.com/issue/CPP-11076

    • Anastasia Kazakova says:

      October 27, 2017

      Thanks for pointing, we’ll check.

      But I’d like to remind you that EAP is not a release version. It can be unstable, have regressions, etc. We are rolling it exactly for checking plenty of configurations and situations that we can’t cover with our testing, so that users report and we fix.

      Anyway, we are looking at the issue now.

  5. Tano says:

    October 27, 2017

    Anastasia, are there any news on CLion 2018 regarding the estimated date, roadmap and the features that will include? 🙂
    Thanks

    • Anastasia Kazakova says:

      October 30, 2017

      It will be available later, after the 2017.3 release approximately. We haven’t planned the 2018.1 release yet.

      • Tano says:

        November 1, 2017

        Thank you.
        Perhaps fix the main problem of CLion in 2018.1, a horrible lag when editing big files? I don’t know if it that slow because of Java or not…
        From 4 IDEs, CLion is the only one lagging. :((

        https://youtrack.jetbrains.com/issue/CPP-11121

        • Anastasia Kazakova says:

          November 1, 2017

          Thanks, we would greatly appreciate a CPU snapshot otherwise it’s not clear how to investigate an issue. We need a snapshot or a code to reproduce an issue.

  6. Evgenii says:

    October 28, 2017

    Any plans for sanitizers(ASan, TSan, etc.)?

  7. Maksim says:

    October 30, 2017

    Please add debugging with Visual Studio! Thanks in advance!

  8. James P. says:

    November 25, 2017

    I have just downloaded it but Error shows that Valgrind executable is not found. Do I have to install or set my computer additionally from just downloading the new version of CLion?

    • Anastasia Kazakova says:

      November 27, 2017

      Do you have Valgrind installed on you machine? If yes, just point to the executable in Settings | Build, Execution, Deployment | Valgrind

  9. Do Hyun Lee says:

    November 25, 2017

    I tried to use memory leak check after downloading Clion 2017.3. But I can only see “Valgrind executable is not found”. Do I have to install or set other things to use this function? Thank you

    • Anastasia Kazakova says:

      November 27, 2017

      Do you have Valgrind installed on you machine? If yes, just point to the executable in Settings | Build, Execution, Deployment | Valgrind

  10. Haresh Kainth says:

    November 25, 2017

    Absolutely fantastic. I just tried this in 2017.3 RC2 and so far it works like a dream. Thank you.

    • Anastasia Kazakova says:

      November 27, 2017

      Glad to hear that!

  11. Alexander Zaitsev says:

    December 2, 2017

    Hello. When will be available assembly view for existing source code? In which Clion release?

    • Anastasia Kazakova says:

      December 3, 2017

      There is no clear plan for this task for now. There are dozens of very important debugger tasks, and while this one is a high priority, still there are others which are even more important.

  12. avikam says:

    March 4, 2018

    Had I ran Valgrind in an external build system like TeamCity, how can I import the result XML to CLion? That is, can I open an independently created XML using the CLion Valgrind viewer?

    Thanks

    • Anastasia Kazakova says:

      March 4, 2018

      No, it’s not possible. CLion runs Valgrind on its own, using specific input keys, parses the output and provides it in the viewer. So external run is not supported.

  13. okman says:

    October 14, 2018

    Hi, Valgrind Can use in the MacOs Mojava? It seems can not compiled.

    • Anastasia Kazakova says:

      October 14, 2018

      Seems it’s not yet available via brew (https://stackoverflow.com/questions/52732036/how-to-install-valgrind-on-macos-mojave10-14-with-homebrew), but probably you can build it from sources.

      • okman says:

        October 17, 2018

        when build from sources, got some errors like this: configure: error: Valgrind works on Darwin 10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x and 17.x (Mac OS X 10.6/7/8/9/10/11 and macOS 10.12/13)… valgrind do not support macOS Mojava yet.

        • Anastasia Kazakova says:

          October 17, 2018

          Indeed seems they check the OS version and stop when Mojave is detected. Not sure we can do smth about it. You can try using Google Sanitizers instead, until Valgrind is ready for the latest macOS.

          • okman says:

            October 19, 2018

            OK, thank you!

Subscribe

Subscribe for updates