Skip to content

Commit 6a66ac5

Browse files
[ENHANCE] Add option for debuggers (#797)
1 parent 937cf63 commit 6a66ac5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ option(WITH_DLT_EXAMPLES "Set to ON to build src/examples binaries"
7979
option(WITH_DLT_FILETRANSFER "Set to ON to build dlt-system with filetransfer support" OFF)
8080
option(WITH_DLT_SYSTEM "Set to ON to build src/system binaries" OFF)
8181
option(WITH_DLT_DBUS "Set to ON to build src/dbus binaries" OFF)
82+
option(WITH_DLT_DEBUGGERS "Set to ON to enable debug symbols, AddressSanitizer, and Valgrind support" OFF)
8283
option(WITH_DLT_TESTS "Set to ON to build src/test binaries" ON)
8384
option(WITH_DLT_UNIT_TESTS "Set to ON to build gtest framework and tests/binaries" OFF)
8485
cmake_dependent_option(WITH_DLT_INSTALLED_TESTS "Set to ON to install tests/binaries" OFF WITH_DLT_UNIT_TESTS OFF)
@@ -155,6 +156,20 @@ include_directories(
155156
${PROJECT_SOURCE_DIR}/systemd/3rdparty
156157
)
157158

159+
if(WITH_DLT_DEBUGGERS)
160+
message(STATUS "WITH_DLT_DEBUGGERS is ON: Enabling -g3, -O0, AddressSanitizer, and Valgrind compatibility.")
161+
if (CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
162+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3 -O0 -fsanitize=address")
163+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O0 -fsanitize=address")
164+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
165+
endif()
166+
set(ENV{ASAN_OPTIONS} "detect_leaks=1")
167+
message(STATUS "AddressSanitizer enabled: run your binaries normally.")
168+
message(STATUS "If a memory error occurs, AddressSanitizer will print a detailed error report to the terminal, including the type of bug, stack trace, and location.")
169+
message(STATUS "Leak detection is enabled by default (ASAN_OPTIONS=detect_leaks=1). See https://clang.llvm.org/docs/AddressSanitizer.html for more info.")
170+
message(STATUS "You can also run the binaries with Valgrind: valgrind ./your_binary")
171+
endif()
172+
158173
add_definitions(-D_GNU_SOURCE)
159174
add_definitions(-DDLT_WRITEV_TIMEOUT_MS=${DLT_WRITEV_TIMEOUT_MS})
160175
add_definitions(-DDLT_QNX_SLOG_ADAPTER_WAIT_BUFFER_TIMEOUT_MS=${DLT_QNX_SLOG_ADAPTER_WAIT_BUFFER_TIMEOUT_MS})
@@ -245,6 +260,7 @@ add_compile_options(
245260
-Wcast-qual
246261
-Wno-system-headers
247262
-Wno-unused-function
263+
-Wno-stringop-truncation
248264
)
249265

250266
if(WITH_DOC STREQUAL "OFF")

0 commit comments

Comments
 (0)