[Libreoffice-commits] core.git: Branch 'aoo/trunk' - 2 commits - sal/osl

Damjan Jovanovic damjan at apache.org
Thu Nov 26 12:08:20 PST 2015


 sal/osl/unx/backtrace.c |    2 +-
 sal/osl/unx/backtrace.h |    2 --
 sal/osl/unx/diagnose.c  |   42 +++++++++++++++++++++++++++++++++++++-----
 3 files changed, 38 insertions(+), 8 deletions(-)

New commits:
commit 87451f66edfa425e51289ac6f12ee110d7109a02
Author: Damjan Jovanovic <damjan at apache.org>
Date:   Thu Nov 26 19:02:59 2015 +0000

    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

diff --git a/sal/osl/unx/backtrace.c b/sal/osl/unx/backtrace.c
index 2e57fb6..1b0b8a8 100644
--- a/sal/osl/unx/backtrace.c
+++ b/sal/osl/unx/backtrace.c
@@ -143,7 +143,7 @@ void backtrace_symbols_fd( void **buffer, int size, int fd )
 #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 )
diff --git a/sal/osl/unx/diagnose.c b/sal/osl/unx/diagnose.c
index b1bcb0d..0f05fbe 100644
--- a/sal/osl/unx/diagnose.c
+++ b/sal/osl/unx/diagnose.c
@@ -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 (oslDebugMessageFunc f)
     }
 }
 
-#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 */
commit 0faee39deac292694d036d753b7dc1c4513e045f
Author: Damjan Jovanovic <damjan at apache.org>
Date:   Thu Nov 26 18:33:01 2015 +0000

    Fix the stack frame layout for backtraces on FreeBSD.
    
    Patch by: me

diff --git a/sal/osl/unx/backtrace.h b/sal/osl/unx/backtrace.h
index 29bf3e0..a3667e6 100644
--- a/sal/osl/unx/backtrace.h
+++ b/sal/osl/unx/backtrace.h
@@ -37,8 +37,6 @@ void backtrace_symbols_fd( void **buffer, int size, int fd );
 /* no frame.h on FreeBSD */
 #if defined FREEBSD
 struct frame {
-    long    arg0[8];
-    long    arg1[6];
     struct frame *fr_savfp;
     long    fr_savpc;
 };


More information about the Libreoffice-commits mailing list