File tree Expand file tree Collapse file tree 3 files changed +6
-8
lines changed Expand file tree Collapse file tree 3 files changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -58,9 +58,8 @@ namespace detail {
5858 CPPTRACE_FORCE_NO_INLINE void collect_current_trace (std::size_t skip, EXCEPTION_POINTERS* exception_ptrs) {
5959 try {
6060 #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)};
61+ (void )skip; // don't skip any frames, the context record is at the throw point
62+ auto trace = raw_trace{detail::capture_frames (0 , SIZE_MAX, exception_ptrs)};
6463 #else
6564 (void )exception_ptrs;
6665 auto trace = raw_trace{detail::capture_frames (skip + 1 , SIZE_MAX)};
@@ -615,9 +614,9 @@ CPPTRACE_BEGIN_NAMESPACE
615614 int maybe_collect_trace (EXCEPTION_POINTERS* exception_ptrs, int filter_result) {
616615 if (filter_result == EXCEPTION_EXECUTE_HANDLER) {
617616 #ifdef CPPTRACE_UNWIND_WITH_DBGHELP
618- collect_current_trace (2 , exception_ptrs);
617+ collect_current_trace (1 , exception_ptrs);
619618 #else
620- collect_current_trace (2 );
619+ collect_current_trace (1 );
621620 (void )exception_ptrs;
622621 #endif
623622 }
Original file line number Diff line number Diff line change @@ -29,7 +29,6 @@ namespace detail {
2929 std::size_t max_depth,
3030 EXCEPTION_POINTERS* exception_pointers
3131 ) {
32- skip++;
3332 // https://jpassing.com/2008/03/12/walking-the-stack-of-the-current-thread/
3433
3534 // Get current thread context
@@ -40,6 +39,7 @@ namespace detail {
4039 if (exception_pointers) {
4140 context = *exception_pointers->ContextRecord ;
4241 } else {
42+ skip++; // we're unwinding from the capture_frames frame, skip it
4343 #if defined(_M_IX86) || defined(__i386__)
4444 context.ContextFlags = CONTEXT_CONTROL;
4545 #if IS_MSVC
Original file line number Diff line number Diff line change @@ -211,15 +211,14 @@ TEST(FromCurrent, SEHBasic) {
211211 does_enter_catch = true ;
212212 EXPECT_FALSE (cpptrace::current_exception_was_rethrown ());
213213 const auto & trace = cpptrace::from_current_exception ();
214- ASSERT_GE (trace.frames .size (), 4 );
215214 auto it = std::find_if (
216215 trace.frames .begin (),
217216 trace.frames .end (),
218217 [](const cpptrace::stacktrace_frame& frame) {
219218 return frame.symbol .find (" my_div_function" ) != std::string::npos;
220219 }
221220 );
222- EXPECT_NE (it, trace.frames .end ()) << trace;
221+ ASSERT_NE (it, trace.frames .end ()) << trace;
223222 size_t i = static_cast <size_t >(it - trace.frames .begin ());
224223 EXPECT_FILE (trace.frames [i].filename , " from_current.cpp" );
225224 } ();
You can’t perform that action at this time.
0 commit comments