Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement stacktrace from current exception for MSVC #159

Merged

Conversation

huangqinjin
Copy link
Contributor

@huangqinjin huangqinjin commented Mar 16, 2024

Original stacktrace from std::exception_ptr is not possible currently. std::current_exception() makes a copy of current exception object into returned std::exception_ptr. So the tracking of the original exception object and its stacktrace are lost.

Support for nested exceptions is not much meaningful IMO, it complicates the implementation (see the last commit). Without nested exceptions support, one can always get stacktrace from current exception immediately after entering catch block, but it loses the original stacktrace for rethrow_after_other_exception case.

The exception object is destroyed by __DestructExceptionObject exported from vcruntime.dll, there is no simple way to cleanup stored traces in time unless override __DestructExceptionObject.

@huangqinjin huangqinjin force-pushed the msvc-stacktrace-from-current-exception branch 5 times, most recently from 3039cdc to 036c9de Compare March 19, 2024 20:32
Copy link
Member

@apolukhin apolukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very impressive!

Added some comments and nitpicks

src/from_exception.cpp Outdated Show resolved Hide resolved
src/from_exception.cpp Outdated Show resolved Hide resolved
src/from_exception.cpp Outdated Show resolved Hide resolved
src/from_exception.cpp Outdated Show resolved Hide resolved
build/Jamfile.v2 Show resolved Hide resolved
test/test_from_exception.cpp Show resolved Hide resolved
src/from_exception.cpp Outdated Show resolved Hide resolved
src/from_exception.cpp Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Apr 12, 2024

Coverage Status

coverage: 86.308%. remained the same
when pulling f76e128 on huangqinjin:msvc-stacktrace-from-current-exception
into 351b03d on boostorg:develop.

std::current_exception() makes a copy of current exception object
into returned std::exception_ptr. So the tracking of the original
exception object and its stacktrace are lost.
@huangqinjin huangqinjin force-pushed the msvc-stacktrace-from-current-exception branch from 036c9de to f76e128 Compare April 13, 2024 18:28
@apolukhin apolukhin merged commit d1b7a61 into boostorg:develop Apr 16, 2024
8 checks passed
@apolukhin
Copy link
Member

Many thanks for the great PR!

@huangqinjin huangqinjin deleted the msvc-stacktrace-from-current-exception branch April 16, 2024 11:25
@ingo-loehken
Copy link

it is possible to track nested exceptions and to map exception_ptr to their callsite, but it can (imho) only be done via IAT Hooking functions in each affected library. Alternatively one may also apply EAT Hooking, if it is guaranteed that the shared libs are not loaded dynamically into foreign processes ... i.e plugin libs into excel or inproc ole/com or other stuff.

Besides that, the perf and abilities of boost::stacktrace are quite impressive. The dep to COM Init should be removed for Windows, if resolving symbols. The implementation of seems to bypass the CoInit and therefore avoid apartment model collisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants