Debugging¶
When debugging, some additional compiler flags are needed to produce debugging information. These flags can be added using the CMake's CMAKE_BUILD_TYPE
environment variable by:
- specifying
-DCMAKE_BUILD_TYPE=Debug
when executingcmake
in the command line, - putting
set(CMAKE_BUILD_TYPE "Debug")
into yours or the libtropic's mainCMakeLists.txt
.
After this, you can use debugging tools of your choice, e.g. gdb or Valgrind. Refer to each tool's documentation for the installation instructions.
If you want to use AddressSanitizer, you have to add more compiler flags. That is why we added the LT_ASAN
option into our main CMakeLists.txt
, along with the LT_ASAN_COMPILE_FLAGS
and LT_ASAN_LINK_FLAGS
variables. If your project is using CMake, you can add the following lines into your CMakeLists.txt
file:
if(LT_ASAN)
message(STATUS "AddressSanitizer (ASan) is enabled for the entire project.")
add_compile_options(${LT_ASAN_COMPILE_FLAGS})
add_link_options(${LT_ASAN_LINK_FLAGS})
endif()
LT_ASAN
is set either via the command line or directly in CMakeLists.txt
. Tip
If you are debugging on any Unix-like operating system, you do not have to make any changes and can directly debug with the TROPIC01 Model, where the environment for debugging is already prepared (the section provides all information on how to do that).