Files
epics-base/modules/libcom/src/osi/os/posix/osdExecinfoBackTrace.cpp
Érico Nogueira 7c4a21eab4 libCom: detect support for backtrace() with __has_include.
This is necessary in order to build epics-base with musl libc, for
example, and any other C libraries which don't include this
functionality. In order to not regress builds with older compilers, we
still support the uclibc check. Furthermore, it has been checked that
uclibc-ng (the maintained version of uclibc) doesn't install the
<execinfo.h> header when the functionality is disabled [1] [2].

To avoid repetition, we don't define HAS_EXECINFO to 0 when it is not
available.

[1] https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/Makefile.in?id=cdb07d2cd52af39feb425e6d36c02b30916b9f0a#n224
[2] https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/Makefile.in?id=cdb07d2cd52af39feb425e6d36c02b30916b9f0a#n277
2023-09-21 08:18:49 -07:00

40 lines
918 B
C++

/*
* Copyright: Stanford University / SLAC National Laboratory.
*
* SPDX-License-Identifier: EPICS
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* Author: Till Straumann <strauman@slac.stanford.edu>, 2011, 2014
*/
// pull in libc feature test macros
#include <stdlib.h>
// execinfo.h may not be present if uclibc is configured to omit backtrace()
// some C libraries, such as musl, don't have execinfo.h at all
#if defined(__has_include)
# if __has_include(<execinfo.h>)
# define HAS_EXECINFO 1
# endif
#elif !defined(__UCLIBC_MAJOR__) || defined(__UCLIBC_HAS_EXECINFO__)
# define HAS_EXECINFO 1
#endif
#if HAS_EXECINFO
#include <execinfo.h>
#endif
#include "epicsStackTracePvt.h"
int epicsBackTrace(void **buf, int buf_sz)
{
#if HAS_EXECINFO
return backtrace(buf, buf_sz);
#else
return -1;
#endif
}