mirror of
https://github.com/tobast/libunwind-eh_elf.git
synced 2024-11-22 15:47:37 +01:00
Change test-varargs to check libunwind backtracing
test-varargs is checking how `backtrace()' provided by the system behaves when varargs are used. Let's make the test more useful by changing it to test the `backtrace()' provided by libunwind. Change the testcase to return 0/1 for success/failure, and add it to the set of checks, so that it gets run on `make check'. Also call `unw_backtrace()' explicitly so that we do not need to bother with `execinfo.h' and `backtrace()' prototype.
This commit is contained in:
parent
ffbe29940e
commit
8203c955c8
3 changed files with 40 additions and 13 deletions
|
@ -303,7 +303,6 @@ old_LIBS="$LIBS"
|
||||||
LIBS=""
|
LIBS=""
|
||||||
AC_SEARCH_LIBS(backtrace, execinfo)
|
AC_SEARCH_LIBS(backtrace, execinfo)
|
||||||
AM_CONDITIONAL(HAVE_BACKTRACE, test "x$ac_cv_search_backtrace" != xno)
|
AM_CONDITIONAL(HAVE_BACKTRACE, test "x$ac_cv_search_backtrace" != xno)
|
||||||
BACKTRACELIB="$LIBS"
|
|
||||||
LIBS="$old_LIBS"
|
LIBS="$old_LIBS"
|
||||||
|
|
||||||
AC_SUBST(build_arch)
|
AC_SUBST(build_arch)
|
||||||
|
@ -319,7 +318,6 @@ AC_SUBST(PKG_MAINTAINER)
|
||||||
AC_SUBST(enable_cxx_exceptions)
|
AC_SUBST(enable_cxx_exceptions)
|
||||||
AC_SUBST(enable_debug_frame)
|
AC_SUBST(enable_debug_frame)
|
||||||
AC_SUBST(DLLIB)
|
AC_SUBST(DLLIB)
|
||||||
AC_SUBST(BACKTRACELIB)
|
|
||||||
|
|
||||||
AC_CONFIG_FILES(Makefile src/Makefile tests/Makefile tests/check-namespace.sh
|
AC_CONFIG_FILES(Makefile src/Makefile tests/Makefile tests/check-namespace.sh
|
||||||
doc/Makefile doc/common.tex include/libunwind-common.h
|
doc/Makefile doc/common.tex include/libunwind-common.h
|
||||||
|
|
|
@ -46,13 +46,13 @@ endif #ARCH_IA64
|
||||||
Gtest-dyn1 Ltest-dyn1 \
|
Gtest-dyn1 Ltest-dyn1 \
|
||||||
Gtest-trace Ltest-trace \
|
Gtest-trace Ltest-trace \
|
||||||
test-async-sig test-flush-cache test-init-remote \
|
test-async-sig test-flush-cache test-init-remote \
|
||||||
test-mem test-setjmp test-ptrace \
|
test-mem test-setjmp test-ptrace test-varargs \
|
||||||
Ltest-nomalloc Ltest-nocalloc rs-race
|
Ltest-nomalloc Ltest-nocalloc rs-race
|
||||||
noinst_PROGRAMS_cdep = forker crasher mapper test-ptrace-misc \
|
noinst_PROGRAMS_cdep = forker crasher mapper test-ptrace-misc \
|
||||||
Gperf-simple Lperf-simple
|
Gperf-simple Lperf-simple
|
||||||
|
|
||||||
if HAVE_BACKTRACE
|
if HAVE_BACKTRACE
|
||||||
noinst_PROGRAMS_cdep += Gperf-trace Lperf-trace test-varargs
|
noinst_PROGRAMS_cdep += Gperf-trace Lperf-trace
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if SUPPORT_CXX_EXCEPTIONS
|
if SUPPORT_CXX_EXCEPTIONS
|
||||||
|
@ -148,7 +148,7 @@ test_proc_info_LDADD = $(LIBUNWIND)
|
||||||
test_static_link_LDADD = $(LIBUNWIND)
|
test_static_link_LDADD = $(LIBUNWIND)
|
||||||
test_strerror_LDADD = $(LIBUNWIND)
|
test_strerror_LDADD = $(LIBUNWIND)
|
||||||
rs_race_LDADD = $(LIBUNWIND) -lpthread
|
rs_race_LDADD = $(LIBUNWIND) -lpthread
|
||||||
test_varargs_LDADD = @BACKTRACELIB@
|
test_varargs_LDADD = $(LIBUNWIND_local)
|
||||||
|
|
||||||
Gtest_bt_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
|
Gtest_bt_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
|
||||||
Gtest_concurrent_LDADD = $(LIBUNWIND) $(LIBUNWIND_local) -lpthread
|
Gtest_concurrent_LDADD = $(LIBUNWIND) $(LIBUNWIND_local) -lpthread
|
||||||
|
|
|
@ -1,28 +1,44 @@
|
||||||
|
#include <libunwind.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern int backtrace (void **, int);
|
int ok;
|
||||||
|
int verbose;
|
||||||
|
|
||||||
static void
|
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 3)
|
||||||
|
void a (int, ...) __attribute__((noinline, optimize(0)));
|
||||||
|
void b (void) __attribute__((noinline, optimize(0)));
|
||||||
|
void c (void) __attribute__((noinline, optimize(0)));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
b (void)
|
b (void)
|
||||||
{
|
{
|
||||||
void *v[20];
|
void *v[20];
|
||||||
int i, n;
|
int i, n;
|
||||||
|
|
||||||
n = backtrace(v, 20);
|
n = unw_backtrace(v, 20);
|
||||||
|
|
||||||
|
/* Check that the number of addresses given by unw_backtrace() looks
|
||||||
|
* reasonable. If the compiler inlined everything, then this check will also
|
||||||
|
* break. */
|
||||||
|
if (n >= 7)
|
||||||
|
ok = 1;
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
for (i = 0; i < n; ++i)
|
for (i = 0; i < n; ++i)
|
||||||
printf ("[%d] %p\n", i, v[i]);
|
printf ("[%d] %p\n", i, v[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
c (void)
|
c (void)
|
||||||
{
|
{
|
||||||
b ();
|
b ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
a (int d, ...)
|
a (int d, ...)
|
||||||
{
|
{
|
||||||
switch (d)
|
switch (d)
|
||||||
|
@ -45,8 +61,21 @@ a (int d, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (void)
|
main (int argc, char **argv __attribute__((unused)))
|
||||||
{
|
{
|
||||||
|
if (argc > 1)
|
||||||
|
verbose = 1;
|
||||||
|
|
||||||
a (5, 3, 4, 5, 6);
|
a (5, 3, 4, 5, 6);
|
||||||
|
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "FAILURE: expected deeper backtrace.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
printf ("SUCCESS.\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue