backtrace-string.c revision 45312f52ff3a3d4c137447be4c7556500c2f8bf2
/* Copyright (c) 2006-2009 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "backtrace-string.h"
#define MAX_STACK_SIZE 30
#define STACK_SKIP_COUNT 2
#if defined(HAVE_BACKTRACE_SYMBOLS) && defined(HAVE_EXECINFO_H)
/* Linux */
#include <execinfo.h>
#include <stdlib.h>
{
void *stack[MAX_STACK_SIZE];
char **strings;
int ret, i;
if (ret <= STACK_SKIP_COUNT)
return -1;
for (i = STACK_SKIP_COUNT; i < ret; i++) {
if (i > STACK_SKIP_COUNT)
else {
/* out of memory case */
}
}
return 0;
}
/* Solaris */
#include <ucontext.h>
struct walk_context {
unsigned int pos;
};
void *context)
{
}
return 0;
}
{
struct walk_context ctx;
if (getcontext(&uc) < 0)
return -1;
return 0;
}
#else
{
return -1;
}
#endif
int backtrace_get(const char **backtrace_r)
{
if (backtrace_append(str) < 0)
return -1;
return 0;
}