Commit a7782ac5 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Make test for backtrace more robust.

parent 928ae460
......@@ -164,6 +164,7 @@ interfaces/testdata/mulval.grb -text
interfaces/testdata/mulval.nc -text
m4/acx_assert_lang_is_fortran_variant.m4 -text
m4/acx_check_strptr_convert.m4 -text
m4/acx_execinfo.m4 -text
m4/acx_lang_other_suffix_conftest.m4 -text
m4/acx_options.m4 -text
m4/acx_sl_fc_mod_path_flag.m4 -text
......
......@@ -97,6 +97,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = \
$(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \
$(top_srcdir)/m4/acx_check_strptr_convert.m4 \
$(top_srcdir)/m4/acx_execinfo.m4 \
$(top_srcdir)/m4/acx_lang_other_suffix_conftest.m4 \
$(top_srcdir)/m4/acx_options.m4 \
$(top_srcdir)/m4/acx_sl_fc_mod_path_flag.m4 \
......
......@@ -1185,6 +1185,7 @@ AC_SUBST([am__untar])
m4_include([m4/acx_assert_lang_is_fortran_variant.m4])
m4_include([m4/acx_check_strptr_convert.m4])
m4_include([m4/acx_execinfo.m4])
m4_include([m4/acx_lang_other_suffix_conftest.m4])
m4_include([m4/acx_options.m4])
m4_include([m4/acx_sl_fc_mod_path_flag.m4])
......
......@@ -90,6 +90,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = \
$(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \
$(top_srcdir)/m4/acx_check_strptr_convert.m4 \
$(top_srcdir)/m4/acx_execinfo.m4 \
$(top_srcdir)/m4/acx_lang_other_suffix_conftest.m4 \
$(top_srcdir)/m4/acx_options.m4 \
$(top_srcdir)/m4/acx_sl_fc_mod_path_flag.m4 \
......
......@@ -24326,7 +24326,7 @@ fi
 
# ----------------------------------------------------------------------
# Checks for header files
for ac_header in malloc.h execinfo.h uuid.h uuid/uuid.h
for ac_header in malloc.h uuid.h uuid/uuid.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
......@@ -24339,6 +24339,134 @@ fi
 
done
 
for ac_header in execinfo.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "execinfo.h" "ac_cv_header_execinfo_h" "$ac_includes_default"
if test "x$ac_cv_header_execinfo_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_EXECINFO_H 1
_ACEOF
fi
done
if test x"$ac_cv_header_execinfo_h" = xyes; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size parameter type for backtrace()" >&5
$as_echo_n "checking size parameter type for backtrace()... " >&6; }
if ${ax_cv_proto_backtrace_type+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
for ax_cv_proto_backtrace_type in size_t int none; do
if test "${ax_cv_proto_backtrace_type}" = none; then :
ax_cv_proto_backtrace_type= ; break
fi
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <execinfo.h>
extern
${ax_cv_proto_backtrace_type} backtrace(void **addrlist, ${ax_cv_proto_backtrace_type} len);
char **backtrace_symbols(void *const *buffer, ${ax_cv_proto_backtrace_type} size);
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
break
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
done
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_proto_backtrace_type" >&5
$as_echo "$ax_cv_proto_backtrace_type" >&6; }
fi
if test x${ax_cv_proto_backtrace_type} != x; then :
cat >>confdefs.h <<_ACEOF
#define backtrace_size_t $ax_cv_proto_backtrace_type
_ACEOF
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing backtrace" >&5
$as_echo_n "checking for library containing backtrace... " >&6; }
if ${ac_cv_search_backtrace+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char backtrace ();
int
main ()
{
return backtrace ();
;
return 0;
}
_ACEOF
for ac_lib in '' execinfo; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_backtrace=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if ${ac_cv_search_backtrace+:} false; then :
break
fi
done
if ${ac_cv_search_backtrace+:} false; then :
else
ac_cv_search_backtrace=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_backtrace" >&5
$as_echo "$ac_cv_search_backtrace" >&6; }
ac_res=$ac_cv_search_backtrace
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
fi
if test x"${ax_cv_proto_backtrace_type}" != x -a x"$ac_cv_header_execinfo_h" = xyes -a x"$ac_cv_search_backtrace" != xno; then :
$as_echo "#define HAVE_BACKTRACE 1" >>confdefs.h
fi
# ----------------------------------------------------------------------
# Checks for the availability of functions
for ac_func in mallinfo
......
......@@ -64,7 +64,8 @@ AC_CHECK_LIB(malloc, malloc)
AC_CHECK_MEMBERS([struct stat.st_blksize])
# ----------------------------------------------------------------------
# Checks for header files
AC_CHECK_HEADERS([malloc.h execinfo.h uuid.h uuid/uuid.h])
AC_CHECK_HEADERS([malloc.h uuid.h uuid/uuid.h])
AX_EXECINFO
# ----------------------------------------------------------------------
# Checks for the availability of functions
AC_CHECK_FUNCS([mallinfo])
......
......@@ -90,6 +90,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = \
$(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \
$(top_srcdir)/m4/acx_check_strptr_convert.m4 \
$(top_srcdir)/m4/acx_execinfo.m4 \
$(top_srcdir)/m4/acx_lang_other_suffix_conftest.m4 \
$(top_srcdir)/m4/acx_options.m4 \
$(top_srcdir)/m4/acx_sl_fc_mod_path_flag.m4 \
......
......@@ -91,6 +91,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = \
$(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \
$(top_srcdir)/m4/acx_check_strptr_convert.m4 \
$(top_srcdir)/m4/acx_execinfo.m4 \
$(top_srcdir)/m4/acx_lang_other_suffix_conftest.m4 \
$(top_srcdir)/m4/acx_options.m4 \
$(top_srcdir)/m4/acx_sl_fc_mod_path_flag.m4 \
......
......@@ -97,6 +97,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = \
$(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \
$(top_srcdir)/m4/acx_check_strptr_convert.m4 \
$(top_srcdir)/m4/acx_execinfo.m4 \
$(top_srcdir)/m4/acx_lang_other_suffix_conftest.m4 \
$(top_srcdir)/m4/acx_options.m4 \
$(top_srcdir)/m4/acx_sl_fc_mod_path_flag.m4 \
......
#
# SYNOPSIS
#
# AX_EXECINFO([ACTION-IF-EXECINFO-H-IS-FOUND],
# [ACTION-IF-EXECINFO-H-IS-NOT-FOUND],
# [ADDITIONAL-TYPES-LIST])
#
#
# DESCRIPTION
#
# Checks for execinfo.h header and if the len parameter/return type can
# be found from a list, also define backtrace_size_t to that type.
#
# By default the list of types to try contains int and size_t, but should
# some yet undiscovered system use e.g. unsigned, the 3rd argument can be
# used for extensions. I'd like to hear of further suggestions.
#
# Executes ACTION-IF-EXECINFO-H-IS-FOUND when present and the execinfo.h
# header is found or ACTION-IF-EXECINFO-H-IS-NOT-FOUND in case the header
# seems unavailable.
#
# Also adds -lexecinfo to LIBS on BSD if needed.
#
# LICENSE
#
# Copyright (c) 2014 Thomas Jahns <jahns@dkrz.de>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
AC_DEFUN([AX_EXECINFO],
[AC_CHECK_HEADERS([execinfo.h])
AS_IF([test x"$ac_cv_header_execinfo_h" = xyes],
[AC_CACHE_CHECK([size parameter type for backtrace()],
[ax_cv_proto_backtrace_type],
[AC_LANG_PUSH([C])
for ax_cv_proto_backtrace_type in size_t int m4_ifnblank([$3],[$3 ])none; do
AS_IF([test "${ax_cv_proto_backtrace_type}" = none],
[ax_cv_proto_backtrace_type= ; break])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#include <execinfo.h>
extern
${ax_cv_proto_backtrace_type} backtrace(void **addrlist, ${ax_cv_proto_backtrace_type} len);
char **backtrace_symbols(void *const *buffer, ${ax_cv_proto_backtrace_type} size);
])],
[break])
done
AC_LANG_POP([C])])])
AS_IF([test x${ax_cv_proto_backtrace_type} != x],
[AC_DEFINE_UNQUOTED([backtrace_size_t], [$ax_cv_proto_backtrace_type],
[Defined to return type of backtrace().])])
AC_SEARCH_LIBS([backtrace],[execinfo])
AS_IF([test x"${ax_cv_proto_backtrace_type}" != x -a x"$ac_cv_header_execinfo_h" = xyes -a x"$ac_cv_search_backtrace" != xno],
[AC_DEFINE([HAVE_BACKTRACE],[1],
[Defined if backtrace() could be fully identified.])
]m4_ifnblank([$1],[$1
]),m4_ifnblank([$2],[$2
]))])
dnl
dnl Local Variables:
dnl mode: autoconf
dnl End:
dnl
......@@ -99,6 +99,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = \
$(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \
$(top_srcdir)/m4/acx_check_strptr_convert.m4 \
$(top_srcdir)/m4/acx_execinfo.m4 \
$(top_srcdir)/m4/acx_lang_other_suffix_conftest.m4 \
$(top_srcdir)/m4/acx_options.m4 \
$(top_srcdir)/m4/acx_sl_fc_mod_path_flag.m4 \
......
......@@ -9,6 +9,9 @@
/* Compiler version */
#undef COMP_VERSION
/* Defined if backtrace() could be fully identified. */
#undef HAVE_BACKTRACE
/* Define if C / Fortran interface cfortran.h works */
#undef HAVE_CF_INTERFACE
......@@ -254,3 +257,6 @@
/* Define for large files, on AIX-style hosts. */
#undef _LARGE_FILES
/* Defined to return type of backtrace(). */
#undef backtrace_size_t
......@@ -17,15 +17,14 @@
static
void show_stackframe()
{
#if defined (HAVE_EXECINFO_H)
#if defined HAVE_EXECINFO_H && defined backtrace_size_t && defined HAVE_BACKTRACE
void *trace[16];
size_t i;
size_t trace_size = backtrace(trace, 16);
backtrace_size_t trace_size = backtrace(trace, 16);
char **messages = backtrace_symbols(trace, trace_size);
fprintf(stderr, "[bt] Execution path:\n");
if ( messages ) {
for ( i = 0; i < trace_size; ++i )
for ( backtrace_size_t i = 0; i < trace_size; ++i )
fprintf(stderr, "[bt] %s\n", messages[i]);
free(messages);
}
......
......@@ -110,6 +110,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = \
$(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \
$(top_srcdir)/m4/acx_check_strptr_convert.m4 \
$(top_srcdir)/m4/acx_execinfo.m4 \
$(top_srcdir)/m4/acx_lang_other_suffix_conftest.m4 \
$(top_srcdir)/m4/acx_options.m4 \
$(top_srcdir)/m4/acx_sl_fc_mod_path_flag.m4 \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment