Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion include/exception
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,45 @@ template <class E> void rethrow_if_nested(const E& e);
#pragma GCC system_header
#endif

#ifdef STD_EXCEPTION_HAS_STACK_TRACE
extern "C" int unw_backtrace(void **, int);
#endif

namespace std // purposefully not using versioning namespace
{

#if !defined(_LIBCPP_ABI_VCRUNTIME)
class _LIBCPP_EXCEPTION_ABI exception
{
public:
_LIBCPP_INLINE_VISIBILITY exception() _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY exception() _NOEXCEPT
{
#ifdef STD_EXCEPTION_HAS_STACK_TRACE
capture();
#endif
}
virtual ~exception() _NOEXCEPT;
virtual const char* what() const _NOEXCEPT;
#ifdef STD_EXCEPTION_HAS_STACK_TRACE
/// This is ClickHouse patch to libc++. It breaks ABI, so you cannot link your code with any C++ library
/// that has any std::exception-related symbols exported and was built without this patch.
void ** const get_stack_trace_frames() const _NOEXCEPT { return const_cast<void**>(frames); }
int get_stack_trace_size() const _NOEXCEPT { return size; }
void set_stack_trace(void ** frames_, int size_) _NOEXCEPT
{
size = size_;
for (int i = 0; i < size; ++i)
frames[i] = frames_[i];
}
private:
static constexpr int capacity = 32;
void * frames[capacity];
int size = 0;
void capture() _NOEXCEPT
{
size = unw_backtrace(frames, capacity);
}
#endif
};

class _LIBCPP_EXCEPTION_ABI bad_exception
Expand Down