1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-05-25 06:02:38 +02: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:
Tommi Rantala 2012-08-31 11:29:26 +03:00
parent ffbe29940e
commit 8203c955c8
3 changed files with 40 additions and 13 deletions

View file

@ -303,7 +303,6 @@ old_LIBS="$LIBS"
LIBS=""
AC_SEARCH_LIBS(backtrace, execinfo)
AM_CONDITIONAL(HAVE_BACKTRACE, test "x$ac_cv_search_backtrace" != xno)
BACKTRACELIB="$LIBS"
LIBS="$old_LIBS"
AC_SUBST(build_arch)
@ -319,7 +318,6 @@ AC_SUBST(PKG_MAINTAINER)
AC_SUBST(enable_cxx_exceptions)
AC_SUBST(enable_debug_frame)
AC_SUBST(DLLIB)
AC_SUBST(BACKTRACELIB)
AC_CONFIG_FILES(Makefile src/Makefile tests/Makefile tests/check-namespace.sh
doc/Makefile doc/common.tex include/libunwind-common.h

View file

@ -46,13 +46,13 @@ endif #ARCH_IA64
Gtest-dyn1 Ltest-dyn1 \
Gtest-trace Ltest-trace \
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
noinst_PROGRAMS_cdep = forker crasher mapper test-ptrace-misc \
Gperf-simple Lperf-simple
if HAVE_BACKTRACE
noinst_PROGRAMS_cdep += Gperf-trace Lperf-trace test-varargs
noinst_PROGRAMS_cdep += Gperf-trace Lperf-trace
endif
if SUPPORT_CXX_EXCEPTIONS
@ -148,7 +148,7 @@ test_proc_info_LDADD = $(LIBUNWIND)
test_static_link_LDADD = $(LIBUNWIND)
test_strerror_LDADD = $(LIBUNWIND)
rs_race_LDADD = $(LIBUNWIND) -lpthread
test_varargs_LDADD = @BACKTRACELIB@
test_varargs_LDADD = $(LIBUNWIND_local)
Gtest_bt_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
Gtest_concurrent_LDADD = $(LIBUNWIND) $(LIBUNWIND_local) -lpthread

View file

@ -1,28 +1,44 @@
#include <libunwind.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.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)
{
void *v[20];
int i, n;
n = backtrace(v, 20);
for (i = 0; i < n; ++i)
printf ("[%d] %p\n", i, v[i]);
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)
printf ("[%d] %p\n", i, v[i]);
}
static void
void
c (void)
{
b ();
}
static void
void
a (int d, ...)
{
switch (d)
@ -45,8 +61,21 @@ a (int d, ...)
}
int
main (void)
main (int argc, char **argv __attribute__((unused)))
{
if (argc > 1)
verbose = 1;
a (5, 3, 4, 5, 6);
if (!ok)
{
fprintf (stderr, "FAILURE: expected deeper backtrace.\n");
return 1;
}
if (verbose)
printf ("SUCCESS.\n");
return 0;
}