24

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?

mstrap
  • 16,808
  • 10
  • 56
  • 86
  • 3
    Thanks, your question solved my problem, adding `SET(CMAKE_BUILD_TYPE Debug)` worked for me. – Searene Aug 30 '18 at 13:46
  • same here! thanks! – Bernardo Rodrigues Oct 19 '19 at 21:13
  • 1
    I have tried every one of these solutions and none of them works. My program just doesn't stop on my breakpoints. It is almost making it pointless to use Clion, which is sad because I like JetBrains software for every other kind of programming I do. – jimboweb Apr 12 '20 at 16:06
  • My issue seems to be connected to this problem with lldb on catalina: https://github.com/microsoft/vscode-cpptools/issues/3829. But this is dealing with the issue on vscode. Don't know how to reproduce the solution with clion. – jimboweb Apr 12 '20 at 16:20

17 Answers17

13

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.

Michael Mairegger
  • 6,833
  • 28
  • 41
  • 6
    In configuration I dnt see Debug as an option. Can you please suggest how to add debug as an option in configuration. – frogEye May 30 '17 at 14:48
  • @Vishal You can find the steps in [Creating and Editing Run/Debug Configurations](https://www.jetbrains.com/help/clion/creating-and-editing-run-debug-configurations.html) – Michael Mairegger May 31 '17 at 05:54
  • CLion documentation is very obscure. I am facing the same problem and am preparing for a long trip to understand the philosophy of configurations, relation with CMake and debuger. – Arnaud Mégret Oct 30 '18 at 14:56
9

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.

Evan Moran
  • 3,825
  • 34
  • 20
  • 1
    Yeaaah. that would be me. This is what happens when you don't use a Big Damn UI for a coupe of months. You forget how the cutesy buttons work, exactly ;) – D Hydar Jul 14 '23 at 18:37
6

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)

mstrap
  • 16,808
  • 10
  • 56
  • 86
  • 5
    If you need to append your own debug flags, this is the fix:: set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") – Vyrx Aug 09 '16 at 15:42
  • @mstrap If this is the problem, what is the fix? just delete it? – Gulzar Nov 24 '21 at 14:53
4

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.

Anonymous
  • 41
  • 2
3

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

Derza Arsad
  • 41
  • 1
  • 2
  • 1
    In 2019.2 the path is slightly different: File -> Settings -> Build, Excution, Deployment -> CMake – HughB Aug 15 '19 at 23:22
3

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

3

I had a different issue that caused my breakpoints not to be hit. I develop both embedded apps and native MacOS console apps with CLion. For the embedded work, GDB needs to be set for your selected Preferences/Toolchains.

For debugging console apps LLDB needs to be selected in Preferences/Toolchains. If it is left on GDB, my breakpoints don't work. Set to LLDB here:

enter image description here

Craig B
  • 4,763
  • 1
  • 25
  • 19
2

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

wrubino
  • 29
  • 2
  • Oh, man! Thank you so much! It resolved my problem. Your answer is one of the most underestimated! – V-Mor Nov 10 '21 at 10:34
  • Same issue for me. Anyone know why a comma breaks things? – mfbutner Apr 04 '22 at 17:26
  • When my project is in the`/tmp` directory, the breakpoint doesn't work, but when the project is in `~/CLionProjects` the breakpoint works, I spent a lot of time troubleshooting this problem, what's the reason behind it? – Poison Oct 16 '22 at 02:30
  • See [CPP-30773](https://youtrack.jetbrains.com/issue/CPP-30773/Breakpoints-do-not-take-effect-when-files-are-created-through-symbolic-link-directories) – Poison Oct 17 '22 at 09:40
1

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

ctc chen
  • 1,336
  • 1
  • 7
  • 7
1

My problem was with the -ffile-prefix-map flag. Once I removed it, everything worked fine.

See https://youtrack.jetbrains.com/issue/CPP-23159 and https://youtrack.jetbrains.com/issue/CPP-15850

Mikhail
  • 20,685
  • 7
  • 70
  • 146
0

I had the same issue. I noticed that every time I click the debug option, the "Antimalware Service Executable" process starts. I created an exclusion for MinGW folder in windows Defender and it worked fine...

Syed Umair
  • 1,480
  • 1
  • 13
  • 14
0

Just like minecrawler said in github, if your os is linux, your should set:

file/Settings/Build,Execution,Deployment/Tllochains/Debugger from Bundled GEB or gdb to Bundled LLDB.

I tried and it worded!

Reza Ghorbani
  • 2,396
  • 2
  • 28
  • 33
0

In my case (Linux / Ubuntu) the problem was somehow related to mounted directory. The project was initially opened in CLion from /media/username/ssd/repo/git/projectname. The breakpoints were always disabled with message No executable code is associated with this line.

Then I opened the same project from a symlinked directory ~/git -> /media/username/ssd/repo/git and the breakpoints began to work fine.

0

In my case I had to edit the file so that everything was compiled again instead of using cache.

YuseqYaseq
  • 244
  • 5
  • 16
0

In my case, the problem is forget to comment out optimize option add_definitions(-O3) in cmakelists. which let compiler go release.

vicky Lin
  • 150
  • 1
  • 10
0

in the case of "the platform is currently not connected" of CLION for RUST, it turns out there is an authorization step which is not enabled on CLION 2022.2 version.

download the correct version solves the problem

zinking
  • 5,561
  • 5
  • 49
  • 81
0

I had target_link_options(app PRIVATE -s) in my CMakeLists.txt which of course removed all necessary symbols ‍♂️

From the gcc docs at https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

-s Remove all symbol table and relocation information from the executable.

tjeerdhans
  • 1,058
  • 10
  • 13