CLion: Enable debugging of external libraries by adding source files

This might happen if libtins is built without debug info. How exactly do you build it?

It should be roughly the following:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ../
make

The easiest way to do so is to build libtins directly in your project. Since libtins can also be built with CMake, the fastest way for you to do this is to add a directory called libtins in your source directory containing the libtins source, and include it in your project with

add_subdirectory(libtins)

For this you will need to fulfill the dependencies of libtins as well.

Then, you do not need FIND_LIBRARY(TINS_LIBRARY tins) anymore, since it is already present in your project. To link it the following should do the trick:

TARGET_LINK_LIBRARIES(myproject ${Boost_LIBRARIES} tins SQLiteCpp sqlite3 pthread dl)

Do not forget to include the tins directories beforehand:

include_directories(libtins/include/tins)

After this, when you run your program in debug mode, the libtins methods should also be available since it was built identically to your project.

Note that I would choose another strategy should you want to include libtins in your project in a long term. Then, I would rather look for a solution with the ExternalProject_Add command.


The following worked for me in Ubuntu 16.04.3 LTS with CLion 2017.3.3.

First you have to replace the CLion bundled gdb with Ubuntu's original (not sure why):

$ cd ~/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/173.4548.31/bin/gdb/bin
$ mv gdb gdb_original
$ ln -s /usr/bin/gdb gdb

Then start the debugging session placing a breakpoint before stepping into library code.

When the execution is stopped at your breakpoint, go to the GDB console tab and execute this pointing to the full path where the source code to be debugged resides. For example, to debug OpenSSL's BIO_new function I had to do:

(gdb) dir /full/path/to/openssl-1.0.2g/crypto/bio

Because BIO_new is implemented in bio_lib.c which resides in the previous folder.

Now you can step into your library code.