diff options
author | Ismael Luceno <ismael@iodev.co.uk> | 2021-12-28 12:12:13 +0100 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2022-01-06 17:33:15 +0100 |
commit | 7c0a4e7ca36b93df4968182f92b3d52fd4d1bb01 (patch) | |
tree | f961e527926947e6eb98bf63f532eb58197c81a1 /sal | |
parent | b65a0aadba3cba51c9ec4f543219351dfdb4bb6c (diff) |
Add configure test for the backtrace implementation
Improve robustness by testing explicitly; instead of assuming based on
the OS, test first the libc and then test for libexecinfo.
The assumption was wrong for FreeBSD (included since 2017) and for
musl-based systems (not in libc).
Also, remove INCLUDE_BACKTRACE and clean up a bit.
Ref: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=220271
Change-Id: Ib4b7fd4fe2cdf5f76babe47a21bd2990fcf42649
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127538
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
(cherry picked from commit c1be12396088563ed77ed61e54fd4e153469701d)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127767
Reviewed-by: Ismael Luceno <ismael@iodev.co.uk>
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/Library_sal.mk | 2 | ||||
-rw-r--r-- | sal/osl/unx/backtrace.c | 20 | ||||
-rw-r--r-- | sal/osl/unx/backtrace.h | 13 | ||||
-rw-r--r-- | sal/osl/unx/signal.cxx | 32 |
4 files changed, 23 insertions, 44 deletions
diff --git a/sal/Library_sal.mk b/sal/Library_sal.mk index f7c7b3ab1764..03ca93f673b8 100644 --- a/sal/Library_sal.mk +++ b/sal/Library_sal.mk @@ -19,6 +19,7 @@ $(eval $(call gb_Library_set_is_ure_library,sal)) $(eval $(call gb_Library_set_include,sal,\ $$(INCLUDE) \ -I$(SRCDIR)/sal/inc \ + $(BACKTRACE_CFLAGS) \ )) $(eval $(call gb_Library_add_defs,sal,\ @@ -71,6 +72,7 @@ $(eval $(call gb_Library_add_libs,sal,\ $(if $(filter HAIKU,$(OS)), \ -lnetwork \ ) \ + $(BACKTRACE_LIBS) \ )) ifeq ($(OS),MACOSX) diff --git a/sal/osl/unx/backtrace.c b/sal/osl/unx/backtrace.c index 26005f7715af..f7bd01c334aa 100644 --- a/sal/osl/unx/backtrace.c +++ b/sal/osl/unx/backtrace.c @@ -17,16 +17,19 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include "backtrace.h" + +#if ! HAVE_FEATURE_BACKTRACE /* no GNU backtrace implementation available */ + #include <sal/types.h> -#ifdef __sun +#ifdef __sun /* Solaris */ #include <dlfcn.h> #include <pthread.h> #include <setjmp.h> #include <stdio.h> #include <sys/frame.h> -#include "backtrace.h" #if defined(SPARC) @@ -140,7 +143,12 @@ void backtrace_symbols_fd( void **buffer, int size, int fd ) #include <setjmp.h> #include <stddef.h> #include <stdio.h> -#include "backtrace.h" + +/* no frame.h on FreeBSD */ +struct frame { + struct frame *fr_savfp; + long fr_savpc; +}; #if defined(POWERPC) || defined(POWERPC64) @@ -212,7 +220,7 @@ void backtrace_symbols_fd( void **buffer, int size, int fd ) } } -#elif !defined LINUX && !defined MACOSX && !defined IOS +#else /* not GNU/BSD/Solaris */ int backtrace( void **buffer, int max_frames ) { @@ -231,6 +239,8 @@ void backtrace_symbols_fd( void **buffer, int size, int fd ) (void)buffer; (void)size; (void)fd; } -#endif +#endif /* not GNU/BSD/Solaris */ + +#endif /* ! HAVE_FEATURE_BACKTRACE */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/osl/unx/backtrace.h b/sal/osl/unx/backtrace.h index 5fafc1c90622..11a9da52efc0 100644 --- a/sal/osl/unx/backtrace.h +++ b/sal/osl/unx/backtrace.h @@ -20,7 +20,9 @@ #ifndef INCLUDED_SAL_OSL_UNX_BACKTRACE_H #define INCLUDED_SAL_OSL_UNX_BACKTRACE_H -#if defined (LINUX) +#include <config_features.h> + +#if HAVE_FEATURE_BACKTRACE /* GNU backtrace implementation available */ #include <execinfo.h> @@ -38,15 +40,6 @@ char ** backtrace_symbols(void * const * buffer, int size); void backtrace_symbols_fd( void **buffer, int size, int fd ); -/* no frame.h on FreeBSD */ -#if defined (FREEBSD) || defined (NETBSD) || defined (OPENBSD) || \ - defined (DRAGONFLY) -struct frame { - struct frame *fr_savfp; - long fr_savpc; -}; -#endif - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/sal/osl/unx/signal.cxx b/sal/osl/unx/signal.cxx index 79721def6c5e..91cf59ff1db1 100644 --- a/sal/osl/unx/signal.cxx +++ b/sal/osl/unx/signal.cxx @@ -27,31 +27,9 @@ /* system headers */ #include "system.hxx" -#if defined( MACOSX ) - -#if defined( INTEL ) -#include "backtrace.h" -#define INCLUDE_BACKTRACE -#endif /* INTEL */ - -#endif /* MACOSX */ - -#ifdef LINUX -#include <execinfo.h> -#include <link.h> -#define INCLUDE_BACKTRACE -#endif - -#ifdef __sun - #include "backtrace.h" -#define INCLUDE_BACKTRACE - -#endif /* defined __sun */ -#if defined INCLUDE_BACKTRACE #define MAX_STACK_FRAMES 256 -#endif #include <osl/diagnose.h> #include <osl/signal.h> @@ -304,24 +282,20 @@ namespace { void printStack(int sig) { -#ifdef INCLUDE_BACKTRACE void *buffer[MAX_STACK_FRAMES]; int size = backtrace( buffer, SAL_N_ELEMENTS(buffer) ); -#endif fprintf( stderr, "\n\nFatal exception: Signal %d\n", sig ); -#if defined( MACOSX ) && !defined( INCLUDE_BACKTRACE ) +#if ! HAVE_FEATURE_BACKTRACE && defined( MACOSX ) && !defined( INTEL ) fprintf( stderr, "Please turn on Enable Crash Reporting and\nAutomatic Display of Crashlogs in the Console application\n" ); -#else -#ifdef INCLUDE_BACKTRACE +#endif + if ( size > 0 ) { fputs( "Stack:\n", stderr ); backtrace_symbols_fd( buffer, size, fileno(stderr) ); } -#endif -#endif } void callSystemHandler(int signal, siginfo_t * info, void * context) |