From d5e84383d14b04cb42a768d02205445fb732c331 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Fri, 19 Sep 2025 01:30:57 +0300 Subject: [PATCH] doc: Document building with sanitizers --- doc/manual/source/development/debugging.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/manual/source/development/debugging.md b/doc/manual/source/development/debugging.md index 98456841a..ccc6614b7 100644 --- a/doc/manual/source/development/debugging.md +++ b/doc/manual/source/development/debugging.md @@ -24,6 +24,19 @@ It is also possible to build without debugging for faster build: (The first line is needed because `fortify` hardening requires at least some optimization.) +## Building Nix with sanitizers + +Nix can be built with [Address](https://clang.llvm.org/docs/AddressSanitizer.html) and +[UB](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) sanitizers using LLVM +or GCC. This is useful when debugging memory corruption issues. + +```console +[nix-shell]$ export mesonBuildType=debugoptimized +[nix-shell]$ appendToVar mesonFlags "-Dlibexpr:gc=disabled" # Disable Boehm +[nix-shell]$ appendToVar mesonFlags "-Dbindings=false" # Disable nix-perl +[nix-shell]$ appendToVar mesonFlags "-Db_sanitize=address,undefined" +``` + ## Debugging the Nix Binary Obtain your preferred debugger within the development shell: