diff --git a/example/debug_function.cpp b/example/debug_function.cpp new file mode 100644 index 0000000..2da6cef --- /dev/null +++ b/example/debug_function.cpp @@ -0,0 +1,32 @@ +// Copyright Antony Polukhin, 2016. +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +//[getting_started_debug_function +#include // ::signal +#include +#include // std::cerr + +void print_signal_handler_and_exit() { + void* p = reinterpret_cast(::signal(SIGSEGV, SIG_DFL)); + boost::stacktrace::frame f(p); + std::cout << f << std::endl; + std::exit(0); +} +//] + + +void my_signal_handler(int signum) { + std::exit(1); +} + +int main() { + ::signal(SIGSEGV, &my_signal_handler); + print_signal_handler_and_exit(); + + return 2; +} + + diff --git a/example/user_config.cpp b/example/user_config.cpp new file mode 100644 index 0000000..0784747 --- /dev/null +++ b/example/user_config.cpp @@ -0,0 +1,38 @@ +// Copyright Antony Polukhin, 2016. +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_USER_CONFIG + +#include +#include // std::set_terminate, std::abort +#include +#include // std::cerr +BOOST_NOINLINE void foo(int i); +BOOST_NOINLINE void bar(int i); + +BOOST_NOINLINE void bar(int i) { + boost::array a = {{-1, -231, -123, -23, -32}}; + if (i >= 0) { + foo(a[i]); + } else { + std::cerr << "Terminate called:\n" << boost::stacktrace::stacktrace() << '\n'; + std::exit(0); + } +} + +BOOST_NOINLINE void foo(int i) { + bar(--i); +} + +int main() { + foo(5); + + return 2; +} + + + + diff --git a/example/user_config.hpp b/example/user_config.hpp new file mode 100644 index 0000000..8f9df13 --- /dev/null +++ b/example/user_config.hpp @@ -0,0 +1,56 @@ +// Copyright Antony Polukhin, 2016. +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + + +//[getting_started_user_config +#ifndef USER_CONFIG_HPP +#define USER_CONFIG_HPP + +#define BOOST_STACKTRACE_DEFAULT_MAX_DEPTH 5 +#include + +#include + +namespace boost { namespace stacktrace { + +template +std::basic_ostream& do_stream_st(std::basic_ostream& os, const basic_stacktrace& bt); + +template +std::basic_ostream& operator<<(std::basic_ostream& os, const stacktrace& bt) { + return do_stream_st(os, bt); +} + +}} // namespace boost::stacktrace +#endif // USER_CONFIG_HPP +//] + +#ifndef USER_CONFIG2_HPP +#define USER_CONFIG2_HPP +//[getting_started_user_config_impl +namespace boost { namespace stacktrace { + +template +std::basic_ostream& do_stream_st(std::basic_ostream& os, const basic_stacktrace& bt) { + const std::streamsize w = os.width(); + const std::size_t frames = bt.size(); + for (std::size_t i = 0; i < frames; ++i) { + os.width(2); + os << i; + os.width(w); + os << "# "; + os << bt[i].name(); + os << '\n'; + } + + return os; +} + +}} // namespace boost::stacktrace +//] + +#endif // USER_CONFIG2_HPP + diff --git a/include/boost/stacktrace/detail/backend.hpp b/include/boost/stacktrace/detail/backend.hpp index 1bc2bf6..951de46 100644 --- a/include/boost/stacktrace/detail/backend.hpp +++ b/include/boost/stacktrace/detail/backend.hpp @@ -14,9 +14,6 @@ #include -#ifndef BOOST_STACKTRACE_DEFAULT_MAX_DEPTH -# define BOOST_STACKTRACE_DEFAULT_MAX_DEPTH 100 -#endif // Link or header only #if !defined(BOOST_STACKTRACE_LINK) && defined(BOOST_STACKTRACE_DYN_LINK) diff --git a/include/boost/stacktrace/stacktrace.hpp b/include/boost/stacktrace/stacktrace.hpp index 8215add..56175f8 100644 --- a/include/boost/stacktrace/stacktrace.hpp +++ b/include/boost/stacktrace/stacktrace.hpp @@ -17,21 +17,12 @@ #include #include +#include #include #include #include -#ifdef BOOST_STACKTRACE_DOXYGEN_INVOKED - -/// You may define this macro to some positive integer to limit the max stack frames count for the boost::stacktrace::stacktrace class. -/// This macro does not affect the boost::stacktrace::basic_stacktrace. -/// -/// @b Default: 100 -#define BOOST_STACKTRACE_DEFAULT_MAX_DEPTH 100 - -#endif - namespace boost { namespace stacktrace { /// Class that on construction copies minimal information about call stack into its internals and provides access to that information. diff --git a/include/boost/stacktrace/stacktrace_fwd.hpp b/include/boost/stacktrace/stacktrace_fwd.hpp index 4dda092..41fdf33 100644 --- a/include/boost/stacktrace/stacktrace_fwd.hpp +++ b/include/boost/stacktrace/stacktrace_fwd.hpp @@ -13,7 +13,15 @@ /// boost::stacktrace::frame, boost::stacktrace::const_iterator, boost::stacktrace::basic_stacktrace /// and does not include any other Boost headers. -/// @cond + +#ifndef BOOST_STACKTRACE_DEFAULT_MAX_DEPTH +/// You may define this macro to some positive integer to limit the max stack frames count for the boost::stacktrace::stacktrace class. +/// This macro does not affect the boost::stacktrace::basic_stacktrace. +/// +/// @b Default: 100 +#define BOOST_STACKTRACE_DEFAULT_MAX_DEPTH 100 +#endif + namespace boost { namespace stacktrace { class frame; @@ -23,8 +31,9 @@ class const_iterator; template class basic_stacktrace; +typedef basic_stacktrace stacktrace; + }} // namespace boost::stacktrace -/// @endcond #endif // BOOST_STACKTRACE_STACKTRACE_FWD_HPP