From 76cfb88fc0bfb96fc21e8cdc0b636e5ed55ca8d8 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Wed, 14 Sep 2016 21:58:15 +0300 Subject: [PATCH] Fixes for linkage and tests --- include/boost/stacktrace.hpp | 6 ++- .../stacktrace/detail/stacktrace_windows.hpp | 9 ++++ test/Jamfile.v2 | 54 +++++++++++-------- test/test.cpp | 17 ++++-- test/test_impl.cpp | 15 ++++-- 5 files changed, 70 insertions(+), 31 deletions(-) diff --git a/include/boost/stacktrace.hpp b/include/boost/stacktrace.hpp index 8262388..d7779cd 100644 --- a/include/boost/stacktrace.hpp +++ b/include/boost/stacktrace.hpp @@ -21,8 +21,12 @@ # define BOOST_STACKTRACE_LINK #endif +#if defined(BOOST_STACKTRACE_LINK) && !defined(BOOST_STACKTRACE_DYN_LINK) && defined(BOOST_ALL_DYN_LINK) +# define BOOST_STACKTRACE_DYN_LINK +#endif + #ifdef BOOST_STACKTRACE_LINK -# if defined(BOOST_STACKTRACE_DYN_LINK) || defined(BOOST_ALL_DYN_LINK) +# if defined(BOOST_STACKTRACE_DYN_LINK) # ifdef BOOST_STACKTRACE_INTERNAL_BUILD_LIBS # define BOOST_STACKTRACE_FUNCTION BOOST_SYMBOL_EXPORT # else diff --git a/include/boost/stacktrace/detail/stacktrace_windows.hpp b/include/boost/stacktrace/detail/stacktrace_windows.hpp index 23f5ddf..0f9bd7f 100644 --- a/include/boost/stacktrace/detail/stacktrace_windows.hpp +++ b/include/boost/stacktrace/detail/stacktrace_windows.hpp @@ -12,6 +12,7 @@ # pragma once #endif +#include #include #include @@ -19,6 +20,14 @@ #include "DbgHelp.h" #include +#if !defined(BOOST_ALL_NO_LIB) +# define BOOST_LIB_NAME Dbghelp +# ifdef BOOST_STACKTRACE_DYN_LINK +# define BOOST_DYN_LINK +# endif +# include +#endif + namespace boost { namespace stacktrace { namespace detail { struct symbol_info_with_stack { diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index b3ef284..cc14616 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -18,33 +18,45 @@ project linux:"-fvisibility=hidden" ; -lib test_impl_lib : test_impl.cpp : BOOST_STACKTRACE_DYN_LINK shared ; -local HONLY_UNW = BOOST_STACKTRACE_USE_LIBUNWIND unwind [ check-target-builds ../build//libunwind : : no ] ; -local HONLY_BT = BOOST_STACKTRACE_USE_BACKTRACE linux:dl [ check-target-builds ../build//backtrace : : no ] ; -local HONLY_WIND = BOOST_STACKTRACE_USE_WINDBG Dbghelp [ check-target-builds ../build//WinDbg : : no ] ; -local HONLY_AUTO = linux:dl windows:Dbghelp [ check-target-builds ../build//libunwind : unwind ] ; -local HONLY_NOOP = BOOST_STACKTRACE_USE_NOOP ; -local LINKST = shared BOOST_STACKTRACE_DYN_LINK .//test_impl_lib ; +local UNW_DEPS = unwind [ check-target-builds ../build//libunwind : : no ] ; +local BT_DEPS = linux:dl [ check-target-builds ../build//backtrace : : no ] ; +local WIND_DEPS = Dbghelp [ check-target-builds ../build//WinDbg : : no ] ; +local NOOP_DEPS = ; +local AUTO_DEPS = linux:dl [ check-target-builds ../build//WinDbg : Dbghelp ] [ check-target-builds ../build//libunwind : unwind ] ; + +local LINKSHARED_UNW = shared BOOST_STACKTRACE_DYN_LINK /boost/stacktrace//boost_stacktrace_libunwind $(UNW_DEPS) ; +local LINKSHARED_BT = shared BOOST_STACKTRACE_DYN_LINK /boost/stacktrace//boost_stacktrace_backtrace $(BT_DEPS) ; +local LINKSHARED_WIND = shared BOOST_STACKTRACE_DYN_LINK /boost/stacktrace//boost_stacktrace_windbg $(WIND_DEPS) ; +local LINKSHARED_NOOP = shared BOOST_STACKTRACE_DYN_LINK /boost/stacktrace//boost_stacktrace_noop $(NOOP_DEPS) ; + +lib test_impl_lib_libunwind : test_impl.cpp : $(LINKSHARED_UNW) ; +lib test_impl_lib_backtrace : test_impl.cpp : $(LINKSHARED_BT) ; +lib test_impl_lib_windbg : test_impl.cpp : $(LINKSHARED_WIND) ; +lib test_impl_lib_noop : test_impl.cpp : $(LINKSHARED_NOOP) ; test-suite stacktrace_tests : - [ run test.cpp test_impl.cpp : : : $(HONLY_UNW) : libunwind_ho ] - [ run test.cpp test_impl.cpp : : : $(HONLY_BT) : backtrace_ho ] - [ run test.cpp test_impl.cpp : : : $(HONLY_WIND) : windbg_ho ] - [ run test.cpp test_impl.cpp : : : $(HONLY_AUTO) : autodetect_ho ] - [ run test_noop.cpp test_impl.cpp : : : $(HONLY_NOOP) : noop_ho ] + # Header only tests + [ run test.cpp test_impl.cpp : : : BOOST_STACKTRACE_USE_LIBUNWIND $(UNW_DEPS) : libunwind_ho ] + [ run test.cpp test_impl.cpp : : : BOOST_STACKTRACE_USE_BACKTRACE $(BT_DEPS) : backtrace_ho ] + [ run test.cpp test_impl.cpp : : : BOOST_STACKTRACE_USE_WINDBG $(WIND_DEPS) : windbg_ho ] + [ run test_noop.cpp test_impl.cpp : : : BOOST_STACKTRACE_USE_NOOP $(NOOP_DEPS) : noop_ho ] + [ run test.cpp test_impl.cpp : : : $(AUTO_DEPS) : autodetect_ho ] - [ run test.cpp : : : $(LINKST) /boost/stacktrace//boost_stacktrace_libunwind [ check-target-builds ../build//libunwind : : no ] : libunwind_lib ] - [ run test.cpp : : : $(LINKST) /boost/stacktrace//boost_stacktrace_backtrace [ check-target-builds ../build//backtrace : : no ] : backtrace_lib ] - [ run test.cpp : : : $(LINKST) /boost/stacktrace//boost_stacktrace_windbg [ check-target-builds ../build//WinDbg : : no ] : windbg_lib ] - [ run test_noop.cpp : : : $(LINKST) /boost/stacktrace//boost_stacktrace_noop : noop_lib ] + # Test wih shared linked backends + [ run test.cpp : : : .//test_impl_lib_libunwind $(LINKSHARED_UNW) : libunwind_lib ] + [ run test.cpp : : : .//test_impl_lib_backtrace $(LINKSHARED_BT) : backtrace_lib ] + [ run test.cpp : : : .//test_impl_lib_windbg $(LINKSHARED_WIND) : windbg_lib ] + [ run test_noop.cpp : : : .//test_impl_lib_noop $(LINKSHARED_NOOP) : noop_lib ] - [ run ../example/getting_started.cpp : : : $(HONLY_UNW) : libunwind_getting_started ] - [ run ../example/getting_started.cpp : : : $(HONLY_BT) : backtrace_getting_started ] - [ run ../example/getting_started.cpp : : : $(HONLY_WIND) : windbg_getting_started ] - [ run ../example/getting_started.cpp : : : $(HONLY_AUTO) : auto_getting_started ] - [ run ../example/getting_started.cpp : : : $(HONLY_NOOP) : noop_getting_started ] + # Making sure that the examples work + [ run ../example/getting_started.cpp : : : $(LINKSHARED_UNW) : libunwind_getting_started ] + [ run ../example/getting_started.cpp : : : $(LINKSHARED_BT) : backtrace_getting_started ] + [ run ../example/getting_started.cpp : : : $(LINKSHARED_WIND) : windbg_getting_started ] + [ run ../example/getting_started.cpp : : : $(LINKSHARED_NOOP) : noop_getting_started ] + + [ run ../example/getting_started.cpp : : : $(AUTO_DEPS) : auto_getting_started ] ; diff --git a/test/test.cpp b/test/test.cpp index 68f48e2..16daf5b 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -12,9 +12,16 @@ #include using boost::stacktrace::stacktrace; -BOOST_SYMBOL_IMPORT std::pair foo2(int i); -BOOST_SYMBOL_IMPORT std::pair foo1(int i); -BOOST_SYMBOL_IMPORT stacktrace return_from_nested_namespaces(); + +#ifdef BOOST_STACKTRACE_DYN_LINK +# define BOOST_ST_API BOOST_SYMBOL_IMPORT +#else +# define BOOST_ST_API +#endif + +BOOST_ST_API std::pair foo2(int i); +BOOST_ST_API std::pair foo1(int i); +BOOST_ST_API stacktrace return_from_nested_namespaces(); void test_deeply_nested_namespaces() { std::stringstream ss; @@ -22,7 +29,7 @@ void test_deeply_nested_namespaces() { std::cout << ss.str() << '\n'; BOOST_TEST(ss.str().find("main") != std::string::npos); -#if defined(BOOST_STACKTRACE_LINK) || !defined(BOOST_STACKTRACE_USE_BACKTRACE) +#if defined(BOOST_STACKTRACE_DYN_LINK) || !defined(BOOST_STACKTRACE_USE_BACKTRACE) BOOST_TEST(ss.str().find("get_backtrace_from_nested_namespaces") != std::string::npos); #endif } @@ -46,7 +53,7 @@ void test_nested() { BOOST_TEST(ss1.str().find("main") != std::string::npos); BOOST_TEST(ss2.str().find("main") != std::string::npos); -#if defined(BOOST_STACKTRACE_LINK) || !defined(BOOST_STACKTRACE_USE_BACKTRACE) +#if defined(BOOST_STACKTRACE_DYN_LINK) || !defined(BOOST_STACKTRACE_USE_BACKTRACE) BOOST_TEST(ss1.str().find("foo1") != std::string::npos); BOOST_TEST(ss1.str().find("foo2") != std::string::npos); BOOST_TEST(ss2.str().find("foo1") != std::string::npos); diff --git a/test/test_impl.cpp b/test/test_impl.cpp index 944b098..42c08e5 100644 --- a/test/test_impl.cpp +++ b/test/test_impl.cpp @@ -9,8 +9,15 @@ #include using namespace boost::stacktrace; -BOOST_SYMBOL_EXPORT BOOST_NOINLINE std::pair foo1(int i); -BOOST_SYMBOL_EXPORT BOOST_NOINLINE std::pair foo2(int i); + +#ifdef BOOST_STACKTRACE_DYN_LINK +# define BOOST_ST_API BOOST_SYMBOL_EXPORT +#else +# define BOOST_ST_API +#endif + +BOOST_ST_API BOOST_NOINLINE std::pair foo1(int i); +BOOST_ST_API BOOST_NOINLINE std::pair foo2(int i); std::pair foo1(int i) { if (i) { @@ -45,12 +52,12 @@ namespace very_very_very_very_very_very_long_namespace { namespace very_very_very_very_very_very_long_namespace { namespace very_very_very_very_very_very_long_namespace { namespace very_very_very_very_very_very_long_namespace { - BOOST_SYMBOL_EXPORT BOOST_NOINLINE stacktrace get_backtrace_from_nested_namespaces() { + BOOST_ST_API BOOST_NOINLINE stacktrace get_backtrace_from_nested_namespaces() { return stacktrace(); } }}}}}}}}}} -BOOST_SYMBOL_EXPORT BOOST_NOINLINE stacktrace return_from_nested_namespaces() { +BOOST_ST_API BOOST_NOINLINE stacktrace return_from_nested_namespaces() { using very_very_very_very_very_very_long_namespace::very_very_very_very_very_very_long_namespace::very_very_very_very_very_very_long_namespace ::very_very_very_very_very_very_long_namespace::very_very_very_very_very_very_long_namespace::very_very_very_very_very_very_long_namespace ::very_very_very_very_very_very_long_namespace::very_very_very_very_very_very_long_namespace::very_very_very_very_very_very_long_namespace