boostorg / stacktrace

C++ library for storing and printing backtraces.
https://boost.org/libs/stacktrace
422 stars 69 forks source link

AV in debugging_symbols::get_source_file_line_impl during app finalization #136

Closed zlojvavan closed 1 month ago

zlojvavan commented 1 year ago

boost 1.81 from vcpkg on windows

"Copy Details" button in "Exception Thrown" window in VS 2022 as usually cannot open clipboard so please bear with me for bringing screenshot

image

tried to output stacktrace to stream during late destructor (apparently too late to idebug_) here's meaningful excerpt from the callstack from IDE

throw_exception_spec.exe!boost::stacktrace::detail::debugging_symbols::get_source_file_line_impl(const void addr=0x000000013f6dd1db) Line 262 C++ throw_exception_spec.exe!boost::stacktrace::detail::debugging_symbols::to_string_impl(const void addr=0x000000013f6dd1db, std::string & res={...}) Line 314 C++ throw_exception_spec.exe!boost::stacktrace::detail::to_string(const boost::stacktrace::frame frames=0x0000000005cd5eb8, unsigned int64 size=31) Line 343 C++ .... throw_exception_spec.exe!_execute_onexit_table::l2::() Line 206 C++ throw_exception_spec.exe!crt_seh_guarded_call::operator()<void (void),int (void) &,void (void)>(acrt_lock_and_call::l2::void (void) && setup=void (void){...}, _execute_onexit_table::l2::int (void) & action=int (void){...}, acrt_lock_and_call::l2::void (void) && cleanup=void (void){...}) Line 204 C++ throw_exception_spec.exe!acrt_lock_and_call<int (void)>(const __acrt_lock_id lock_id=acrt_exit_lock, _execute_onexit_table::__l2::int (void) && action=int (void){...}) Line 974 C++ throw_exception_spec.exe!_execute_onexit_table(_onexit_table_t table=0x000000013fd11500) Line 231 C++ throw_exception_spec.exe!common_exit::l2::() Line 227 C++ throw_exception_spec.exe!crt_seh_guarded_call::operator()<void (void),void (void) &,void (void)>(acrt_lock_and_call::__l2::void (void) && setup=void (void){...}, common_exit::l2::void (void) & action=void (void){...}, acrt_lock_and_call::l2::void (void) && cleanup=void (void){...}) Line 224 C++ throw_exception_spec.exe!acrt_lock_and_call<void (void)>(const acrt_lock_id lock_id=acrt_exit_lock, common_exit::__l2::void (void) && action=void (void){...}) Line 974 C++ throw_exception_spec.exe!common_exit(const int return_code=0, const _crt_exit_cleanup_mode cleanup_mode=_crt_exit_full_cleanup, const _crt_exit_return_mode return_mode=_crt_exit_terminate_process) Line 259 C++ throw_exception_spec.exe!exit(int return_code=0) Line 294 C++ throw_exception_spec.exe!scrt_common_main_seh() Line 297 C++ throw_exception_spec.exe!scrt_common_main() Line 331 C++ throw_exception_spec.exe!mainCRTStartup(void * formal=0x000007fffffd4000) Line 17 C++ kernel32.dll!BaseThreadInitThunk() Unknown ntdll.dll!RtlUserThreadStart() Unknown

apolukhin commented 6 months ago

@zlojvavan there's some workaround in https://github.com/boostorg/stacktrace/issues/148. The issues seem to be about the same OS limitation

Does the workaround help?

zlojvavan commented 6 months ago

@apolukhin not sure what is workaround there. I suppose it's just the order of static init/finit and there's not much end user can do cleanly if stacktrace lib internals finalized before his own code without author's intervening ;) sometimes I am forced to do such dirty tricks by replacing some static class instances with dynamically created ones and introducing memleak but it's better than crash during finit in my book

apolukhin commented 2 months ago

Could you provide a minimal reproducer?

Also note that implementation of the library changed in latest release. Does the issue still happen on new version of the library?

apolukhin commented 1 month ago

Updated the library in 1.85 to use the same aproach as the C++ standard library implementation. If the crash remains - it's a platform limitation