diff --git a/mdbx.h b/mdbx.h index f5731988..f875fef2 100644 --- a/mdbx.h +++ b/mdbx.h @@ -1567,6 +1567,7 @@ LIBMDBX_API MDBX_oom_func *mdbx_env_get_oomfunc(MDBX_env *env); #define MDBX_DBG_EXTRA 8 #define MDBX_DBG_AUDIT 16 #define MDBX_DBG_JITTER 32 +#define MDBX_DBG_DUMP 64 typedef void MDBX_debug_func(int type, const char *function, int line, const char *msg, va_list args); diff --git a/src/mdbx.c b/src/mdbx.c index 4271cb99..462564db 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -9859,6 +9859,32 @@ int __cold mdbx_reader_check0(MDBX_env *env, int rdt_locked, int *dead) { int __cold mdbx_setup_debug(int flags, MDBX_debug_func *logger) { unsigned ret = mdbx_runtime_flags; mdbx_runtime_flags = flags; + +#ifdef __linux__ + if (flags & MDBX_DBG_DUMP) { + int core_filter_fd = open("/proc/self/coredump_filter", O_TRUNC | O_RDWR); + if (core_filter_fd >= 0) { + char buf[32]; + const unsigned r = pread(core_filter_fd, buf, sizeof(buf), 0); + if (r > 0 && r < sizeof(buf)) { + buf[r] = 0; + unsigned long mask = strtoul(buf, NULL, 16); + if (mask != ULONG_MAX) { + mask |= 1 << 3 /* Dump file-backed shared mappings */; + mask |= 1 << 6 /* Dump shared huge pages */; + mask |= 1 << 8 /* Dump shared DAX pages */; + unsigned w = snprintf(buf, sizeof(buf), "0x%lx\n", mask); + if (w > 0 && w < sizeof(buf)) { + w = pwrite(core_filter_fd, buf, w, 0); + (void)w; + } + } + } + close(core_filter_fd); + } + } +#endif /* __linux__ */ + mdbx_debug_logger = logger; return ret; } diff --git a/test/base.h b/test/base.h index 39e2c357..fe09aa89 100644 --- a/test/base.h +++ b/test/base.h @@ -37,8 +37,11 @@ #if defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS) #include #else +#include #include +#include #include +#include #include #endif diff --git a/test/test.cc b/test/test.cc index 04a1b82e..0874c4bb 100644 --- a/test/test.cc +++ b/test/test.cc @@ -114,7 +114,7 @@ void testcase::db_prepare() { log_trace(">> db_prepare"); assert(!db_guard); - int mdbx_dbg_opts = MDBX_DBG_ASSERT | MDBX_DBG_JITTER; + int mdbx_dbg_opts = MDBX_DBG_ASSERT | MDBX_DBG_JITTER | MDBX_DBG_DUMP; if (config.params.loglevel <= logging::trace) mdbx_dbg_opts |= MDBX_DBG_TRACE; if (config.params.loglevel <= logging::verbose)