Added backtrace

git-svn: trunk@625
remotes/push_mirror/metadata
Nigel Horne 21 years ago
parent bd2da64a06
commit 81aade769a
  1. 49
      clamav-devel/test/mbox/debugm.c

@ -1,5 +1,7 @@
/*
* $CC $CFLAGS debugm.c -lclamav -lefence (or what ever memory debugger)
* $CC $CFLAGS -I../.. debugm.c -lclamav -lefence (or what ever memory debugger)
* If you're going to use HAVE_BACKTRACE, ensure CFLAGS includes -g and doesn't
* include -fomit-frame-pointer
*
* njh@bandsman.co.uk
*/
@ -11,6 +13,48 @@
#include <malloc.h>
#include <clamav.h>
#include <sys/resource.h>
#include <signal.h>
#include <features.h>
#include "clamav-config.h"
#if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1
/*#define HAVE_BACKTRACE /* Only tested on Linux... */
#endif
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
#endif
static void print_trace(void);
static void sigsegv(int sig);
static void
sigsegv(int sig)
{
signal(SIGSEGV, SIG_DFL);
print_trace();
_exit(SIGSEGV);
}
static void
print_trace(void)
{
#ifdef HAVE_BACKTRACE
void *array[10];
size_t size, i;
char **strings;
puts("Segfault caught, backtrace:");
size = backtrace(array, 10);
strings = backtrace_symbols(array, size);
for(i = 0; i < size; i++)
printf("\t%s\n", strings[i]);
free(strings);
#endif
}
int
main(int argc, char **argv)
@ -29,6 +73,7 @@ main(int argc, char **argv)
perror("/tmp/mboxtest");
return errno;
}
signal(SIGSEGV, sigsegv);
while(*++argv) {
int fd = open(*argv, 0);
@ -42,5 +87,5 @@ main(int argc, char **argv)
}
puts("Finished - don't forget to rm -rf /tmp/mboxtest");
exit(0);
return 0;
}

Loading…
Cancel
Save