First add this to your CMakeLists.txt file:
if(BOARD STREQUAL "native_posix_64")
target_compile_options(app PRIVATE -fsanitize=address -fsanitize=undefined)
target_link_options(app PRIVATE -fsanitize=address -fsanitize=undefined)
target_link_libraries(app PRIVATE asan ubsan)
endif()
For testing I used the blinky example, and added this at the beginning of the main function: