diff --git a/.gitignore b/.gitignore index 9bde15c4..f8fa8582 100644 --- a/.gitignore +++ b/.gitignore @@ -66,6 +66,7 @@ tests/test-static-link tests/[GL]test-trace tests/[GL]perf-trace tests/Ltest-cxx-exceptions +tests/Ltest-init-local-signal tests/[GL]ia64-test-nat tests/[GL]ia64-test-rbs tests/[GL]ia64-test-readonly diff --git a/tests/Ltest-init-local-signal-lib.c b/tests/Ltest-init-local-signal-lib.c new file mode 100644 index 00000000..45c0e7c1 --- /dev/null +++ b/tests/Ltest-init-local-signal-lib.c @@ -0,0 +1,6 @@ +#include + +/* To prevent inlining and optimizing away */ +int foo(int* f) { + return *f; +} diff --git a/tests/Ltest-init-local-signal.c b/tests/Ltest-init-local-signal.c new file mode 100644 index 00000000..c77ad1ed --- /dev/null +++ b/tests/Ltest-init-local-signal.c @@ -0,0 +1,57 @@ +#include "libunwind.h" +#include +#include +#include + +#include + +#include +#include +#include + +int stepper(unw_cursor_t* c) { + int steps = 0; + int ret = 1; + while (ret) { + + ret = unw_step(c); + if (!ret) { + break; + } + steps++; + } + return steps; +} + +/* Verify that we can step from both ucontext, and from getcontext() + * roughly the same. This tests that the IP from ucontext is used + * correctly (see impl of unw_init_local_signal) */ +void handler(int num, siginfo_t* info, void* ucontext) { + unw_cursor_t c; + unw_context_t context; + unw_getcontext(&context); + int ret = unw_init_local_signal(&c, ucontext); + assert(!ret); + int ucontext_steps = stepper(&c); + + ret = unw_init_local(&c, &context); + assert(!ret); + int getcontext_steps = stepper(&c); + if (ucontext_steps == getcontext_steps - 2) { + exit(0); + } + printf("unw_getcontext steps was %i, ucontext steps was %i, should be %i\n", + getcontext_steps, ucontext_steps, getcontext_steps - 2); + exit(-1); +} + +int foo(int* f); + +int main(){ + struct sigaction a; + memset(&a, 0, sizeof(struct sigaction)); + a.sa_sigaction = &handler; + sigaction(SIGSEGV, &a, NULL); + + foo(NULL); +} diff --git a/tests/Makefile.am b/tests/Makefile.am index cd3e589b..53ca6989 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -45,6 +45,7 @@ endif #!ARCH_IA64 Gtest-resume-sig Ltest-resume-sig \ Gtest-resume-sig-rt Ltest-resume-sig-rt \ Gtest-trace Ltest-trace \ + Ltest-init-local-signal \ test-async-sig test-flush-cache test-init-remote \ test-mem Ltest-varargs Ltest-nomalloc \ Ltest-nocalloc Lrs-race @@ -134,6 +135,8 @@ Gtest_init_SOURCES = Gtest-init.cxx Ltest_init_SOURCES = Ltest-init.cxx Ltest_cxx_exceptions_SOURCES = Ltest-cxx-exceptions.cxx +Ltest_init_local_signal_SOURCES = Ltest-init-local-signal.c Ltest-init-local-signal-lib.c + Gtest_dyn1_SOURCES = Gtest-dyn1.c flush-cache.S flush-cache.h Ltest_dyn1_SOURCES = Ltest-dyn1.c flush-cache.S flush-cache.h test_static_link_SOURCES = test-static-link-loc.c test-static-link-gen.c @@ -174,6 +177,7 @@ test_static_link_LDADD = $(LIBUNWIND) test_strerror_LDADD = $(LIBUNWIND) Lrs_race_LDADD = $(LIBUNWIND_local) -lpthread Ltest_varargs_LDADD = $(LIBUNWIND_local) +Ltest_init_local_signal_LDADD = $(LIBUNWIND) Gtest_bt_LDADD = $(LIBUNWIND) $(LIBUNWIND_local) Gtest_concurrent_LDADD = $(LIBUNWIND) $(LIBUNWIND_local) -lpthread