CLion skips breakpoints when executing tests using gtest

I've got a simple C++ library with some tests using GTest:

.
├── CMakeLists.txt
├── LICENSE
├── nametract.cpp
├── nametract.h
├── README.md
└── tests
    ├── CMakeLists.txt
    └── nametract_test.cpp

I can run the tests just fine using CLion's gtest run configuration - it runs them as expected. It also does recognise all the tests in nametract_test.cpp - if I want, I can run them individually.

However, when I set a breakpoint in my test case, or in nametract.cpp, and run my tests, all the breakpoints are skipped. It does say that it is running with debugger, the tests themselves are being run and CLion reports the breakpoints as being enabled - however, it doesn't stop code execution on those. What might be the cause of this problem? How could I fix it?

Main CMakeLists.txt:

cmake_minimum_required(VERSION 3.20)
project(nametract)

set(CMAKE_CXX_STANDARD 17)

add_library(nametract nametract.cpp)

add_subdirectory(tests)

CMakeLists.txt in tests folder:

include(FetchContent)

project(tests)

FetchContent_Declare(
        googletest
        GIT_REPOSITORY https://github.com/google/googletest.git
        GIT_TAG        955c7f837efad184ec63e771c42542d37545eaef
)

FetchContent_MakeAvailable(googletest)

add_executable(tests_run nametract_test.cpp)

target_link_libraries(tests_run nametract)
target_link_libraries(tests_run gtest gtest_main)
0
1 comment

If you had found previously that debugging with GDB was slow to load symbols and put the line 

set auto-solib-add off

in your ~/.gdbinit file, which has the effect of loading symbols significantly faster, then you will need to comment/remove this line for symbols in a gtest to be loaded and the breakpoint to be active

 

0

Please sign in to leave a comment.