Commit 30818c79 authored by Leif Walsh's avatar Leif Walsh

Merge branch 'backtrace-errfile'

Conflicts:
	buildheader/make_tdb.cc
	portability/toku_assert.cc
	src/ydb.cc
parents e841d460 1b92856c
......@@ -464,6 +464,7 @@ static void print_db_env_struct (void) {
"void (*set_loader_memory_size)(DB_ENV *env, uint64_t (*get_loader_memory_size_callback)(void))",
"uint64_t (*get_loader_memory_size)(DB_ENV *env)",
"void (*set_killed_callback)(DB_ENV *env, uint64_t default_killed_time_msec, uint64_t (*get_killed_time_callback)(uint64_t default_killed_time_msec), int (*killed_callback)(void))",
"void (*env_do_backtrace) (DB_ENV *env)",
NULL};
sort_and_dump_fields("db_env", true, extra);
......@@ -855,7 +856,6 @@ int main (int argc, char *const argv[] __attribute__((__unused__))) {
printf("void db_env_set_num_bucket_mutexes(uint32_t) %s;\n", VISIBLE);
printf("int db_env_set_toku_product_name(const char*) %s;\n", VISIBLE);
printf("void db_env_try_gdb_stack_trace(const char *gdb_path) %s;\n", VISIBLE);
printf("void db_env_do_backtrace(void) %s;\n", VISIBLE);
printf("#if defined(__cplusplus) || defined(__cilkplusplus)\n}\n#endif\n");
printf("#endif\n");
......
......@@ -133,29 +133,28 @@ void toku_assert_set_fpointers(int (*toku_maybe_get_engine_status_text_pointer)(
bool toku_gdb_dump_on_assert = false;
void (*do_assert_hook)(void) = NULL;
extern "C" void db_env_do_backtrace(void) __attribute__((__visibility__("default"))); // also declared in db.h for consumers of that API
extern "C" void db_env_do_backtrace(void) {
void db_env_do_backtrace(FILE *outf) {
// backtrace
int n = backtrace(backtrace_pointers, N_POINTERS);
fprintf(stderr, "Backtrace: (Note: toku_do_assert=0x%p)\n", toku_do_assert); fflush(stderr);
backtrace_symbols_fd(backtrace_pointers, n, fileno(stderr));
fprintf(outf, "Backtrace: (Note: toku_do_assert=0x%p)\n", toku_do_assert); fflush(outf);
backtrace_symbols_fd(backtrace_pointers, n, fileno(outf));
fflush(stderr);
fflush(outf);
if (engine_status_num_rows && toku_maybe_get_engine_status_text_p) {
int buffsize = engine_status_num_rows * 128; // assume 128 characters per row (gross overestimate, should be safe)
char buff[buffsize];
toku_maybe_get_engine_status_text_p(buff, buffsize);
fprintf(stderr, "Engine status:\n%s\n", buff);
fprintf(outf, "Engine status:\n%s\n", buff);
} else {
fprintf(outf, "Engine status function not available\n");
}
else
fprintf(stderr, "Engine status function not available\n");
fprintf(stderr, "Memory usage:\n");
fflush(stderr); // just in case malloc_stats() crashes, we still want engine status (and to know that malloc_stats() failed)
fprintf(outf, "Memory usage:\n");
fflush(outf); // just in case malloc_stats() crashes, we still want engine status (and to know that malloc_stats() failed)
if (malloc_stats_f) {
malloc_stats_f();
}
fflush(stderr);
fflush(outf);
if (do_assert_hook) do_assert_hook();
if (toku_gdb_dump_on_assert) {
......@@ -165,7 +164,7 @@ extern "C" void db_env_do_backtrace(void) {
__attribute__((noreturn))
static void toku_do_backtrace_abort(void) {
db_env_do_backtrace();
db_env_do_backtrace(stderr);
abort();
}
......
......@@ -98,6 +98,7 @@ PATENT RIGHTS GRANT:
#include <stdint.h>
#include <errno.h>
#include <stdio.h>
#ifdef NDEBUG
#error NDEBUG should not be set
......@@ -133,6 +134,7 @@ void toku_do_assert_expected_fail(uintptr_t/*expr*/, uintptr_t /*expected*/, con
// #define GCOV
extern void (*do_assert_hook)(void); // Set this to a function you want called after printing the assertion failure message but before calling abort(). By default this is NULL.
void db_env_do_backtrace(FILE *outf);
#ifdef assert
# undef assert
......
......@@ -2467,6 +2467,14 @@ static void env_set_killed_callback(DB_ENV *env, uint64_t default_killed_time_ms
env->i->killed_callback = killed_callback;
}
static void env_do_backtrace(DB_ENV *env) {
if (env->i->errfile) {
db_env_do_backtrace(env->i->errfile);
} else {
db_env_do_backtrace(stderr);
}
}
static int
toku_env_create(DB_ENV ** envp, uint32_t flags) {
int r = ENOSYS;
......@@ -2543,6 +2551,7 @@ toku_env_create(DB_ENV ** envp, uint32_t flags) {
USENV(set_loader_memory_size);
USENV(get_loader_memory_size);
USENV(set_killed_callback);
USENV(do_backtrace);
#undef USENV
// unlocked methods
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment