以下程序在 Visual Studio 2013 (MSVC++ 12.0) 中不可调试:
#include "stdafx.h"
#include <thread>
#include <stdexcept>
int main()
{
std::thread t([]() {
throw std::logic_error("WHAAT");
});
t.join();
return 0;
}
调试崩溃时(在调试模式下),调用堆栈完全没用:
> msvcr120d.dll!_NMSG_WRITE(int rterrnum) Line 226 C
msvcr120d.dll!abort() Line 62 C
msvcr120d.dll!terminate() Line 97 C++
msvcp120d.dll!_Call_func(void * _Data) Line 39 C++
msvcr120d.dll!_callthreadstartex() Line 376 C
msvcr120d.dll!_threadstartex(void * ptd) Line 359 C
kernel32.dll!@BaseThreadInitThunk@12() Unknown
ntdll.dll!__RtlUserThreadStart() Unknown
ntdll.dll!__RtlUserThreadStart@8() Unknown
并行调用堆栈窗口也不会提示程序崩溃的位置
奇怪的是,如果你用MSVC++ 14.1编译同样的,崩溃的原因是清楚地报告的:
ucrtbased.dll!issue_debug_notification(const wchar_t * const message) Line 28 C++
ucrtbased.dll!__acrt_report_runtime_error(const wchar_t * message) Line 154 C++
ucrtbased.dll!abort() Line 51 C++
ucrtbased.dll!terminate() Line 59 C++
vcruntime140d.dll!FindHandler(EHExceptionRecord * pExcept, EHRegistrationNode * pRN, _CONTEXT * pContext, void * pDC, const _s_FuncInfo * pFuncInfo, unsigned char recursive, int CatchDepth, EHRegistrationNode * pMarkerRN) Line 627 C++
vcruntime140d.dll!__InternalCxxFrameHandler(EHExceptionRecord * pExcept, EHRegistrationNode * pRN, _CONTEXT * pContext, void * pDC, const _s_FuncInfo * pFuncInfo, int CatchDepth, EHRegistrationNode * pMarkerRN, unsigned char recursive) Line 347 C++
vcruntime140d.dll!__CxxFrameHandler(EHExceptionRecord * pExcept, EHRegistrationNode * pRN, void * pContext, void * pDC) Line 219 C++
ntdll.dll!ExecuteHandler2@20() Unknown
ntdll.dll!ExecuteHandler@20() Unknown
ntdll.dll!_KiUserExceptionDispatcher@8() Unknown
KernelBase.dll!_RaiseException@16() Unknown
vcruntime140d.dll!_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 136 C++
> Sandbox2017.exe!main::__l2::<lambda>() Line 13 C++
Sandbox2017.exe!std::_Invoker_functor::_Call<void <lambda>(void) >(main::__l2::void <lambda>(void) && _Obj) C++
Sandbox2017.exe!std::invoke<void <lambda>(void) >(main::__l2::void <lambda>(void) && _Obj) C++
Sandbox2017.exe!std::_LaunchPad<std::unique_ptr<std::tuple<void <lambda>(void) >,std::default_delete<std::tuple<void <lambda>(void) > > > >::_Execute<0>(std::tuple<void <lambda>(void) > & _Tup, std::integer_sequence<unsigned int,0> __formal) Line 240 C++
Sandbox2017.exe!std::_LaunchPad<std::unique_ptr<std::tuple<void <lambda>(void) >,std::default_delete<std::tuple<void <lambda>(void) > > > >::_Run(std::_LaunchPad<std::unique_ptr<std::tuple<void <lambda>(void) >,std::default_delete<std::tuple<void <lambda>(void) > > > > * _Ln) Line 247 C++
Sandbox2017.exe!std::_LaunchPad<std::unique_ptr<std::tuple<void <lambda>(void) >,std::default_delete<std::tuple<void <lambda>(void) > > > >::_Go() Line 232 C++
Sandbox2017.exe!std::_Pad::_Call_func(void * _Data) Line 210 C++
ucrtbased.dll!invoke_thread_procedure(unsigned int(__stdcall*)(void *) procedure, void * const context) Line 92 C++
ucrtbased.dll!thread_start<unsigned int (__stdcall*)(void *)>(void * const parameter) Line 115 C++
kernel32.dll!@BaseThreadInitThunk@12() Unknown
ntdll.dll!__RtlUserThreadStart() Unknown
ntdll.dll!__RtlUserThreadStart@8() Unknown
我可以配置什么来使代码在 VS2013 中可调试吗?或者它是一个编译器错误?