Compare commits

...

42 Commits

Author SHA1 Message Date
Antony Polukhin
1ad62e582a Add comment about async signal safety for PR #70 2019-01-12 22:37:31 +03:00
Antony Polukhin
5c6740b680 Merge branch 'develop' of github.com:boostorg/stacktrace into develop 2019-01-12 22:15:24 +03:00
Antony Polukhin
d9d6512743 Update copyright years 2019-01-12 22:15:16 +03:00
Antony Polukhin
158a59ae51 Merge pull request #70 from ivanarh/use_execinfo_backtrace
Added an option to use libc backtrace function from execinfo.h
2019-01-11 21:59:44 +03:00
Antony Polukhin
839a1a127d Update collect_unwind.ipp 2019-01-11 13:27:43 +03:00
Ivan Ponomarev
411d92cbf3 Forced backtrace() function usage on iOS, 32-bit ARM architecture. Used macros from Boost predef. 2019-01-09 23:07:37 +03:00
Ivan Ponomarev
1b7956a40d Added an ability to use libc backtrace() function (from execinfo.h) instead of _Unwind_Backtrace on Unix-like systems. Useful on iOS 32-bit ARM where _Unwind_Backtrace symbol is undefined. 2019-01-09 01:04:47 +03:00
Antony Polukhin
d708d17ecd Suppress warning (fixes #69) 2019-01-05 13:48:53 +03:00
Antony Polukhin
d946b124ba Fix typo noted by Telegram user PRoSToC0der 2018-12-13 11:00:33 +03:00
Antony Polukhin
39486260ae Merge pull request #67 from JanEisenhauer/develop
Collect at most as many frames as requested.
2018-10-30 10:49:47 +03:00
Jan Eisenhauer
cbd625bd91 fixup! Postprocessing to limit the trace to max_depth is no longer necessary. 2018-10-29 15:12:34 +01:00
Jan Eisenhauer
b08dab1c44 Postprocessing to limit the trace to max_depth is no longer necessary. 2018-10-29 14:34:16 +01:00
Jan Eisenhauer
77405d8d7f Collect at most as many frames as requested. 2018-10-29 14:30:59 +01:00
Jan Eisenhauer
324a24abba Evade the min macro from Windows headers. 2018-10-29 14:06:42 +01:00
Jan Eisenhauer
5e85e7414a Collect at most as many frames as requested. 2018-10-29 13:27:36 +01:00
Antony Polukhin
4123beb4af fix memory consumption when using libbacktrace and speedup trace decoding 2018-10-07 20:08:27 +03:00
Antony Polukhin
f0a9ba6809 Add long tests that detect leaks 2018-10-06 20:39:13 +03:00
Antony Polukhin
b414d35518 Add missing include 2018-10-05 11:10:17 +03:00
Antony Polukhin
42bf318144 Make the traces comparison test more reliable 2018-10-05 10:58:36 +03:00
Antony Polukhin
61c94e65e1 force the hidden visibility using new b2 feature 2018-09-22 22:05:30 +03:00
Antony Polukhin
d573d2a405 add tests for basic impl for cases when symbols are not exported 2018-09-19 23:12:47 +03:00
Antony Polukhin
9f232606cb make tests less verbose 2018-09-19 23:03:47 +03:00
Antony Polukhin
d6f0c65a83 fix typos and use BOOST_SYMBOL_VISIBLE 2018-09-17 09:56:24 +03:00
Antony Polukhin
3089b733a8 Win related issues in tests fixed 2018-09-17 00:12:46 +03:00
Antony Polukhin
99da94f5bd Rework the tests, deal with visibility issues, make sure that libbacktrace implementation now uses export tables 2018-09-16 23:23:33 +03:00
Antony Polukhin
3f047cbfc4 Fix damn web ui artifacts 2018-09-13 20:25:59 +03:00
Antony Polukhin
e14dd6560a Fixes for tests run with hidden visibility
Related to the changes in https://github.com/boostorg/boost/pull/190
2018-09-13 19:58:55 +03:00
Antony Polukhin
f328647e45 More docs improvemnts for the #62 2018-09-13 18:23:37 +03:00
Antony Polukhin
6d101ba4d6 Improve docs for #62 2018-09-13 18:19:56 +03:00
Antony Polukhin
c63afe54a2 Fix #61 2018-08-29 12:37:40 +03:00
Antony Polukhin
745c6aa7a0 Merge pull request #60 from driesdeschout/develop
Libbacktrace fallback to sym info when debug info is missing or incomplete
2018-08-20 10:18:19 +03:00
Dries Deschout
7a595a164f Fix style 2018-08-20 09:03:12 +02:00
Dries Deschout
b4b84780b1 Libbacktrace fallback to sym info in name_impl 2018-08-20 09:02:29 +02:00
Dries Deschout
1289134b6d Libbacktrace fallback to sym info when debug info is missing or incomplete 2018-08-13 14:58:21 +02:00
Antony Polukhin
819f2b1c86 bump copyright years 2018-08-07 22:41:22 +03:00
Antony Polukhin
fb47f17836 Allow to specify exact location of the backtrace.h header. Fixes #59 2018-08-07 22:29:00 +03:00
Antony Polukhin
b8dec8b126 Added to_string function for the boost::stacktrace::basic_stacktrace classes. Fixes #57 2018-07-28 17:12:03 +03:00
Antony Polukhin
7fedfa1265 Add info that the library is proposed for C++20 2018-06-11 18:55:06 +03:00
Antony Polukhin
4a5471a239 const_cast address to void* to avoid compile issues on platforms that have dladdr(void*, Dl_info*). Issue #54 2018-05-23 22:27:46 +03:00
Antony Polukhin
e4e2d4c3c1 Add missing include for tests 2018-04-15 14:19:01 +03:00
Antony Polukhin
14852ad597 Merge pull request #51 from boostorg/droping_dependencies
Drop dependency on lexical_cast and add more tests
2018-04-15 13:02:02 +03:00
Antony Polukhin
87b4789289 Drop dependency on lexical_cast and add more tests 2018-03-14 22:33:04 +03:00
57 changed files with 520 additions and 251 deletions

View File

@@ -2,7 +2,7 @@
# subject to 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)
#
# Copyright Antony Polukhin 2014-2018.
# Copyright Antony Polukhin 2014-2019.
#
# See https://svn.boost.org/trac/boost/wiki/TravisCoverals for description of this file

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2016-2017, Antony Polukhin.
# Copyright (C) 2016-2019, Antony Polukhin.
#
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -8,7 +8,7 @@
project
: source-location .
: requirements
<target-os>linux:<cxxflags>"-fvisibility=hidden"
<visibility>hidden
;
lib dl ;

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
# Copyright Antony Polukhin 2016-2017.
# Copyright Antony Polukhin 2016-2019.
# Use, modification, and distribution are
# subject to 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)

View File

@@ -2,7 +2,7 @@
[quickbook 1.6]
[version 1.0]
[id stacktrace]
[copyright 2016-2017 Antony Polukhin]
[copyright 2016-2019 Antony Polukhin]
[category Language Features Emulation]
[license
Distributed under the Boost Software License, Version 1.0.
@@ -298,7 +298,7 @@ In header only mode library could be tuned by macro. If one of the link macro fr
[[['default for MSVC, Intel on Windows, MinGW-w64] / *BOOST_STACKTRACE_USE_WINDBG*] [*boost_stacktrace_windbg*] [ Uses COM to show debug info. May require linking with *ole32* and *dbgeng*. ] [MSVC, MinGW-w64, Intel on Windows] [yes] [no]]
[[['default for other platforms]] [*boost_stacktrace_basic*] [Uses compiler intrinsics to collect stacktrace and if possible `::dladdr` to show information about the symbol. Requires linking with *libdl* library on POSIX platforms.] [Any compiler on POSIX or MinGW] [no] [yes]]
[[*BOOST_STACKTRACE_USE_WINDBG_CACHED*] [*boost_stacktrace_windbg_cached*] [ Uses COM to show debug info and caches COM instances in TLS for better performance. Useful only for cases when traces are gathered very often. [footnote This may affect other components of your program that use COM, because this mode calls the `CoInitializeEx(0, COINIT_MULTITHREADED)` on first use and does not call `::CoUninitialize();` until the current thread is destroyed. ] May require linking with *ole32* and *dbgeng*. ] [MSVC, Intel on Windows] [yes] [no]]
[[*BOOST_STACKTRACE_USE_BACKTRACE*] [*boost_stacktrace_backtrace*] [Requires linking with *libdl* on POSIX and *libbacktrace* libraries. *libbacktrace* is probably already installed in your system, or built into your compiler.
[[*BOOST_STACKTRACE_USE_BACKTRACE*] [*boost_stacktrace_backtrace*] [Requires linking with *libdl* on POSIX and *libbacktrace* libraries. *libbacktrace* is probably already installed in your system[footnote If you are using Clang with libstdc++ you could get into troubles of including `<backtrace.h>`, because on some platforms Clang does not search for headers in the GCC's include paths and any attempt to add GCC's include path leads to linker errors. To explicitly specify a path to the `<backtrace.h>` header you could define the *BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE* to a full path to the header. For example on Ubuntu Xenial use the command line option *-DBOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE=</usr/lib/gcc/x86_64-linux-gnu/5/include/backtrace.h>* while building with Clang. ], or built into your compiler.
Otherwise (if you are a *MinGW*/*MinGW-w64* user for example) it can be downloaded [@https://github.com/ianlancetaylor/libbacktrace from here] or [@https://github.com/gcc-mirror/gcc/tree/master/libbacktrace from here]. ] [Any compiler on POSIX, or MinGW, or MinGW-w64] [yes] [yes]]
[[*BOOST_STACKTRACE_USE_ADDR2LINE*] [*boost_stacktrace_addr2line*] [Use *addr2line* program to retrieve stacktrace. Requires linking with *libdl* library and `::fork` system call. Macro *BOOST_STACKTRACE_ADDR2LINE_LOCATION* must be defined to the absolute path to the addr2line executable if it is not located in /usr/bin/addr2line. ] [Any compiler on POSIX] [yes] [yes]]
@@ -308,8 +308,8 @@ In header only mode library could be tuned by macro. If one of the link macro fr
[*Examples:]
* if you wish to switch to more powerful implementation on Clang/MinGW and *BOOST_STACKTRACE_LINK* is defined, you just need link with "*-lboost_stacktrace_backtrace -ldl -lbacktrace*" or "*-lboost_stacktrace_addr2line -ldl*"
* if you wish to disable backtracing and you use the library in header only mode, you just need to define *BOOST_STACKTRACE_USE_NOOP* for the whole project
* if you wish to disable backtracing and *BOOST_STACKTRACE_LINK* is defined, you just need link with *-lboost_stacktrace_noop*
* if you wish to disable backtracing and you use the library in header only mode, you just need to define *BOOST_STACKTRACE_USE_NOOP* for the whole project and recompile it
[section MinGW and MinGW-w64 specific notes]

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2018.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2018.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2018.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -35,7 +35,7 @@ BOOST_NOINLINE void oops(int i) {
if (i >= 4)
throw_with_trace(std::out_of_range("'i' must be less than 4 in oops()"));
if (i <= 0)
throw_with_trace(std::logic_error("'i' must not be greater than zero in oops()"));
throw_with_trace(std::logic_error("'i' must be greater than zero in oops()"));
//]
foo(i);
std::exit(1);

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -29,6 +29,9 @@ std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT
#ifndef USER_CONFIG2_HPP
#define USER_CONFIG2_HPP
#include <ios> // std::streamsize
//[getting_started_user_config_impl
namespace boost { namespace stacktrace {

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -13,8 +13,9 @@
#endif
#include <boost/stacktrace/detail/to_hex_array.hpp>
#include <boost/stacktrace/detail/to_dec_array.hpp>
#include <boost/stacktrace/detail/try_dec_convert.hpp>
#include <boost/core/demangle.hpp>
#include <boost/lexical_cast.hpp>
#include <cstdio>
#include <sys/types.h>
@@ -212,7 +213,7 @@ std::size_t frame::source_line() const {
}
res = res.substr(last + 1);
if (!boost::conversion::try_lexical_convert(res, line_num)) {
if (!boost::stacktrace::detail::try_dec_convert(res.c_str(), line_num)) {
return 0;
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -14,7 +14,19 @@
#include <boost/stacktrace/safe_dump_to.hpp>
// On iOS 32-bit ARM architecture _Unwind_Backtrace function doesn't exist, symbol is undefined.
// Forcing libc backtrace() function usage.
#include <boost/predef.h>
#if defined(BOOST_OS_IOS_AVAILABLE) && defined(BOOST_ARCH_ARM_AVAILABLE) && BOOST_VERSION_NUMBER_MAJOR(BOOST_ARCH_ARM) < 8
#define BOOST_STACKTRACE_USE_LIBC_BACKTRACE_FUNCTION
#endif
#if defined(BOOST_STACKTRACE_USE_LIBC_BACKTRACE_FUNCTION)
#include <execinfo.h>
#include <algorithm>
#else
#include <unwind.h>
#endif
#include <cstdio>
#if !defined(_GNU_SOURCE) && !defined(BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED) && !defined(BOOST_WINDOWS)
@@ -23,6 +35,7 @@
namespace boost { namespace stacktrace { namespace detail {
#if !defined(BOOST_STACKTRACE_USE_LIBC_BACKTRACE_FUNCTION)
struct unwind_state {
std::size_t frames_to_skip;
native_frame_ptr_t* current;
@@ -48,16 +61,35 @@ inline _Unwind_Reason_Code unwind_callback(::_Unwind_Context* context, void* arg
}
return ::_URC_NO_REASON;
}
#endif //!defined(BOOST_STACKTRACE_USE_LIBC_BACKTRACE_FUNCTION)
std::size_t this_thread_frames::collect(native_frame_ptr_t* out_frames, std::size_t max_frames_count, std::size_t skip) BOOST_NOEXCEPT {
std::size_t frames_count = 0;
if (!max_frames_count) {
return frames_count;
}
skip += 1;
boost::stacktrace::detail::unwind_state state = { skip + 1, out_frames, out_frames + max_frames_count };
#if defined(BOOST_STACKTRACE_USE_LIBC_BACKTRACE_FUNCTION)
// According to https://opensource.apple.com/source/Libc/Libc-1272.200.26/gen/backtrace.c.auto.html
// it looks like the `::backtrace` is async signal safe.
frames_count = static_cast<size_t>(::backtrace(const_cast<void **>(out_frames), static_cast<int>(max_frames_count)));
// NOTE: There is no way to pass "skip" count to backtrace function so we need to perform left shift operation.
// If number of elements in result backtrace is >= max_frames_count then "skip" elements are wasted.
if (frames_count && skip) {
if (skip >= frames_count) {
frames_count = 0;
} else {
std::copy(out_frames + skip, out_frames + frames_count, out_frames);
frames_count -= skip;
}
}
#else
boost::stacktrace::detail::unwind_state state = { skip, out_frames, out_frames + max_frames_count };
::_Unwind_Backtrace(&boost::stacktrace::detail::unwind_callback, &state);
frames_count = state.current - out_frames;
#endif //defined(BOOST_STACKTRACE_USE_LIBC_BACKTRACE_FUNCTION)
if (frames_count && out_frames[frames_count - 1] == 0) {
-- frames_count;
@@ -69,4 +101,6 @@ std::size_t this_thread_frames::collect(native_frame_ptr_t* out_frames, std::siz
}}} // namespace boost::stacktrace::detail
#undef BOOST_STACKTRACE_USE_LIBC_BACKTRACE_FUNCTION
#endif // BOOST_STACKTRACE_DETAIL_COLLECT_UNWIND_IPP

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -16,7 +16,7 @@
#include <boost/core/demangle.hpp>
#include <boost/core/noncopyable.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/stacktrace/detail/to_dec_array.hpp>
#include <boost/stacktrace/detail/to_hex_array.hpp>
#include <windows.h>
#include "dbgeng.h"
@@ -329,7 +329,7 @@ public:
res += " at ";
res += source_line.first;
res += ':';
res += boost::lexical_cast<boost::array<char, 40> >(source_line.second).data();
res += boost::stacktrace::detail::to_dec_array(source_line.second).data();
} else if (!module_name.empty()) {
res += " in ";
res += module_name;
@@ -349,7 +349,7 @@ std::string to_string(const frame* frames, std::size_t size) {
if (i < 10) {
res += ' ';
}
res += boost::lexical_cast<boost::array<char, 40> >(i).data();
res += boost::stacktrace::detail::to_dec_array(i).data();
res += '#';
res += ' ';
idebug.to_string_impl(frames[i].address(), res);

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -16,8 +16,8 @@
#include <boost/stacktrace/detail/to_hex_array.hpp>
#include <boost/stacktrace/detail/location_from_symbol.hpp>
#include <boost/stacktrace/detail/to_dec_array.hpp>
#include <boost/core/demangle.hpp>
#include <boost/lexical_cast.hpp>
#include <cstdio>
@@ -67,7 +67,7 @@ std::string to_string(const frame* frames, std::size_t size) {
if (i < 10) {
res += ' ';
}
res += boost::lexical_cast<boost::array<char, 40> >(i).data();
res += boost::stacktrace::detail::to_dec_array(i).data();
res += '#';
res += ' ';
res += impl(frames[i].address());
@@ -84,7 +84,7 @@ std::string to_string(const frame* frames, std::size_t size) {
std::string frame::name() const {
#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
::Dl_info dli;
const bool dl_ok = !!::dladdr(addr_, &dli);
const bool dl_ok = !!::dladdr(const_cast<void*>(addr_), &dli); // `dladdr` on Solaris accepts nonconst addresses
if (dl_ok && dli.dli_sname) {
return boost::core::demangle(dli.dli_sname);
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -13,11 +13,15 @@
#endif
#include <boost/stacktrace/detail/to_hex_array.hpp>
#include <boost/stacktrace/detail/to_dec_array.hpp>
#include <boost/stacktrace/detail/location_from_symbol.hpp>
#include <boost/core/demangle.hpp>
#include <boost/lexical_cast.hpp>
#include <backtrace.h>
#ifdef BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE
# include BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE
#else
# include <backtrace.h>
#endif
namespace boost { namespace stacktrace { namespace detail {
@@ -28,6 +32,18 @@ struct pc_data {
std::size_t line;
};
inline void libbacktrace_syminfo_callback(void *data, uintptr_t /*pc*/, const char *symname, uintptr_t /*symval*/, uintptr_t /*symsize*/) {
pc_data& d = *static_cast<pc_data*>(data);
if (d.function && symname) {
*d.function = symname;
}
}
// Old versions of libbacktrace have different signature for the callback
inline void libbacktrace_syminfo_callback(void *data, uintptr_t pc, const char *symname, uintptr_t symval) {
boost::stacktrace::detail::libbacktrace_syminfo_callback(data, pc, symname, symval, 0);
}
inline int libbacktrace_full_callback(void *data, uintptr_t /*pc*/, const char *filename, int lineno, const char *function) {
pc_data& d = *static_cast<pc_data*>(data);
if (d.filename && filename) {
@@ -44,30 +60,54 @@ inline void libbacktrace_error_callback(void* /*data*/, const char* /*msg*/, int
// Do nothing, just return.
}
inline ::backtrace_state* construct_state(const program_location& prog_location) BOOST_NOEXCEPT {
// Currently `backtrace_create_state` can not detect file name on Windows https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82543
// That's why we provide a `prog_location` here.
return ::backtrace_create_state(
prog_location.name(), 0 /*thread-safe*/, boost::stacktrace::detail::libbacktrace_error_callback, 0
);
// TODO: this does not seem to work well when this function is in .so:
// Not async-signal-safe, so this method is not called from async-safe functions.
//
// This function is not async signal safe because:
// * Dynamic initialization of a block-scope variable with static storage duration could lock a mutex
// * No guarantees on `backtrace_create_state` function.
// Not async-signal-safe, so this method is not called from async-safe functions.
//
// This function is not async signal safe because:
// * Dynamic initialization of a block-scope variable with static storage duration could lock a mutex
// * No guarantees on `backtrace_create_state` function.
//
// Currently `backtrace_create_state` can not detect file name on Windows https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82543
// That's why we provide a `prog_location` here.
BOOST_SYMBOL_VISIBLE inline ::backtrace_state* construct_state(const program_location& prog_location) BOOST_NOEXCEPT {
// [dcl.inline]: A static local variable in an inline function with external linkage always refers to the same object.
/*
static ::backtrace_state* state = ::backtrace_create_state(
0, 1 , boost::stacktrace::detail::libbacktrace_error_callback, 0
);
// TODO: The most obvious solution:
//
//static ::backtrace_state* state = ::backtrace_create_state(
// prog_location.name(),
// 1, // allow safe concurrent usage of the same state
// boost::stacktrace::detail::libbacktrace_error_callback,
// 0 // pointer to data that will be passed to callback
//);
//
//
// Unfortunately, that solution segfaults when `construct_state()` function is in .so file
// and multiple threads concurrently work with state.
#ifndef BOOST_HAS_THREADS
static
#else
// Result of `construct_state()` invocation is not stored by the callers, so `thread_local`
// gives a single `state` per thread and that state is not shared between threads in any way.
# ifndef BOOST_NO_CXX11_THREAD_LOCAL
thread_local
# elif defined(__GNUC__)
static __thread
# else
/* just a local variable */
# endif
#endif
::backtrace_state* state = ::backtrace_create_state(
prog_location.name(),
0,
boost::stacktrace::detail::libbacktrace_error_callback,
0
);
return state;
*/
}
struct to_string_using_backtrace {
@@ -86,6 +126,14 @@ struct to_string_using_backtrace {
boost::stacktrace::detail::libbacktrace_full_callback,
boost::stacktrace::detail::libbacktrace_error_callback,
&data
)
||
::backtrace_syminfo(
state,
reinterpret_cast<uintptr_t>(addr),
boost::stacktrace::detail::libbacktrace_syminfo_callback,
boost::stacktrace::detail::libbacktrace_error_callback,
&data
);
}
line = data.line;
@@ -99,7 +147,7 @@ struct to_string_using_backtrace {
res += " at ";
res += filename;
res += ':';
res += boost::lexical_cast<boost::array<char, 40> >(line).data();
res += boost::stacktrace::detail::to_dec_array(line).data();
return true;
}
@@ -125,6 +173,14 @@ inline std::string name_impl(const void* addr) {
boost::stacktrace::detail::libbacktrace_full_callback,
boost::stacktrace::detail::libbacktrace_error_callback,
&data
)
||
::backtrace_syminfo(
state,
reinterpret_cast<uintptr_t>(addr),
boost::stacktrace::detail::libbacktrace_syminfo_callback,
boost::stacktrace::detail::libbacktrace_error_callback,
&data
);
}
if (!res.empty()) {

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -28,7 +28,7 @@ public:
explicit location_from_symbol(const void* addr) BOOST_NOEXCEPT
: dli_()
{
if (!::dladdr(addr, &dli_)) {
if (!::dladdr(const_cast<void*>(addr), &dli_)) { // `dladdr` on Solaris accepts nonconst addresses
dli_.dli_fname = 0;
}
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2018.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -0,0 +1,46 @@
// Copyright Antony Polukhin, 2016-2019.
//
// 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)
#ifndef BOOST_STACKTRACE_DETAIL_TO_DEC_ARRAY_HPP
#define BOOST_STACKTRACE_DETAIL_TO_DEC_ARRAY_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <boost/array.hpp>
namespace boost { namespace stacktrace { namespace detail {
// We do not use boost::lexical_cast in this function to reduce module dependencies
inline boost::array<char, 40> to_dec_array(std::size_t value) BOOST_NOEXCEPT {
boost::array<char, 40> ret;
if (!value) {
ret[0] = '0';
ret[1] = '\0';
return ret;
}
std::size_t digits = 0;
for (std::size_t value_copy = value; value_copy; value_copy /= 10) {
++ digits;
}
for (std::size_t i = 1; i <= digits; ++i) {
ret[digits - i] = static_cast<char>('0' + (value % 10));
value /= 10;
}
ret[digits] = '\0';
return ret;
}
}}} // namespace boost::stacktrace::detail
#endif // BOOST_STACKTRACE_DETAIL_TO_DEC_ARRAY_HPP

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -0,0 +1,29 @@
// Copyright Antony Polukhin, 2016-2019.
//
// 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)
#ifndef BOOST_STACKTRACE_DETAIL_TRY_DEC_CONVERT_HPP
#define BOOST_STACKTRACE_DETAIL_TRY_DEC_CONVERT_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <cstdlib>
namespace boost { namespace stacktrace { namespace detail {
// We do not use boost::lexical_cast in this function to reduce module dependencies
inline bool try_dec_convert(const char* s, std::size_t& res) BOOST_NOEXCEPT {
char* end_ptr = 0;
res = std::strtoul(s, &end_ptr, 10);
return *end_ptr == '\0';
}
}}} // namespace boost::stacktrace::detail
#endif // BOOST_STACKTRACE_DETAIL_TRY_DEC_CONVERT_HPP

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,5 +1,5 @@
// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
// Copyright 2015-2017 Antony Polukhin.
// Copyright 2015-2019 Antony Polukhin.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -84,7 +84,7 @@ struct this_thread_frames { // struct is required to avoid warning about usage o
///
/// @b Async-Handler-Safety: Safe.
///
/// @returns Stored call sequence depth including terminating zero frame.
/// @returns Stored call sequence depth including terminating zero frame. To get the actually consumed bytes multiply this value by the sizeof(boost::stacktrace::frame::native_frame_ptr_t)
///
/// @param memory Preallocated buffer to store current function call sequence into.
///
@@ -99,7 +99,7 @@ BOOST_FORCEINLINE std::size_t safe_dump_to(void* memory, std::size_t size) BOOST
///
/// @b Async-Handler-Safety: Safe.
///
/// @returns Stored call sequence depth including terminating zero frame.
/// @returns Stored call sequence depth including terminating zero frame. To get the actually consumed bytes multiply this value by the sizeof(boost::stacktrace::frame::native_frame_ptr_t)
///
/// @param skip How many top calls to skip and do not store.
///

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -72,10 +72,9 @@ class basic_stacktrace {
try {
{ // Fast path without additional allocations
native_frame_ptr_t buffer[buffer_size];
const std::size_t frames_count = boost::stacktrace::detail::this_thread_frames::collect(buffer, buffer_size, frames_to_skip + 1);
if (buffer_size > frames_count || frames_count >= max_depth) {
const std::size_t size = (max_depth < frames_count ? max_depth : frames_count);
fill(buffer, size);
const std::size_t frames_count = boost::stacktrace::detail::this_thread_frames::collect(buffer, buffer_size < max_depth ? buffer_size : max_depth, frames_to_skip + 1);
if (buffer_size > frames_count || frames_count == max_depth) {
fill(buffer, frames_count);
return;
}
}
@@ -88,10 +87,9 @@ class basic_stacktrace {
#endif
std::vector<native_frame_ptr_t, allocator_void_t> buf(buffer_size * 2, 0, impl_.get_allocator());
do {
const std::size_t frames_count = boost::stacktrace::detail::this_thread_frames::collect(&buf[0], buf.size(), frames_to_skip + 1);
if (buf.size() > frames_count || frames_count >= max_depth) {
const std::size_t size = (max_depth < frames_count ? max_depth : frames_count);
fill(&buf[0], size);
const std::size_t frames_count = boost::stacktrace::detail::this_thread_frames::collect(&buf[0], buf.size() < max_depth ? buf.size() : max_depth, frames_to_skip + 1);
if (buf.size() > frames_count || frames_count == max_depth) {
fill(&buf[0], frames_count);
return;
}
@@ -319,6 +317,10 @@ public:
/// Constructs stacktrace from raw memory dump. Terminating zero frame is discarded.
///
/// @param begin Begining of the memory where the stacktrace was saved using the boost::stacktrace::safe_dump_to
///
/// @param buffer_size_in_bytes Size of the memory. Usually the same value that was passed to the boost::stacktrace::safe_dump_to
///
/// @b Complexity: O(size) in worst case
static basic_stacktrace from_dump(const void* begin, std::size_t buffer_size_in_bytes, const allocator_type& a = allocator_type()) {
basic_stacktrace ret(0, 0, a);
@@ -390,14 +392,20 @@ std::size_t hash_value(const basic_stacktrace<Allocator>& st) BOOST_NOEXCEPT {
return boost::hash_range(st.as_vector().begin(), st.as_vector().end());
}
/// Outputs stacktrace in a human readable format to output stream; unsafe to use in async handlers.
template <class CharT, class TraitsT, class Allocator>
std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const basic_stacktrace<Allocator>& bt) {
if (bt) {
os << boost::stacktrace::detail::to_string(&bt.as_vector()[0], bt.size());
/// Returns std::string with the stacktrace in a human readable format; unsafe to use in async handlers.
template <class Allocator>
std::string to_string(const basic_stacktrace<Allocator>& bt) {
if (!bt) {
return std::string();
}
return os;
return boost::stacktrace::detail::to_string(&bt.as_vector()[0], bt.size());
}
/// Outputs stacktrace in a human readable format to the output stream `os`; unsafe to use in async handlers.
template <class CharT, class TraitsT, class Allocator>
std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const basic_stacktrace<Allocator>& bt) {
return os << boost::stacktrace::to_string(bt);
}
/// This is the typedef to use unless you'd like to provide a specific allocator to boost::stacktrace::basic_stacktrace.

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,6 +1,6 @@
<!DOCTYPE html>
<!--
Copyright (c) 2014-2017 Antony Polukhin
Copyright (c) 2014-2019 Antony Polukhin
antoshkka at gmail dot com
Distributed under the Boost Software License,
@@ -29,7 +29,7 @@
<a href="../../doc/html/stacktrace.html">../../doc/html/stacktrace.html</a>
</p>
<p>
&copy; 2014-2017 Antony Polukhin
&copy; 2014-2019 Antony Polukhin
</p>
</body>
</html>

View File

@@ -8,6 +8,7 @@
"Antony Polukhin <antoshkka -at- gmail.com>"
],
"description": "Gather, store, copy and print backtraces.",
"std": [ "proposal" ],
"category": [
"System", "Correctness"
]

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2016-2018, Antony Polukhin.
# Copyright (C) 2016-2019, Antony Polukhin.
#
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -27,28 +27,28 @@ project
<target-os>linux:<linkflags>-lpthread
<warnings>all
<test-info>always_show_run_output
<visibility>hidden
;
local RDYNAMIC = <target-os>freebsd:<linkflags>"-rdynamic" <target-os>solaris:<linkflags>"-Bdynamic" <target-os>aix:<linkflags>"-rdynamic"
local FORCE_SYMBOL_EXPORT = <target-os>freebsd:<linkflags>"-rdynamic" <target-os>solaris:<linkflags>"-Bdynamic" <target-os>aix:<linkflags>"-rdynamic"
<target-os>qnxnto,<toolset>qcc:<linkflags>"-Bdynamic" <target-os>qnxnto,<toolset>gcc:<linkflags>"-rdynamic"
<target-os>android:<linkflags>"-rdynamic" <target-os>linux:<linkflags>"-rdynamic" <target-os>darwin,<toolset>gcc:<linkflags>"-dynamic"
<target-os>darwin,<toolset>clang:<linkflags>"-rdynamic" <target-os>iphone:<linkflags>"-rdynamic" ;
<target-os>darwin,<toolset>clang:<linkflags>"-rdynamic" <target-os>iphone:<linkflags>"-rdynamic"
<define>BOOST_STACKTRACE_TEST_EXPORTS_TABLE_USAGE ;
local HIDE_SYMBS = <target-os>linux:<cxxflags>"-fvisibility=hidden" ;
local BT_DEPS = $(HIDE_SYMBS) <target-os>linux:<library>dl <library>backtrace [ check-target-builds ../build//libbacktrace : : <build>no ] ;
local AD2L_DEPS = $(HIDE_SYMBS) <target-os>linux:<library>dl [ check-target-builds ../build//addr2line : : <build>no ] ;
local WIND_DEPS = $(HIDE_SYMBS) <library>Dbgeng <library>ole32 [ check-target-builds ../build//WinDbg : : <build>no ] ;
local WICA_DEPS = $(HIDE_SYMBS) <library>Dbgeng <library>ole32 [ check-target-builds ../build//WinDbgCached : : <build>no ] ;
local NOOP_DEPS = $(HIDE_SYMBS) ;
local BASIC_DEPS = $(RDYNAMIC) <target-os>linux:<library>dl [ check-target-builds ../build//WinDbg : <build>no ] ;
local BT_DEPS = <target-os>linux:<library>dl <library>backtrace [ check-target-builds ../build//libbacktrace : : <build>no ] ;
local AD2L_DEPS = <target-os>linux:<library>dl [ check-target-builds ../build//addr2line : : <build>no ] ;
local WIND_DEPS = <library>Dbgeng <library>ole32 [ check-target-builds ../build//WinDbg : : <build>no ] ;
local WICA_DEPS = <library>Dbgeng <library>ole32 [ check-target-builds ../build//WinDbgCached : : <build>no ] ;
local NOOP_DEPS = ;
local BASIC_DEPS = <target-os>linux:<library>dl [ check-target-builds ../build//WinDbg : <build>no ] ;
local LINKSHARED_BT = <link>shared <define>BOOST_STACKTRACE_DYN_LINK <library>/boost/stacktrace//boost_stacktrace_backtrace $(BT_DEPS) ;
local LINKSHARED_AD2L = <link>shared <define>BOOST_STACKTRACE_DYN_LINK <library>/boost/stacktrace//boost_stacktrace_addr2line $(AD2L_DEPS) ;
local LINKSHARED_WIND = <link>shared <define>BOOST_STACKTRACE_DYN_LINK <library>/boost/stacktrace//boost_stacktrace_windbg $(WIND_DEPS) ;
local LINKSHARED_WIND_CACHED = <link>shared <define>BOOST_STACKTRACE_DYN_LINK <library>/boost/stacktrace//boost_stacktrace_windbg_cached $(WICA_DEPS) ;
local LINKSHARED_NOOP = <link>shared <define>BOOST_STACKTRACE_DYN_LINK <library>/boost/stacktrace//boost_stacktrace_noop $(NOOP_DEPS) ;
local LINKSHARED_BASIC = <link>shared <define>BOOST_STACKTRACE_DYN_LINK <library>/boost/stacktrace//boost_stacktrace_basic $(BASIC_DEPS) ;
local LINKSHARED_BASIC = <link>shared <define>BOOST_STACKTRACE_DYN_LINK <library>/boost/stacktrace//boost_stacktrace_basic $(BASIC_DEPS) $(FORCE_SYMBOL_EXPORT) ;
# Libs with debug symbols
lib test_impl_lib_backtrace : test_impl.cpp : <debug-symbols>on $(LINKSHARED_BT) ;
@@ -76,12 +76,13 @@ test-suite stacktrace_tests
:
# Header only tests with debug symbols
[ run test.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_BACKTRACE $(BT_DEPS) : backtrace_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_ADDR2LINE $(AD2L_DEPS) : addr2line_ho ]
[ run test_noop.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_NOOP $(NOOP_DEPS) : noop_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on $(WIND_DEPS) : windbg_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_WINDBG_CACHED $(WICA_DEPS) : windbg_cached_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on $(BASIC_DEPS) : basic_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_BACKTRACE $(BT_DEPS) : backtrace_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_ADDR2LINE $(AD2L_DEPS) : addr2line_ho ]
[ run test_noop.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_NOOP $(NOOP_DEPS) : noop_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on $(WIND_DEPS) : windbg_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_WINDBG_CACHED $(WICA_DEPS) : windbg_cached_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on $(FORCE_SYMBOL_EXPORT) $(BASIC_DEPS) : basic_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL $(BASIC_DEPS) : basic_ho_empty ]
# Test with shared linked implementations with debug symbols
[ run test.cpp : : : <debug-symbols>on <library>.//test_impl_lib_backtrace $(LINKSHARED_BT) : backtrace_lib ]
@@ -117,22 +118,23 @@ test-suite stacktrace_tests
##### Tests with disabled debug symbols #####
# Header only tests without debug symbols
[ run test.cpp test_impl.cpp : : : <debug-symbols>off <define>BOOST_STACKTRACE_USE_BACKTRACE <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL $(BT_DEPS) : backtrace_ho_no_dbg ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>off <define>BOOST_STACKTRACE_USE_BACKTRACE $(FORCE_SYMBOL_EXPORT) $(BT_DEPS) : backtrace_ho_no_dbg ]
[ run test_noop.cpp test_impl.cpp : : : <debug-symbols>off <define>BOOST_STACKTRACE_USE_NOOP $(NOOP_DEPS) : noop_ho_no_dbg ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>off <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL $(WIND_DEPS) : windbg_ho_no_dbg ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>off <define>BOOST_STACKTRACE_USE_WINDBG_CACHED <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL $(WICA_DEPS) : windbg_cached_ho_no_dbg ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>off $(BASIC_DEPS) : basic_ho_no_dbg ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>off $(FORCE_SYMBOL_EXPORT) $(BASIC_DEPS) : basic_ho_no_dbg ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>off <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL $(BASIC_DEPS) : basic_ho_no_dbg_empty ]
[ run test.cpp test_impl.cpp
: : : <debug-symbols>off <define>BOOST_STACKTRACE_USE_ADDR2LINE <define>BOOST_STACKTRACE_ADDR2LINE_LOCATION="/usr/bin/addr2line" $(AD2L_DEPS)
: addr2line_ho_no_dbg ]
# Test with shared linked implementations without debug symbols
[ run test.cpp : : : <debug-symbols>off <library>.//test_impl_lib_backtrace_no_dbg $(LINKSHARED_BT) <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL : backtrace_lib_no_dbg ]
[ run test.cpp : : : <debug-symbols>off <library>.//test_impl_lib_addr2line_no_dbg $(LINKSHARED_AD2L) : addr2line_lib_no_dbg ]
[ run test.cpp : : : <debug-symbols>off <library>.//test_impl_lib_windbg_no_dbg $(LINKSHARED_WIND) <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL : windbg_lib_no_dbg ]
[ run test.cpp : : : <debug-symbols>off <library>.//test_impl_lib_windbg_cached_no_dbg $(LINKSHARED_WIND_CACHED) <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL : windbg_cached_lib_no_dbg ]
[ run test_noop.cpp : : : <debug-symbols>off <library>.//test_impl_lib_noop_no_dbg $(LINKSHARED_NOOP) : noop_lib_no_dbg ]
[ run test.cpp : : : <debug-symbols>off <library>.//test_impl_lib_basic_no_dbg $(LINKSHARED_BASIC) : basic_lib_no_dbg ]
[ run test.cpp : : : <debug-symbols>off <library>.//test_impl_lib_backtrace_no_dbg $(LINKSHARED_BT) $(FORCE_SYMBOL_EXPORT) : backtrace_lib_no_dbg ]
[ run test.cpp : : : <debug-symbols>off <library>.//test_impl_lib_addr2line_no_dbg $(LINKSHARED_AD2L) : addr2line_lib_no_dbg ]
[ run test.cpp : : : <debug-symbols>off <library>.//test_impl_lib_windbg_no_dbg $(LINKSHARED_WIND) <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL : windbg_lib_no_dbg ]
[ run test.cpp : : : <debug-symbols>off <library>.//test_impl_lib_windbg_cached_no_dbg $(LINKSHARED_WIND_CACHED) <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL : windbg_cached_lib_no_dbg ]
[ run test_noop.cpp : : : <debug-symbols>off <library>.//test_impl_lib_noop_no_dbg $(LINKSHARED_NOOP) : noop_lib_no_dbg ]
[ run test.cpp : : : <debug-symbols>off <library>.//test_impl_lib_basic_no_dbg $(LINKSHARED_BASIC) : basic_lib_no_dbg ]
# Thread safety without debug symbols
[ run thread_safety_checking.cpp
@@ -182,6 +184,7 @@ test-suite stacktrace_tests
: windbg_cached_lib_threaded_com_st ]
[ run test_void_ptr_cast.cpp ]
[ run test_num_conv.cpp ]
;
# Assuring that examples compile and run. Adding sources from `examples` directory to the `type_index` test suite.
@@ -213,3 +216,21 @@ for local p in [ glob ../example/*.cpp ]
}
# Very long tests for detecting memory leaks and corruptions
test-suite stacktrace_torture
:
[ run torture.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_BACKTRACE $(BT_DEPS) : torture_backtrace_ho ]
#[ run torture.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_ADDR2LINE $(AD2L_DEPS) : torture_addr2line_ho ]
[ run torture.cpp test_impl.cpp : : : <debug-symbols>on $(WIND_DEPS) : torture_windbg_ho ]
[ run torture.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_WINDBG_CACHED $(WICA_DEPS) : torture_windbg_cached_ho ]
[ run torture.cpp test_impl.cpp : : : <debug-symbols>on $(FORCE_SYMBOL_EXPORT) $(BASIC_DEPS) : torture_basic_ho ]
[ run torture.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL $(BASIC_DEPS) : torture_basic_ho_empty ]
[ run torture.cpp test_impl.cpp : : : <debug-symbols>on <library>.//test_impl_lib_backtrace $(LINKSHARED_BT) : torture_backtrace_lib ]
#[ run torture.cpp test_impl.cpp : : : <debug-symbols>on <library>.//test_impl_lib_addr2line $(LINKSHARED_AD2L) : torture_addr2line_lib ]
[ run torture.cpp test_impl.cpp : : : <debug-symbols>on <library>.//test_impl_lib_windbg $(LINKSHARED_WIND) : torture_windbg_lib ]
[ run torture.cpp test_impl.cpp : : : <debug-symbols>on <library>.//test_impl_lib_windbg_cached $(LINKSHARED_WIND_CACHED) : torture_windbg_cached_lib ]
[ run torture.cpp test_impl.cpp : : : <debug-symbols>on <library>.//test_impl_lib_basic $(LINKSHARED_BASIC) : torture_basic_lib ]
;
explicit stacktrace_torture ;

View File

@@ -2,7 +2,7 @@
# subject to 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)
#
# Copyright Antony Polukhin 2016-2017.
# Copyright Antony Polukhin 2016-2019.
#
# See https://svn.boost.org/trac/boost/wiki/TravisCoverals for description of this file

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -14,50 +14,25 @@
#include <boost/functional/hash.hpp>
#include "test_impl.hpp"
using boost::stacktrace::stacktrace;
using boost::stacktrace::frame;
#ifdef BOOST_STACKTRACE_DYN_LINK
# define BOOST_ST_API BOOST_SYMBOL_IMPORT
#else
# define BOOST_ST_API
#endif
#if (defined(BOOST_GCC) && defined(BOOST_WINDOWS) && !defined(BOOST_STACKTRACE_USE_BACKTRACE) && !defined(BOOST_STACKTRACE_USE_ADDR2LINE)) \
|| defined(BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL)
# define BOOST_STACKTRACE_SYMNAME 0
# define BOOST_STACKTRACE_TEST_SHOULD_OUTPUT_READABLE_NAMES 0
#else
# define BOOST_STACKTRACE_SYMNAME 1
# define BOOST_STACKTRACE_TEST_SHOULD_OUTPUT_READABLE_NAMES 1
#endif
typedef std::pair<stacktrace, stacktrace> (*foo1_t)(int i);
BOOST_ST_API std::pair<stacktrace, stacktrace> foo2(int i, foo1_t foo1);
BOOST_ST_API stacktrace return_from_nested_namespaces();
BOOST_ST_API boost::stacktrace::stacktrace bar1();
BOOST_ST_API boost::stacktrace::stacktrace bar2();
BOOST_NOINLINE std::pair<stacktrace, stacktrace> foo1(int i) {
if (i) {
return foo2(i - 1, foo1);
}
std::pair<stacktrace, stacktrace> ret;
try {
throw std::logic_error("test");
} catch (const std::logic_error& /*e*/) {
ret.second = stacktrace();
return ret;
}
}
void test_deeply_nested_namespaces() {
std::stringstream ss;
ss << return_from_nested_namespaces();
std::cout << ss.str() << '\n';
#if BOOST_STACKTRACE_SYMNAME
#if BOOST_STACKTRACE_TEST_SHOULD_OUTPUT_READABLE_NAMES
BOOST_TEST(ss.str().find("main") != std::string::npos);
BOOST_TEST(ss.str().find("get_backtrace_from_nested_namespaces") != std::string::npos
@@ -72,14 +47,16 @@ void test_deeply_nested_namespaces() {
// Template parameter Depth is to produce different functions on each Depth. This simplifies debugging when one of the tests catches error
template <std::size_t Depth>
void test_nested() {
std::pair<stacktrace, stacktrace> res = foo2(Depth, foo1);
void test_nested(bool print = true) {
std::pair<stacktrace, stacktrace> res = function_from_library(Depth, function_from_main_translation_unit);
std::stringstream ss1, ss2;
ss1 << res.first;
ss2 << res.second;
std::cout << "'" << ss1.str() << "'\n\n" << ss2.str() << std::endl;
if (print) {
std::cout << "'" << ss1.str() << "'\n\n" << ss2.str() << std::endl;
}
BOOST_TEST(!ss1.str().empty());
BOOST_TEST(!ss2.str().empty());
@@ -92,15 +69,15 @@ void test_nested() {
BOOST_TEST(ss1.str().find(" in ") != std::string::npos);
BOOST_TEST(ss2.str().find(" in ") != std::string::npos);
#if BOOST_STACKTRACE_SYMNAME
#if BOOST_STACKTRACE_TEST_SHOULD_OUTPUT_READABLE_NAMES
BOOST_TEST(ss1.str().find("main") != std::string::npos);
BOOST_TEST(ss2.str().find("main") != std::string::npos);
BOOST_TEST(ss1.str().find("foo2") != std::string::npos);
BOOST_TEST(ss2.str().find("foo2") != std::string::npos);
BOOST_TEST(ss1.str().find("function_from_library") != std::string::npos);
BOOST_TEST(ss2.str().find("function_from_library") != std::string::npos);
BOOST_TEST(ss1.str().find("foo1") != std::string::npos);
BOOST_TEST(ss2.str().find("foo1") != std::string::npos);
BOOST_TEST(ss1.str().find("function_from_main_translation_unit") != std::string::npos);
BOOST_TEST(ss2.str().find("function_from_main_translation_unit") != std::string::npos);
#endif
//BOOST_TEST(false);
@@ -194,7 +171,7 @@ void test_iterators() {
void test_frame() {
stacktrace nst = return_from_nested_namespaces();
stacktrace st;
stacktrace st = make_some_stacktrace1();
const std::size_t min_size = (nst.size() < st.size() ? nst.size() : st.size());
BOOST_TEST(min_size > 2);
@@ -270,14 +247,14 @@ int main() {
test_empty_basic_stacktrace<true>();
test_empty_basic_stacktrace<false>();
BOOST_TEST(&bar1 != &bar2);
boost::stacktrace::stacktrace b1 = bar1();
BOOST_TEST(&make_some_stacktrace1 != &make_some_stacktrace2);
boost::stacktrace::stacktrace b1 = make_some_stacktrace1();
BOOST_TEST(b1.size() == 4);
boost::stacktrace::stacktrace b2 = bar2();
boost::stacktrace::stacktrace b2 = make_some_stacktrace2();
BOOST_TEST(b2.size() == 4);
test_comparisons_base(bar1(), bar2());
test_comparisons_base(make_some_stacktrace1(), make_some_stacktrace2());
test_nested<300>();
test_nested<260>(false);
BOOST_TEST(boost::stacktrace::stacktrace(0, 1).size() == 1);
BOOST_TEST(boost::stacktrace::stacktrace(1, 1).size() == 1);

View File

@@ -1,32 +1,15 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// 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)
#include <boost/stacktrace/stacktrace.hpp>
#if defined(BOOST_LEXICAL_CAST_TRY_LEXICAL_CONVERT_HPP) || defined(BOOST_LEXICAL_CAST_BAD_LEXICAL_CAST_HPP)
#error "LexicalCast headers leaked into the boost/stacktrace/stacktrace.hpp"
#endif
#if !defined(BOOST_USE_WINDOWS_H) && defined(_WINDOWS_H)
#error "windows.h header leaked into the boost/stacktrace/stacktrace.hpp"
#endif
#include <stdexcept>
#define BOOST_STACKTRACE_TEST_IMPL_LIB 1
#include "test_impl.hpp"
using namespace boost::stacktrace;
#ifdef BOOST_STACKTRACE_DYN_LINK
# define BOOST_ST_API BOOST_SYMBOL_EXPORT
#else
# define BOOST_ST_API
#endif
typedef std::pair<stacktrace, stacktrace> (*foo1_t)(int i);
BOOST_ST_API BOOST_NOINLINE std::pair<stacktrace, stacktrace> foo2(int i, foo1_t foo1) {
BOOST_ST_API BOOST_NOINLINE std::pair<stacktrace, stacktrace> function_from_library(int i, foo1_t foo1) {
if (i) {
return foo1(--i);
} else {
@@ -59,31 +42,31 @@ BOOST_ST_API BOOST_NOINLINE stacktrace return_from_nested_namespaces() {
return get_backtrace_from_nested_namespaces();
}
BOOST_ST_API BOOST_NOINLINE boost::stacktrace::stacktrace bar1_impl(int d = 0) {
BOOST_ST_API BOOST_NOINLINE boost::stacktrace::stacktrace make_some_stacktrace1_impl(int d = 0) {
boost::stacktrace::stacktrace result(0, 4);
if (result.size() < 4) {
if (d > 4) throw std::runtime_error("Stack is not growing in test OR stacktrace fails to work in `bar1` function.");
return bar1_impl(d + 1);
return make_some_stacktrace1_impl(d + 1);
}
return result;
}
BOOST_ST_API BOOST_NOINLINE boost::stacktrace::stacktrace bar2_impl(int d = 0) {
BOOST_ST_API BOOST_NOINLINE boost::stacktrace::stacktrace make_some_stacktrace2_impl(int d = 0) {
boost::stacktrace::stacktrace result(0, 4);
if (result.size() < 4) {
if (d > 4) throw std::runtime_error("Stack is not growing in test OR stacktrace fails to work in `bar2` function.");
return bar2_impl(d + 1);
return make_some_stacktrace2_impl(d + 1);
}
return result;
}
BOOST_ST_API BOOST_NOINLINE boost::stacktrace::stacktrace bar1() {
boost::stacktrace::stacktrace result = bar1_impl();
BOOST_ST_API BOOST_NOINLINE boost::stacktrace::stacktrace make_some_stacktrace1() {
boost::stacktrace::stacktrace result = make_some_stacktrace1_impl();
return result;
}
BOOST_ST_API BOOST_NOINLINE boost::stacktrace::stacktrace bar2() {
boost::stacktrace::stacktrace result = bar2_impl();
BOOST_ST_API BOOST_NOINLINE boost::stacktrace::stacktrace make_some_stacktrace2() {
boost::stacktrace::stacktrace result = make_some_stacktrace2_impl();
return result;
}

58
test/test_impl.hpp Normal file
View File

@@ -0,0 +1,58 @@
// Copyright Antony Polukhin, 2016-2019.
//
// 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)
#include <boost/stacktrace/stacktrace.hpp>
#if defined(BOOST_LEXICAL_CAST_TRY_LEXICAL_CONVERT_HPP) || defined(BOOST_LEXICAL_CAST_BAD_LEXICAL_CAST_HPP)
#error "LexicalCast headers leaked into the boost/stacktrace/stacktrace.hpp"
#endif
#if !defined(BOOST_USE_WINDOWS_H) && defined(_WINDOWS_H)
#error "windows.h header leaked into the boost/stacktrace/stacktrace.hpp"
#endif
#include <stdexcept>
using namespace boost::stacktrace;
#ifdef BOOST_STACKTRACE_DYN_LINK
# ifdef BOOST_STACKTRACE_TEST_IMPL_LIB
# define BOOST_ST_API BOOST_SYMBOL_EXPORT
# else
# define BOOST_ST_API BOOST_SYMBOL_IMPORT
# endif
#else
# ifdef BOOST_STACKTRACE_TEST_EXPORTS_TABLE_USAGE
# define BOOST_ST_API BOOST_SYMBOL_VISIBLE
# else
# define BOOST_ST_API
# endif
#endif
typedef std::pair<boost::stacktrace::stacktrace, boost::stacktrace::stacktrace> st_pair;
typedef st_pair (*foo1_t)(int i);
BOOST_ST_API st_pair function_from_library(int i, foo1_t foo1);
BOOST_ST_API boost::stacktrace::stacktrace return_from_nested_namespaces();
BOOST_ST_API boost::stacktrace::stacktrace make_some_stacktrace1();
BOOST_ST_API boost::stacktrace::stacktrace make_some_stacktrace2();
#ifdef BOOST_STACKTRACE_TEST_EXPORTS_TABLE_USAGE
BOOST_SYMBOL_VISIBLE
#endif
inline st_pair function_from_main_translation_unit(int i) {
if (i) {
return function_from_library(i - 1, function_from_main_translation_unit);
}
std::pair<stacktrace, stacktrace> ret;
try {
throw std::logic_error("test");
} catch (const std::logic_error& /*e*/) {
ret.second = stacktrace();
return ret;
}
}

View File

@@ -1,44 +1,21 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// 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)
#include "test_impl.hpp"
#include <boost/stacktrace.hpp>
#include <boost/core/lightweight_test.hpp>
#include <stdexcept>
#include <boost/functional/hash.hpp>
using boost::stacktrace::stacktrace;
using boost::stacktrace::frame;
#ifdef BOOST_STACKTRACE_DYN_LINK
# define BOOST_ST_API BOOST_SYMBOL_IMPORT
#else
# define BOOST_ST_API
#endif
typedef std::pair<stacktrace, stacktrace> (*foo1_t)(int i);
BOOST_ST_API std::pair<stacktrace, stacktrace> foo2(int i, foo1_t foo1);
BOOST_ST_API stacktrace return_from_nested_namespaces();
BOOST_NOINLINE std::pair<stacktrace, stacktrace> foo1(int i) {
if (i) {
return foo2(i - 1, foo1);
}
std::pair<stacktrace, stacktrace> ret;
try {
throw std::logic_error("test");
} catch (const std::logic_error& /*e*/) {
ret.second = stacktrace();
return ret;
}
}
void test_deeply_nested_namespaces() {
BOOST_TEST(return_from_nested_namespaces().size() == 0);
BOOST_TEST(return_from_nested_namespaces().empty());
@@ -46,7 +23,7 @@ void test_deeply_nested_namespaces() {
}
void test_nested() {
std::pair<stacktrace, stacktrace> res = foo2(15, foo1);
std::pair<stacktrace, stacktrace> res = function_from_library(15, function_from_main_translation_unit);
BOOST_TEST(!res.first);
BOOST_TEST(res.first.empty());

71
test/test_num_conv.cpp Normal file
View File

@@ -0,0 +1,71 @@
// Copyright Antony Polukhin, 2016-2019.
//
// 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)
#include <boost/stacktrace/detail/to_dec_array.hpp>
#include <boost/stacktrace/detail/to_hex_array.hpp>
#include <boost/stacktrace/detail/try_dec_convert.hpp>
#include <boost/core/lightweight_test.hpp>
#include <string>
#include <iostream>
void test_to_hex_array() {
const void* ptr = 0;
BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("0x0") != std::string::npos);
ptr = reinterpret_cast<const void*>(0x10);
BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("10") != std::string::npos);
ptr = reinterpret_cast<void*>(0x19);
BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("19") != std::string::npos);
ptr = reinterpret_cast<void*>(0x999999);
BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("999999") != std::string::npos);
}
void test_to_dec_array() {
BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(0).data()), std::string("0"));
BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(10).data()), std::string("10"));
BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(19).data()), std::string("19"));
BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(999999).data()), std::string("999999"));
}
void test_try_dec_convert() {
std::size_t res = 0;
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("0", res));
BOOST_TEST(res == 0);
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("+0", res));
BOOST_TEST(res == 0);
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("10", res));
BOOST_TEST(res == 10);
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("19", res));
BOOST_TEST(res == 19);
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("+19", res));
BOOST_TEST(res == 19);
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("9999", res));
BOOST_TEST(res == 9999);
BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("q", res));
BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("0z", res));
BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("0u", res));
BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("+0u", res));
}
int main() {
test_to_hex_array();
test_to_dec_array();
test_try_dec_convert();
return boost::report_errors();
}

View File

@@ -1,9 +1,10 @@
// Copyright Antony Polukhin, 2016-2017.
// Copyright Antony Polukhin, 2016-2019.
//
// 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)
#include "test_impl.hpp"
#include <boost/stacktrace/stacktrace_fwd.hpp>
#include <sstream>
@@ -15,31 +16,8 @@
#include <boost/timer/timer.hpp>
#ifdef BOOST_STACKTRACE_DYN_LINK
# define BOOST_ST_API BOOST_SYMBOL_IMPORT
#else
# define BOOST_ST_API
#endif
using boost::stacktrace::stacktrace;
typedef std::pair<stacktrace, stacktrace> (*foo1_t)(int i);
BOOST_ST_API std::pair<stacktrace, stacktrace> foo2(int i, foo1_t foo1);
BOOST_ST_API stacktrace return_from_nested_namespaces();
BOOST_NOINLINE std::pair<stacktrace, stacktrace> foo1(int i) {
if (i) {
return foo2(i - 1, foo1);
}
std::pair<stacktrace, stacktrace> ret;
try {
throw std::logic_error("test");
} catch (const std::logic_error& /*e*/) {
ret.second = stacktrace();
return ret;
}
}
void main_test_loop() {
std::size_t loops = 100;
@@ -49,7 +27,7 @@ void main_test_loop() {
std::stringstream ss_ethalon;
while (--loops) {
std::pair<stacktrace, stacktrace> res = foo2(Depth, foo1);
std::pair<stacktrace, stacktrace> res = function_from_library(Depth, function_from_main_translation_unit);
if (ethalon) {
BOOST_TEST(res == *ethalon);

26
test/torture.cpp Normal file
View File

@@ -0,0 +1,26 @@
// Copyright Antony Polukhin, 2018.
//
// 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)
// This file tests for memory leaks. Some of the backtrace implementations
// consume memory for internal needs and incorrect usage of those implementations
// could lead to segfaults. Sanitizers do not detect such misuse, but this
// test and `top` does.
#include <boost/stacktrace.hpp>
#include <iostream>
#include "test_impl.hpp"
int main() {
int result = 0;
for (unsigned i = 0; i < 10000000; ++i) {
result += make_some_stacktrace1()[0].source_line();
}
std::cerr << "OK\nLines count " << result;
}