Implement a backtrace handler which displays a backtrace in case of Segmentation Fault
This commit is contained in:
parent
1176487045
commit
6825cb0c06
@ -15,9 +15,9 @@
|
|||||||
# this program; if not, write to the Free Software Foundation, Inc.,
|
# this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
AM_CPPFLAGS = -I$(top_srcdir)/src/include -I$(top_builddir)/src/include
|
AM_CPPFLAGS = -I$(top_srcdir)/src/include -I$(top_builddir)/src/include -rdynamic
|
||||||
|
|
||||||
LDFLAGS += $(SQLITE_LIBS) -lpthread
|
LDFLAGS += $(SQLITE_LIBS) -lpthread -rdynamic
|
||||||
|
|
||||||
bin_PROGRAMS = distromatic
|
bin_PROGRAMS = distromatic
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#if HAVE_UNISTD_H
|
#if HAVE_UNISTD_H
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
@ -193,6 +194,26 @@ program_version(void) {
|
|||||||
printf("%s\n", freelicense[linenum]);
|
printf("%s\n", freelicense[linenum]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Obtain a backtrace and print it to stdout. */
|
||||||
|
void backtraceHandler(int sig)
|
||||||
|
{
|
||||||
|
void *array[10];
|
||||||
|
size_t size;
|
||||||
|
char **strings;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
size = backtrace (array, 10);
|
||||||
|
strings = (char**)backtrace_symbols (array, size);
|
||||||
|
|
||||||
|
printf ("Obtained %zd stack frames.\n", size);
|
||||||
|
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
printf ("%s\n", strings[i]);
|
||||||
|
|
||||||
|
free (strings);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* checks if given single requirement is met by given provides
|
* checks if given single requirement is met by given provides
|
||||||
*
|
*
|
||||||
@ -1165,6 +1186,9 @@ main(int argc, char *argv[])
|
|||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// install backtrace handler
|
||||||
|
signal(SIGSEGV, backtraceHandler);
|
||||||
|
|
||||||
start_time=time(NULL);
|
start_time=time(NULL);
|
||||||
|
|
||||||
opterr = 1;
|
opterr = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user