diff --git a/meson.build b/meson.build
index 71cb6c4ae58071702591b1ecd66f1cb74ec2ed53..2467cdc15f39ca094f3a9a8f5fc3b5e5be285d3c 100644
--- a/meson.build
+++ b/meson.build
@@ -177,6 +177,12 @@ else
 	              check_anywhere_queue_while_stealing == 'true')
 endif
 
+is_debug_buildtype = get_option('buildtype').startswith('debug')
+libstdcxx_debug = get_option('libstdcxx_debug')
+if (libstdcxx_debug == 'auto' and is_debug_buildtype) or libstdcxx_debug == true
+  add_global_arguments('-D_GLIBCXX_DEBUG', language: 'cpp')
+endif
+
 # check io meson options consistency
 if get_option('io_single_uring')
 	if io_sqpoll_option == 'each' or io_sqpoll_option == 'numa'
diff --git a/meson_options.txt b/meson_options.txt
index 1b54e3de90bf82ae6625eb53800075b6d65cab06..8ee2e7cbaf4c1fa2d06656043273ad08ab83fe3a 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -217,3 +217,10 @@ option(
   description: 'Memory ordering used for the lockless CQ algorithm',
   value: 'weak',
 )
+option(
+  'libstdcxx_debug',
+  type: 'combo',
+  choices: ['auto', 'true', 'false'],
+  description: 'Enable __GLIBCXX_DEBUG by defining it',
+  value: 'auto',
+)