Commit 768b2188 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

Merge the backtrace onto the mainline. Refs #2387. [t:2387].

{{{
svn merge -r 18063:18082 https://svn.tokutek.com/tokudb/toku/tokudb.2387
}}}


git-svn-id: file:///svn/toku/tokudb@18084 c7de825b-a66e-492c-adef-691d508d4ae1
parent a242d962
...@@ -81,4 +81,3 @@ check-coverage-range-tree-tests: ...@@ -81,4 +81,3 @@ check-coverage-range-tree-tests:
(cd src/range_tree/tests && $(MAKE) clean && $(MAKE) -k check.lin VGRIND="" OPTFLAGS=-O0 GCOV_FLAGS="-fprofile-arcs -ftest-coverage") (cd src/range_tree/tests && $(MAKE) clean && $(MAKE) -k check.lin VGRIND="" OPTFLAGS=-O0 GCOV_FLAGS="-fprofile-arcs -ftest-coverage")
check-coverage-lock-tree-tests: check-coverage-lock-tree-tests:
(cd src/lock_tree/tests && $(MAKE) clean && $(MAKE) -k check.lin VGRIND="" OPTFLAGS=-O0 GCOV_FLAGS="-fprofile-arcs -ftest-coverage") (cd src/lock_tree/tests && $(MAKE) clean && $(MAKE) -k check.lin VGRIND="" OPTFLAGS=-O0 GCOV_FLAGS="-fprofile-arcs -ftest-coverage")
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
CPPFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE CPPFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
CPPFLAGS += -I../../toku_include -I.. -I. CPPFLAGS += -I../../toku_include -I.. -I.
CFLAGS = -Wall -Werror -g -O0 -std=c99 CFLAGS = -Wall -Werror -g -O0 -std=c99
ifeq ($(GCCVERSION),4.4.2)
CFLAGS += -Wno-deprecated
endif
ifneq ($(GCOV),) ifneq ($(GCOV),)
CFLAGS += -fprofile-arcs -ftest-coverage -DGCOV CFLAGS += -fprofile-arcs -ftest-coverage -DGCOV
endif endif
LDFLAGS = ../libtokuportability.a -lpthread LDFLAGS = ../libtokuportability.a -lpthread
SRCS = $(wildcard test-*.c) SRCS = $(wildcard *.c)
TARGETS = $(patsubst %.c,%,$(SRCS)) TARGETS = $(patsubst %.c,%,$(SRCS))
RUNTARGETS = $(patsubst %,%.tdbrun,$(TARGETS)) RUNTARGETS = $(patsubst %,%.tdbrun,$(TARGETS))
VGRIND = valgrind VGRIND = valgrind
...@@ -19,10 +22,10 @@ HERE=linux/tests ...@@ -19,10 +22,10 @@ HERE=linux/tests
ifeq ($(SUMMARIZE),1) ifeq ($(SUMMARIZE),1)
SUMMARIZE_CMD = ;if test $$? = 0; then printf "%-60sPASS\n" $(HERE)/$@; else printf "%-60sFAIL\n" $(HERE)/$@ ; test 0 = 1; fi SUMMARIZE_CMD = ;if test $$? = 0; then printf "%-60sPASS\n" $(HERE)/$@; else printf "%-60sFAIL\n" $(HERE)/$@ ; test 0 = 1; fi
SUMMARIZE_SHOULD_FAIL= ;if test $$? = 0; then printf "%-60sXFAIL\n" $(HERE)/$@; else printf "%-60sXPASS\n" $(HERE)/$@ ; test 0 = 1; fi SUMMARIZE_SHOULD_FAIL= ;if test $$? = 0; then printf "%-60sXFAIL\n" $(HERE)/$@; else printf "%-60sXPASS\n" $(HERE)/$@ ; test 0 = 1; fi
INVERTER=;test $$? -ne 0
else else
SUMMARIZE_CMD = SUMMARIZE_CMD =
endif endif
INVERTER=;test $$? -ne 0
all: $(TARGETS) all: $(TARGETS)
...@@ -50,6 +53,30 @@ else ...@@ -50,6 +53,30 @@ else
$(SUMMARIZE_CMD) $(SUMMARIZE_CMD)
endif endif
# check to see if that logic makes an error when there is a leak.
try-leak.tdbrun: try-leak
ifeq ($(VGRIND),)
./$< $(SUMMARIZE_CMD)
else
$(VGRIND) --error-exitcode=1 --quiet --leak-check=full --log-file=$<.check.valgrind ./$< >$<.check.output 2>&1; \
if [ $$? = 0 ] ; then \
lines=`cat $<.check.valgrind | wc -l`; \
if [ $$lines -ne 0 ] ; then cat $<.check.valgrind; test 0 = 1; fi \
else \
test 0 = 1; \
fi \
$(INVERTER) \
$(SUMMARIZE_CMD)
endif
try-assert0.tdbrun: try-assert0
./$< 2> /dev/null $(INVERTER) $(SUMMARIZE_CMD)
clean: clean:
rm -rf $(TARGETS) *.check.output *.check.valgrind pwrite4g.data testdir rm -rf $(TARGETS) *.check.output *.check.valgrind pwrite4g.data testdir
try-assert0.tdbrun:
foo:
echo $(TARGETS)
...@@ -59,6 +59,9 @@ ...@@ -59,6 +59,9 @@
toku_os_get_max_process_data_size; toku_os_get_max_process_data_size;
toku_os_get_phys_memory_size; toku_os_get_phys_memory_size;
toku_do_assert;
toku_do_assert_fail;
local: *; local: *;
}; };
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#error NDEBUG should not be set #error NDEBUG should not be set
#endif #endif
void toku_do_assert(int,const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/); void toku_do_assert_fail(const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/) __attribute__((__visibility__("default"))) __attribute__((__noreturn__));
void toku_do_assert(int,const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/) __attribute__((__visibility__("default")));
// Define GCOV if you want to get test-coverage information that ignores the assert statements. // Define GCOV if you want to get test-coverage information that ignores the assert statements.
// #define GCOV // #define GCOV
...@@ -16,7 +17,7 @@ void toku_do_assert(int,const char*/*expr_as_string*/,const char */*fun*/,const ...@@ -16,7 +17,7 @@ void toku_do_assert(int,const char*/*expr_as_string*/,const char */*fun*/,const
#if defined(GCOV) || TOKU_WINDOWS #if defined(GCOV) || TOKU_WINDOWS
#define assert(expr) toku_do_assert((expr) != 0, #expr, __FUNCTION__, __FILE__, __LINE__) #define assert(expr) toku_do_assert((expr) != 0, #expr, __FUNCTION__, __FILE__, __LINE__)
#else #else
#include <assert.h> #define assert(expr) ((expr) ? (void)0 : toku_do_assert_fail(#expr, __FUNCTION__, __FILE__, __LINE__))
#endif #endif
#ifdef GCOV #ifdef GCOV
......
...@@ -4,39 +4,50 @@ ...@@ -4,39 +4,50 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#if !TOKU_WINDOWS
#include <execinfo.h>
#endif
#if !TOKU_WINDOWS
#define N_POINTERS 1000
// These are statically allocated so that the backtrace can run without any calls to malloc()
static void *backtrace_pointers[N_POINTERS];
#endif
void toku_do_assert_fail (const char* expr_as_string,const char *function,const char*file,int line)
{
fprintf(stderr, "%s:%d %s: Assertion `%s' failed\n", file,line,function,expr_as_string);
int toku_continue_on_assert_failure=0; // backtrace
#if !TOKU_WINDOWS
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));
#endif
static void toku_assert_failed_but_continue_anyway (void) __attribute__((noinline)); fflush(stderr);
static void #if TOKU_WINDOWS
toku_assert_failed_but_continue_anyway (void) { //Following commented methods will not always end the process (could hang).
printf("Assertion failed, but continuing anyway\n"); //They could be unacceptable for other reasons as well (popups,
//flush buffers before quitting, etc)
// abort()
// assert(FALSE) (assert.h assert)
// raise(SIGABRT)
// divide by 0
// null dereference
// _exit
// exit
// ExitProcess
TerminateProcess(GetCurrentProcess(), 134); //Only way found so far to unconditionally
//Terminate the process
#endif
abort();
} }
void toku_do_assert(int expr,const char* expr_as_string,const char *function,const char*file,int line) { void toku_do_assert(int expr,const char* expr_as_string,const char *function,const char*file,int line) {
if (expr==0) { if (expr==0) {
fprintf(stderr, "%s:%d %s: Assertion `%s' failed\n", file,line,function,expr_as_string); toku_do_assert_fail(expr_as_string, function, file, line);
if (!toku_continue_on_assert_failure) {
fflush(stderr);
#if TOKU_WINDOWS
//Following commented methods will not always end the process (could hang).
//They could be unacceptable for other reasons as well (popups,
//flush buffers before quitting, etc)
// abort()
// assert(FALSE) (assert.h assert)
// raise(SIGABRT)
// divide by 0
// null dereference
// _exit
// exit
// ExitProcess
TerminateProcess(GetCurrentProcess(), 134); //Only way found so far to unconditionally
//Terminate the process
#endif
abort();
}
else
toku_assert_failed_but_continue_anyway();
} }
} }
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