From b7f6c641f1989c03f678ff4c059ac0e8213db456 Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Sat, 19 Sep 2026 16:07:10 -0400 Subject: [PATCH] Define more debug options for `make develop` (#2124) --- CMakeLists.txt | 12 ++++++++++-- Makefile | 4 +++- src/version.cpp | 19 ++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c1337533..30d106f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,14 +52,22 @@ endif() if(SANITIZERS) if(MSVC) message(STATUS "ASan enabled") - add_compile_options(/fsanitize=address) # Note that this shouldn't be passed to the linker. + add_compile_options(/fsanitize=address /sdl) # Note that this shouldn't be passed to the linker. + add_definitions(/_MSVC_STL_HARDENING=1 /_MSVC_STL_DESTRUCTOR_TOMBSTONES=1 /D_ITERATOR_DEBUG_LEVEL=2) else() # We assume a GNU-like compiler. message(STATUS "ASan and UBSan enabled") set(SAN_FLAGS -fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero) add_compile_options(${SAN_FLAGS}) add_link_options(${SAN_FLAGS}) - add_definitions(-D_GLIBCXX_ASSERTIONS -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG) + # Consider using `_GLIBCXX_DEBUG_BACKTRACE` (and `-lstdc++exp`) if unable to debug locally. + add_definitions(-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_GLIBCXX_SANITIZE_VECTOR + -D_GLIBCXX_VERBOSE_ASSERT + # This enables debug-mode checks for `std::string`s, but stdlibc++ says + # "this is unsupported and not guaranteed to work", so removing it may be fine. + # https://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode_semantics.html + -D_GLIBCXX_EXTERN_TEMPLATE=0 + -D_LIBCPP_DEBUG -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG) # A non-zero optimization level is desired even in debug mode (especially for Clang), # and the two codegen flags improve the sanitizers' backtraces, but we want the user to # be able to override these easily so we put them first. diff --git a/Makefile b/Makefile index 859b134e..1f6b2f14 100644 --- a/Makefile +++ b/Makefile @@ -225,7 +225,9 @@ develop: -Wformat=2 -Wformat-overflow=2 -Wformat-truncation=1 \ -Wno-format-nonliteral -Wno-strict-overflow -Wno-unused-but-set-variable \ -Wno-type-limits -Wno-tautological-constant-out-of-range-compare -Wvla \ - -D_GLIBCXX_ASSERTIONS -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG \ + -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_GLIBCXX_SANITIZE_VECTOR \ + -D_GLIBCXX_VERBOSE_ASSERT -D_GLIBCXX_EXTERN_TEMPLATE=0 \ + -D_LIBCPP_DEBUG -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG \ -fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero" \ CXXFLAGS="-ggdb3 -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls" diff --git a/src/version.cpp b/src/version.cpp index e64e2060..9e44d95d 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -14,13 +14,22 @@ #if !defined(NDEBUG) && defined(__SANITIZE_ADDRESS__) && !defined(__APPLE__) extern "C" { char const *__asan_default_options(void) { - return "detect_leaks=1" - ":detect_stack_use_after_return=1" + return ":check_initialization_order=1" ":detect_invalid_pointer_pairs=2" - ":check_initialization_order=1" + ":detect_leaks=1" + ":detect_stack_use_after_return=1" + // ":fast_unwind_on_malloc=0" // Enable this if ASan outputs bad backtraces + ":print_legend=0" ":strict_init_order=1" - ":strict_string_checks=1" - ":print_legend=0"; + ":strict_string_checks=1"; + } +} +#endif + +#if !defined(NDEBUG) && defined(__SANITIZE_UNDEFINED__) +extern "C" { + char const *__ubsan_default_options(void) { + return "print_stacktrace=1"; } } #endif