diff --git a/kitty/ringbuf.c b/kitty/ringbuf.c
index 3c138adb2..0c1b3921d 100644
--- a/kitty/ringbuf.c
+++ b/kitty/ringbuf.c
@@ -13,7 +13,9 @@
* .
*/
+#ifndef KITTY_DEBUG_BUILD
#define NDEBUG 1
+#endif
#include "ringbuf.h"
#include
diff --git a/setup.py b/setup.py
index bb3a507e1..d6a62247e 100755
--- a/setup.py
+++ b/setup.py
@@ -304,6 +304,9 @@ def init_env(
cflags.append('-flto')
ldflags.append('-flto')
+ if debug:
+ cflags.append('-DKITTY_DEBUG_BUILD')
+
if profile:
cppflags.append('-DWITH_PROFILER')
cflags.append('-g3')