Author: damjan Date: Thu Nov 26 19:02:59 2015 New Revision: 1716759 URL: http://svn.apache.org/viewvc?rev=1716759&view=rev Log: Implement osl_diagnose_backtrace_Impl() on FreeBSD. Also fix the value of FRAME_PTR_OFFSET in both backtrace.c and diagnose.c - it's 3 because of the EBP/RBP register's position in the jmp_buf (https://github.com/freebsd/freebsd/blob/master/lib/libc/amd64/gen/_setjmp.S and https://github.com/freebsd/freebsd/blob/master/lib/libc/i386/gen/_setjmp.S). This gets backtracing to fully work on FreeBSD.
Patch by: me Modified: openoffice/trunk/main/sal/osl/unx/backtrace.c openoffice/trunk/main/sal/osl/unx/diagnose.c Modified: openoffice/trunk/main/sal/osl/unx/backtrace.c URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/osl/unx/backtrace.c?rev=1716759&r1=1716758&r2=1716759&view=diff ============================================================================== --- openoffice/trunk/main/sal/osl/unx/backtrace.c (original) +++ openoffice/trunk/main/sal/osl/unx/backtrace.c Thu Nov 26 19:02:59 2015 @@ -143,7 +143,7 @@ void backtrace_symbols_fd( void **buffer #include <stdio.h> #include "backtrace.h" -#define FRAME_PTR_OFFSET 1 +#define FRAME_PTR_OFFSET 3 #define FRAME_OFFSET 0 int backtrace( void **buffer, int max_frames ) Modified: openoffice/trunk/main/sal/osl/unx/diagnose.c URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/osl/unx/diagnose.c?rev=1716759&r1=1716758&r2=1716759&view=diff ============================================================================== --- openoffice/trunk/main/sal/osl/unx/diagnose.c (original) +++ openoffice/trunk/main/sal/osl/unx/diagnose.c Thu Nov 26 19:02:59 2015 @@ -26,9 +26,9 @@ #ifndef HAVE_DLFCN_H -#if defined(LINUX) || defined(SOLARIS) +#if defined(LINUX) || defined(SOLARIS) || defined(FREEBSD) #define HAVE_DLFCN_H -#endif /* LINUX || SOLARIS */ +#endif /* LINUX || SOLARIS || FREEBSD */ #endif /* HAVE_DLFCN_H */ @@ -73,7 +73,7 @@ static void osl_diagnose_backtrace_Impl #define OSL_DIAGNOSE_OUTPUTMESSAGE(f, s) \ ((f != 0) ? (*(f))((s)) : (void)fprintf(stderr, "%s", (s))) -#if defined (LINUX) || defined (SOLARIS) +#if defined (LINUX) || defined (SOLARIS) || defined(FREEBSD) /************************************************************************/ /* osl_diagnose_frame_Impl */ /************************************************************************/ @@ -194,14 +194,46 @@ static void osl_diagnose_backtrace_Impl } } -#else /* (LINUX || SOLARIS) */ +#elif defined(FREEBSD) + +#include <setjmp.h> +#include "backtrace.h" /* for struct frame */ + +#if defined(X86) || defined(X86_64) + +#define FRAME_PTR_OFFSET 3 +#define FRAME_OFFSET 0 + +#endif /* (X86 || X86_64) */ + +static void osl_diagnose_backtrace_Impl (oslDebugMessageFunc f) +{ + struct frame * fp; + jmp_buf ctx; + int i; + + setjmp (ctx); + fp = (struct frame*)(((long*)(ctx))[FRAME_PTR_OFFSET]); + + for (i = 0; (i < FRAME_OFFSET) && (fp != 0); i++) + fp = fp->fr_savfp; + + for (i = 0; (fp != 0) && (fp->fr_savpc != 0); i++) + { + struct frame * prev = fp->fr_savfp; + osl_diagnose_frame_Impl (f, i, (void*)(fp->fr_savpc)); + fp = (prev > fp) ? prev : 0; + } +} + +#else /* (LINUX || SOLARIS || FREEBSD) */ static void osl_diagnose_backtrace_Impl (oslDebugMessageFunc f) { /* not yet implemented */ } -#endif /* (LINUX || SOLARIS) */ +#endif /* (LINUX || SOLARIS || FREEBSD) */ /************************************************************************/ /* osl_assertFailedLine */