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 {
58
58
CPPTRACE_FORCE_NO_INLINE void collect_current_trace (std::size_t skip, EXCEPTION_POINTERS* exception_ptrs) {
59
59
try {
60
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)};
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)};
64
63
#else
65
64
(void )exception_ptrs;
66
65
auto trace = raw_trace{detail::capture_frames (skip + 1 , SIZE_MAX)};
@@ -615,9 +614,9 @@ CPPTRACE_BEGIN_NAMESPACE
615
614
int maybe_collect_trace (EXCEPTION_POINTERS* exception_ptrs, int filter_result) {
616
615
if (filter_result == EXCEPTION_EXECUTE_HANDLER) {
617
616
#ifdef CPPTRACE_UNWIND_WITH_DBGHELP
618
- collect_current_trace (2 , exception_ptrs);
617
+ collect_current_trace (1 , exception_ptrs);
619
618
#else
620
- collect_current_trace (2 );
619
+ collect_current_trace (1 );
621
620
(void )exception_ptrs;
622
621
#endif
623
622
}
Original file line number Diff line number Diff line change @@ -29,7 +29,6 @@ namespace detail {
29
29
std::size_t max_depth,
30
30
EXCEPTION_POINTERS* exception_pointers
31
31
) {
32
- skip++;
33
32
// https://jpassing.com/2008/03/12/walking-the-stack-of-the-current-thread/
34
33
35
34
// Get current thread context
@@ -40,6 +39,7 @@ namespace detail {
40
39
if (exception_pointers) {
41
40
context = *exception_pointers->ContextRecord ;
42
41
} else {
42
+ skip++; // we're unwinding from the capture_frames frame, skip it
43
43
#if defined(_M_IX86) || defined(__i386__)
44
44
context.ContextFlags = CONTEXT_CONTROL;
45
45
#if IS_MSVC
Original file line number Diff line number Diff line change @@ -211,15 +211,14 @@ TEST(FromCurrent, SEHBasic) {
211
211
does_enter_catch = true ;
212
212
EXPECT_FALSE (cpptrace::current_exception_was_rethrown ());
213
213
const auto & trace = cpptrace::from_current_exception ();
214
- ASSERT_GE (trace.frames .size (), 4 );
215
214
auto it = std::find_if (
216
215
trace.frames .begin (),
217
216
trace.frames .end (),
218
217
[](const cpptrace::stacktrace_frame& frame) {
219
218
return frame.symbol .find (" my_div_function" ) != std::string::npos;
220
219
}
221
220
);
222
- EXPECT_NE (it, trace.frames .end ()) << trace;
221
+ ASSERT_NE (it, trace.frames .end ()) << trace;
223
222
size_t i = static_cast <size_t >(it - trace.frames .begin ());
224
223
EXPECT_FILE (trace.frames [i].filename , " from_current.cpp" );
225
224
} ();
You can’t perform that action at this time.
0 commit comments