@@ -54,22 +54,30 @@ namespace detail {
5454 }
5555 }
5656
57- #ifdef CPPTRACE_UNWIND_WITH_DBGHELP
57+ #if defined(_MSC_VER) && defined( CPPTRACE_UNWIND_WITH_DBGHELP)
5858 CPPTRACE_FORCE_NO_INLINE void collect_current_trace (std::size_t skip, EXCEPTION_POINTERS* exception_ptrs) {
59- #if defined(_M_IX86) || defined(__i386__)
60- // skip one frame, first is CxxThrowException
61- (void )skip;
62- auto trace = raw_trace{detail::capture_frames (1 , SIZE_MAX, exception_ptrs)};
63- #else
64- (void )exception_ptrs;
65- auto trace = raw_trace{detail::capture_frames (skip + 1 , SIZE_MAX)};
66- #endif
67- save_current_trace (std::move (trace));
59+ try {
60+ #if defined(_M_IX86) || defined(__i386__)
61+ // skip one frame, first is CxxThrowException
62+ (void )skip;
63+ auto trace = raw_trace{detail::capture_frames (1 , SIZE_MAX, exception_ptrs)};
64+ #else
65+ (void )exception_ptrs;
66+ auto trace = raw_trace{detail::capture_frames (skip + 1 , SIZE_MAX)};
67+ #endif
68+ save_current_trace (std::move (trace));
69+ } catch (...) {
70+ detail::log_and_maybe_propagate_exception (std::current_exception ());
71+ }
6872 }
6973 #else
7074 CPPTRACE_FORCE_NO_INLINE void collect_current_trace (std::size_t skip) {
71- auto trace = raw_trace{detail::capture_frames (skip + 1 , SIZE_MAX)};
72- save_current_trace (std::move (trace));
75+ try {
76+ auto trace = raw_trace{detail::capture_frames (skip + 1 , SIZE_MAX)};
77+ save_current_trace (std::move (trace));
78+ } catch (...) {
79+ detail::log_and_maybe_propagate_exception (std::current_exception ());
80+ }
7381 }
7482 #endif
7583
@@ -85,7 +93,7 @@ namespace detail {
8593 // - https://github.com/ecatmur/stacktrace-from-exception/blob/main/stacktrace-from-exception.cpp
8694 // - https://github.com/catboost/catboost/blob/master/contrib/libs/cxxsupp/libcxx/src/support/runtime/exception_pointer_msvc.ipp
8795 // - https://www.geoffchappell.com/studies/msvc/language/predefined/index.htm
88- #if defined _WIN64
96+ #ifdef _WIN64
8997 #pragma pack(push, 4)
9098 struct CatchableType {
9199 std::uint32_t properties;
@@ -102,8 +110,18 @@ namespace detail {
102110 std::int32_t pForwardCompat;
103111 std::int32_t pCatchableTypeArray;
104112 };
113+ #pragma warning(disable:4200)
114+ #pragma clang diagnostic push
115+ #pragma clang diagnostic ignored "-Wc99-extensions"
116+ struct CatchableTypeArray {
117+ uint32_t nCatchableTypes;
118+ int32_t arrayOfCatchableTypes[];
119+ };
120+ #pragma clang diagnostic pop
121+ #pragma warning (pop)
105122 #pragma pack(pop)
106123 #else
124+ using CatchableTypeArray = ::_CatchableTypeArray;
107125 using CatchableType = ::_CatchableType;
108126 using ThrowInfo = ::_ThrowInfo;
109127 #endif
@@ -115,11 +133,11 @@ namespace detail {
115133
116134 class catchable_type_info {
117135 HMODULE module_pointer = nullptr ;
118- const _CatchableTypeArray * catchable_types = nullptr ;
136+ const CatchableTypeArray * catchable_types = nullptr ;
119137 public:
120138 catchable_type_info (const HMODULE module_pointer, catchable_type_array_t catchable_type_array)
121139 : module_pointer(module_pointer) {
122- catchable_types = rtti_rva<const _CatchableTypeArray *>(catchable_type_array);
140+ catchable_types = rtti_rva<const CatchableTypeArray *>(catchable_type_array);
123141 }
124142
125143 class iterator {
0 commit comments