diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-11 21:19:30 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-11 21:19:30 +0300 |
commit | 086d452fbb92465b3251e6210cf476990c74983e (patch) | |
tree | 883938357ead649f38d7eb5ffe17d72786fbbcd9 | |
parent | bd5d3bed530e4e968071e27b39bb7d82ec296389 (diff) | |
download | ydb-086d452fbb92465b3251e6210cf476990c74983e.tar.gz |
intermediate changes
ref:48e6218a168cd73f6795cee2a5d673003780b3cb
27 files changed, 286 insertions, 76 deletions
diff --git a/build/platform/cuda/ya.make b/build/platform/cuda/ya.make index e8884fd1cfc..4a33666bb13 100644 --- a/build/platform/cuda/ya.make +++ b/build/platform/cuda/ya.make @@ -1,6 +1,6 @@ RESOURCES_LIBRARY() -# https://wiki.yandex-team.ru/devtools/cuda/ +# https://docs.yandex-team.ru/ya-make/manual/project_specific/cuda#cuda_host_compiler OWNER(g:contrib somov) diff --git a/build/scripts/build_java_with_error_prone2.py b/build/scripts/build_java_with_error_prone2.py index 4efc1e444a6..ddf1ccbfc1c 100644 --- a/build/scripts/build_java_with_error_prone2.py +++ b/build/scripts/build_java_with_error_prone2.py @@ -25,7 +25,7 @@ JAVA10_EXPORTS = [ def get_java_version(exe): p = subprocess.Popen([exe, '-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() - for line in ((out or '').strip() + (err or '').strip()).split("\n"): + for line in (out or '').strip().split("\n") + (err or '').strip().split("\n"): m = re.match(r'java version "(.+)"', line) if m: parts = m.groups()[0].split(".") diff --git a/contrib/restricted/boost/boost/stacktrace.hpp b/contrib/restricted/boost/boost/stacktrace.hpp index 6e1ec0489a1..b458e3ad12c 100644 --- a/contrib/restricted/boost/boost/stacktrace.hpp +++ b/contrib/restricted/boost/boost/stacktrace.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/detail/addr2line_impls.hpp b/contrib/restricted/boost/boost/stacktrace/detail/addr2line_impls.hpp index e314fe9f31c..d54fd8247a1 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/addr2line_impls.hpp +++ b/contrib/restricted/boost/boost/stacktrace/detail/addr2line_impls.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // 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; } diff --git a/contrib/restricted/boost/boost/stacktrace/detail/collect_msvc.ipp b/contrib/restricted/boost/boost/stacktrace/detail/collect_msvc.ipp index 37d3a298ac8..7d41eb3515c 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/collect_msvc.ipp +++ b/contrib/restricted/boost/boost/stacktrace/detail/collect_msvc.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/detail/collect_noop.ipp b/contrib/restricted/boost/boost/stacktrace/detail/collect_noop.ipp index bcfae4c400b..ca251c393f9 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/collect_noop.ipp +++ b/contrib/restricted/boost/boost/stacktrace/detail/collect_noop.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/detail/collect_unwind.ipp b/contrib/restricted/boost/boost/stacktrace/detail/collect_unwind.ipp index 98d8fcb7f89..6f99d4ad111 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/collect_unwind.ipp +++ b/contrib/restricted/boost/boost/stacktrace/detail/collect_unwind.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // 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; } - - boost::stacktrace::detail::unwind_state state = { skip + 1, out_frames, out_frames + max_frames_count }; + skip += 1; + +#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 diff --git a/contrib/restricted/boost/boost/stacktrace/detail/frame_decl.hpp b/contrib/restricted/boost/boost/stacktrace/detail/frame_decl.hpp index 1919f6a4e8e..6248757ecb6 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/frame_decl.hpp +++ b/contrib/restricted/boost/boost/stacktrace/detail/frame_decl.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/detail/frame_msvc.ipp b/contrib/restricted/boost/boost/stacktrace/detail/frame_msvc.ipp index 6e5eb490c65..2e7a3af6e1e 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/frame_msvc.ipp +++ b/contrib/restricted/boost/boost/stacktrace/detail/frame_msvc.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // 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" @@ -98,7 +98,7 @@ public: }; -static std::string mingw_demangling_workaround(const std::string& s) { +inline std::string mingw_demangling_workaround(const std::string& s) { #ifdef BOOST_GCC if (s.empty()) { return s; @@ -114,6 +114,17 @@ static std::string mingw_demangling_workaround(const std::string& s) { #endif } +inline void trim_right_zeroes(std::string& s) { + // MSVC-9 does not have back() and pop_back() functions in std::string + while (!s.empty()) { + const std::size_t last = static_cast<std::size_t>(s.size() - 1); + if (s[last] != '\0') { + break; + } + s.resize(last); + } +} + class debugging_symbols: boost::noncopyable { static void try_init_com(com_holder< ::IDebugSymbols>& idebug, const com_global_initer& com) BOOST_NOEXCEPT { com_holder< ::IDebugClient> iclient(com); @@ -217,6 +228,7 @@ public: &size, 0 )); + trim_right_zeroes(result); } else if (res) { result = name; } @@ -301,6 +313,7 @@ public: &size, 0 )); + trim_right_zeroes(result.first); result.second = line_num; if (!res) { @@ -329,7 +342,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 +362,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); diff --git a/contrib/restricted/boost/boost/stacktrace/detail/frame_noop.ipp b/contrib/restricted/boost/boost/stacktrace/detail/frame_noop.ipp index b9b1b988008..7bac4c22447 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/frame_noop.ipp +++ b/contrib/restricted/boost/boost/stacktrace/detail/frame_noop.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/detail/frame_unwind.ipp b/contrib/restricted/boost/boost/stacktrace/detail/frame_unwind.ipp index d4e79739685..a5e21029f74 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/frame_unwind.ipp +++ b/contrib/restricted/boost/boost/stacktrace/detail/frame_unwind.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // 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> @@ -59,6 +59,9 @@ public: std::string to_string(const frame* frames, std::size_t size) { std::string res; + if (size == 0) { + return res; + } res.reserve(64 * size); to_string_impl impl; @@ -67,7 +70,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()); @@ -82,9 +85,13 @@ std::string to_string(const frame* frames, std::size_t size) { std::string frame::name() const { + if (!addr_) { + return std::string(); + } + #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); } @@ -93,6 +100,10 @@ std::string frame::name() const { } std::string to_string(const frame& f) { + if (!f) { + return std::string(); + } + boost::stacktrace::detail::to_string_impl impl; return impl(f.address()); } diff --git a/contrib/restricted/boost/boost/stacktrace/detail/libbacktrace_impls.hpp b/contrib/restricted/boost/boost/stacktrace/detail/libbacktrace_impls.hpp index 121c41bffa3..593133c3c61 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/libbacktrace_impls.hpp +++ b/contrib/restricted/boost/boost/stacktrace/detail/libbacktrace_impls.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // 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,56 @@ 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. - /* + // TODO: The most obvious solution: + // static ::backtrace_state* state = ::backtrace_create_state( - 0, 1 , boost::stacktrace::detail::libbacktrace_error_callback, 0 + 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. + +// Code from TODO works fine in Arcadia (with statically linked libbacktrace) -- bugaevskiy@ +#if 0 +#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__) && !defined(__clang__) + 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 + ); +#endif return state; - */ } struct to_string_using_backtrace { @@ -86,6 +128,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 +149,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 +175,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()) { @@ -139,6 +197,10 @@ inline std::string name_impl(const void* addr) { std::string frame::source_file() const { std::string res; + if (!addr_) { + return res; + } + boost::stacktrace::detail::program_location prog_location; ::backtrace_state* state = boost::stacktrace::detail::construct_state(prog_location); @@ -157,6 +219,10 @@ std::string frame::source_file() const { } std::size_t frame::source_line() const { + if (!addr_) { + return 0; + } + boost::stacktrace::detail::program_location prog_location; ::backtrace_state* state = boost::stacktrace::detail::construct_state(prog_location); diff --git a/contrib/restricted/boost/boost/stacktrace/detail/location_from_symbol.hpp b/contrib/restricted/boost/boost/stacktrace/detail/location_from_symbol.hpp index 534ac91075b..5d6e2f19f70 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/location_from_symbol.hpp +++ b/contrib/restricted/boost/boost/stacktrace/detail/location_from_symbol.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // 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; } } diff --git a/contrib/restricted/boost/boost/stacktrace/detail/pop_options.h b/contrib/restricted/boost/boost/stacktrace/detail/pop_options.h index 8995b00adab..5ab5fc6a213 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/pop_options.h +++ b/contrib/restricted/boost/boost/stacktrace/detail/pop_options.h @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/detail/push_options.h b/contrib/restricted/boost/boost/stacktrace/detail/push_options.h index 3adb626121a..6d7e46b7ae9 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/push_options.h +++ b/contrib/restricted/boost/boost/stacktrace/detail/push_options.h @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/detail/safe_dump_noop.ipp b/contrib/restricted/boost/boost/stacktrace/detail/safe_dump_noop.ipp index 78fdc3a8aeb..2bda3c92f90 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/safe_dump_noop.ipp +++ b/contrib/restricted/boost/boost/stacktrace/detail/safe_dump_noop.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/detail/safe_dump_posix.ipp b/contrib/restricted/boost/boost/stacktrace/detail/safe_dump_posix.ipp index 97792c94b74..bc79d5c8d84 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/safe_dump_posix.ipp +++ b/contrib/restricted/boost/boost/stacktrace/detail/safe_dump_posix.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/detail/safe_dump_win.ipp b/contrib/restricted/boost/boost/stacktrace/detail/safe_dump_win.ipp index 23e81aab483..ab5445a8aa0 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/safe_dump_win.ipp +++ b/contrib/restricted/boost/boost/stacktrace/detail/safe_dump_win.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2018. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/detail/to_dec_array.hpp b/contrib/restricted/boost/boost/stacktrace/detail/to_dec_array.hpp new file mode 100644 index 00000000000..8cdcdfcf88d --- /dev/null +++ b/contrib/restricted/boost/boost/stacktrace/detail/to_dec_array.hpp @@ -0,0 +1,46 @@ +// Copyright Antony Polukhin, 2016-2021. +// +// 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 diff --git a/contrib/restricted/boost/boost/stacktrace/detail/to_hex_array.hpp b/contrib/restricted/boost/boost/stacktrace/detail/to_hex_array.hpp index dd55ded8b63..84d88bff9ba 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/to_hex_array.hpp +++ b/contrib/restricted/boost/boost/stacktrace/detail/to_hex_array.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/detail/try_dec_convert.hpp b/contrib/restricted/boost/boost/stacktrace/detail/try_dec_convert.hpp new file mode 100644 index 00000000000..46d811edb1a --- /dev/null +++ b/contrib/restricted/boost/boost/stacktrace/detail/try_dec_convert.hpp @@ -0,0 +1,29 @@ +// Copyright Antony Polukhin, 2016-2021. +// +// 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 diff --git a/contrib/restricted/boost/boost/stacktrace/detail/unwind_base_impls.hpp b/contrib/restricted/boost/boost/stacktrace/detail/unwind_base_impls.hpp index 18a2378d259..9a4566a4c2c 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/unwind_base_impls.hpp +++ b/contrib/restricted/boost/boost/stacktrace/detail/unwind_base_impls.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/detail/void_ptr_cast.hpp b/contrib/restricted/boost/boost/stacktrace/detail/void_ptr_cast.hpp index f956f4789fa..3247aab933f 100644 --- a/contrib/restricted/boost/boost/stacktrace/detail/void_ptr_cast.hpp +++ b/contrib/restricted/boost/boost/stacktrace/detail/void_ptr_cast.hpp @@ -1,5 +1,5 @@ // Copyright 2014 Renato Tegon Forti, Antony Polukhin. -// Copyright 2015-2017 Antony Polukhin. +// Copyright 2015-2021 Antony Polukhin. // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt diff --git a/contrib/restricted/boost/boost/stacktrace/frame.hpp b/contrib/restricted/boost/boost/stacktrace/frame.hpp index 8a1b426d7ac..6873dd0c02e 100644 --- a/contrib/restricted/boost/boost/stacktrace/frame.hpp +++ b/contrib/restricted/boost/boost/stacktrace/frame.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/contrib/restricted/boost/boost/stacktrace/safe_dump_to.hpp b/contrib/restricted/boost/boost/stacktrace/safe_dump_to.hpp index ded0036e845..f2301e6cb81 100644 --- a/contrib/restricted/boost/boost/stacktrace/safe_dump_to.hpp +++ b/contrib/restricted/boost/boost/stacktrace/safe_dump_to.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // 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. /// diff --git a/contrib/restricted/boost/boost/stacktrace/stacktrace.hpp b/contrib/restricted/boost/boost/stacktrace/stacktrace.hpp index c80679c8def..243b0551994 100644 --- a/contrib/restricted/boost/boost/stacktrace/stacktrace.hpp +++ b/contrib/restricted/boost/boost/stacktrace/stacktrace.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -13,6 +13,7 @@ #endif #include <boost/core/explicit_operator_bool.hpp> +#include <boost/core/no_exceptions_support.hpp> #include <boost/container_hash/hash_fwd.hpp> #include <iosfwd> @@ -69,13 +70,12 @@ class basic_stacktrace { return; } - try { + BOOST_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,18 +88,18 @@ 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; } buf.resize(buf.size() * 2); } while (buf.size() < buf.max_size()); // close to `true`, but suppresses `C4127: conditional expression is constant`. - } catch (...) { + } BOOST_CATCH (...) { // ignore exception } + BOOST_CATCH_END } /// @endcond @@ -319,6 +319,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 +394,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. diff --git a/contrib/restricted/boost/boost/stacktrace/stacktrace_fwd.hpp b/contrib/restricted/boost/boost/stacktrace/stacktrace_fwd.hpp index ec131564c0f..d54a6369468 100644 --- a/contrib/restricted/boost/boost/stacktrace/stacktrace_fwd.hpp +++ b/contrib/restricted/boost/boost/stacktrace/stacktrace_fwd.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2021. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at |