mdbx: add MDBX_DBG_DUMP for mdbx_setup_debug().

So, meta-pages and lck-section now will be included into a coredump.
This commit is contained in:
Leo Yuriev 2017-06-15 04:06:07 +03:00
parent 2392c70e2b
commit 71e2fe3df0
4 changed files with 31 additions and 1 deletions

1
mdbx.h
View File

@ -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);

View File

@ -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;
}

View File

@ -37,8 +37,11 @@
#if defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS)
#include <io.h>
#else
#include <fcntl.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#endif

View File

@ -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)