Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my breakpoints not hit in CLion?

I'm trying to debug an executable which has been created with CMake configuration

SET(CMAKE_BUILD_TYPE Debug)

However, CLion does not hit any breakpoints. What could be the problem?

like image 294
mstrap Avatar asked Mar 09 '16 10:03

mstrap


People also ask

Why are my breakpoints not working?

If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.

How do I activate breakpoints?

To set a breakpoint in source code, click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint.

How do you debug CLion?

For debug press Shift+F9 . To help you inspect the state of your code during debugging, CLion equips you with many useful shortcuts like Step over/into ( F8/F7 ), Step out ( Shift+F8 ), or Run to cursor ( Alt+F9 ).


8 Answers

I had the same issue today. I figured out that the configuration for the project was not set to Debug. After setting the configuration to Debug all the breakpoints are hit.

Please ensure that you have following configuration:

  • Select the MenuItem Run/EditConfigurations
  • Select the right Target
  • Select Debug as Configuration

Now the breakpoints should be hit.

like image 122
Michael Mairegger Avatar answered Oct 03 '22 01:10

Michael Mairegger


In case this helps someone else, it turned out that my (somewhat embarrassing) issue was that I was hitting Run instead of Debug. So in the Run menu don't use the play icon, instead choose the cute bug icon instead. Choosing Run was causing it to automatically build the non-debug build so breakpoints wouldn't work. Once I started choosing the bug icon, the breakpoints worked like a charm.

like image 22
Evan Moran Avatar answered Oct 03 '22 00:10

Evan Moran


As it has turned out, the executable was compiled with following CMake options (further down in the script):

SET(CMAKE_C_FLAGS_DEBUG "-D_DEBUG")

This was breaking debug functionality for CLion (it was also breaking most of the debug functionality of gdb)

like image 35
mstrap Avatar answered Oct 03 '22 00:10

mstrap


I also had the same Problem. Since 2016.3 CLion changed the CMake workflow so that only one configuration is allowed at one time clion new workflow

The solution is File -> Settings -> Build, Excution, Deployment -> change the build configuration

like image 37
Derza Arsad Avatar answered Oct 03 '22 01:10

Derza Arsad


In my case my CMake option CMAKE_BUILD_TYPE was already set to DEBUG on CMake Settings. However, it was the command set(CMAKE_BUILD_TYPE Release) in the CMakeLists.txt, which was merged by git pull and overrode the CMake Settings while execution. I could not figure out earlier as CMake Debug console was showing -DCMAKE_BUILD_TYPE=Debug

When I changed it to set(CMAKE_BUILD_TYPE Debug) breakpoints were hit again.

like image 25
Anonymous Avatar answered Oct 03 '22 02:10

Anonymous


In case this helps someone else:

In my case I had to set the -DCMAKE_BUILD_TYPE option to Debug explicitly in Settings -> Build, Execution, Deployment -> CMake

My case

like image 36
Dmitriy Merkushov Avatar answered Oct 03 '22 02:10

Dmitriy Merkushov


I had a comma in my project path. Removing the comma fixed the problem for me.

like image 35
wrubino Avatar answered Oct 03 '22 02:10

wrubino


In 2019.3, it turns out to be CLion/Preference/Build,Execution,Deployment/CMake/Build type/Debug.

like image 1
ctc chen Avatar answered Oct 03 '22 02:10

ctc chen