Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run CTest test in debugger

Tags:

gdb

cmake

ctest

Suppose in CMakeLists.txt I have

add_executable(mytarget main.cpp)

enable_testing()
add_test(mytarget_test0 mytarget -option0)

Is there any easy way how can I run mytarget in GDB with all command line options from some particular CTest test? (Other than searching for test in CMakeLists and then copy-pasting add_test parameters to command line manually?)

Real life scenario: I run all tests using ctest, one fails, I want to open it in debugger quickly.

In other build systems there are command line parameters to use gdb, for example in Meson meson test --gdb testname , in bazel bazel --run_under=gdbserver. I did not found anything similar for CTest

like image 776
random Avatar asked Nov 22 '25 15:11

random


1 Answers

It is possible to get test command with arguments:

ctest -R $regex_matching_test -V -N

As output you will get something like:

Test project ../cmake-build-debug-gcc7
Constructing a list of tests
Done constructing a list of tests

1: Test command: ../cmake-build-debug-gcc7/my_tool  "-v" "test0"
  Test #1: my_tool_test0

Total Tests: 1

Then using regexp it is possible to grab command line args for gdb

like image 134
random Avatar answered Nov 25 '25 10:11

random



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!