Commit 56018f5a authored by Mark Fasheh's avatar Mark Fasheh

Print a stack trace when we abort()

Should make it a little easier to figure out where a crash came from.
Signed-off-by: 's avatarMark Fasheh <mfasheh@suse.de>
parent 540ab9e5
......@@ -23,7 +23,7 @@ glib_CFLAGS=$(shell pkg-config --cflags glib-2.0)
glib_LIBS=$(shell pkg-config --libs glib-2.0)
override CFLAGS += -D_FILE_OFFSET_BITS=64 -DVERSTRING=\"$(RELEASE)\" \
$(crypt_CFLAGS) $(glib_CFLAGS)
$(crypt_CFLAGS) $(glib_CFLAGS) -rdynamic
LIBRARY_FLAGS += $(crypt_LIBS) $(glib_LIBS)
objects = duperemove.o rbtree.o hash-tree.o results-tree.o dedupe.o filerec.o util.o serialize.o btrfs-util.o $(hash_obj)
......
......@@ -63,14 +63,17 @@ void print_mem_stats(void);
#define dprintf(args...) if (debug) printf(args)
#define vprintf(args...) if (verbose) printf(args)
void print_stack_trace(void);/* defined in util.c */
#define abort_lineno() do { \
printf("ERROR: %s:%d\n", __FILE__, __LINE__); \
print_stack_trace(); \
abort(); \
} while (0)
#define abort_on(condition) do { \
if (condition) { \
printf("ERROR: %s:%d\n", __FILE__, __LINE__);\
printf("ERROR: %s:%d\n", __FILE__, __LINE__); \
print_stack_trace(); \
abort(); \
} \
} while(0)
......
......@@ -24,6 +24,7 @@
#include <stdint.h>
#include <ctype.h>
#include <inttypes.h>
#include <execinfo.h>
#include "debug.h"
#include "util.h"
......@@ -127,3 +128,17 @@ void print_mem_stats(void)
show_allocs_filerec();
show_allocs_filerec_token();
}
void print_stack_trace(void)
{
void *trace[16];
char **messages = (char **)NULL;
int i, trace_size = 0;
trace_size = backtrace(trace, 16);
messages = backtrace_symbols(trace, trace_size);
printf("[stack trace follows]\n");
for (i=0; i < trace_size; i++)
printf("%s\n", messages[i]);
free(messages);
}
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