From: Brian Norris Date: Thu, 13 Sep 2012 21:47:23 +0000 (-0700) Subject: common: add print_trace() for backtracing X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=70515e16c177a40e1053285262ff34e10c33e57e;p=c11tester.git common: add print_trace() for backtracing --- diff --git a/Makefile b/Makefile index 2bd61ce2..f6a0837e 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,9 @@ include common.mk OBJECTS = libthreads.o schedule.o model.o threads.o librace.o action.o \ nodestack.o clockvector.o main.o snapshot-interface.o cyclegraph.o \ datarace.o impatomic.o cmodelint.o \ - snapshot.o malloc.o mymemory.o + snapshot.o malloc.o mymemory.o common.o -CPPFLAGS += -Iinclude -I. +CPPFLAGS += -Iinclude -I. -rdynamic LDFLAGS = -ldl -lrt SHARED = -shared diff --git a/common.cc b/common.cc new file mode 100644 index 00000000..8cb649bb --- /dev/null +++ b/common.cc @@ -0,0 +1,25 @@ +#include +#include +#include + +#include "common.h" + +#define MAX_TRACE_LEN 100 + +/** Print a backtrace of the current program state. */ +void print_trace(void) +{ + void *array[MAX_TRACE_LEN]; + char **strings; + int size, i; + + size = backtrace(array, MAX_TRACE_LEN); + strings = backtrace_symbols(array, size); + + printf("\nDumping stack trace (%d frames):\n", size); + + for (i = 0; i < size; i++) + printf("\t%s\n", strings[i]); + + free(strings); +} diff --git a/common.h b/common.h index 017cb4f9..80bc9ad6 100644 --- a/common.h +++ b/common.h @@ -28,4 +28,6 @@ do { \ #define error_msg(...) fprintf(stderr, "Error: " __VA_ARGS__) +void print_trace(void); + #endif /* __COMMON_H__ */