OpenCover / opencover

A code coverage tool for .NET 2 and above (WINDOWS OS only), support for 32 and 64 processes with both branch and sequence points
https://blog.many-monkeys.com
Other
1.31k stars 248 forks source link

Assertion in OpenCover.Profiler.dll debug_heap #376

Closed trivalik closed 8 years ago

trivalik commented 8 years ago

Today I got this assertion on our system. I followed this time the windows with the taskmgr and Profile dll is loaded by Nunit agent.

Now I found the complete stacktrace in a the create dump file.

    ntdll.dll!_ZwWaitForSingleObject@12()  Unknown
    ntdll.dll!_RtlpWaitOnCriticalSection@8()   Unknown
    ntdll.dll!_RtlEnterCriticalSection@4() Unknown
    OpenCover.Profiler.dll!__acrt_lock(__acrt_lock_id _Lock) Line 55    C++
    OpenCover.Profiler.dll!heap_alloc_dbg_internal(const unsigned int size, const int block_use, const char * const file_name, const int line_number) Line 309  C++
    OpenCover.Profiler.dll!heap_alloc_dbg(const unsigned int size, const int block_use, const char * const file_name, const int line_number) Line 450   C++
    OpenCover.Profiler.dll!_malloc_dbg(unsigned int size, int block_use, const char * file_name, int line_number) Line 491  C++
    OpenCover.Profiler.dll!malloc(unsigned int size) Line 18    C++
>   OpenCover.Profiler.dll!operator new(unsigned int size) Line 19  C++
    OpenCover.Profiler.dll!std::_Allocate<std::_Container_proxy>(unsigned int _Count, std::_Container_proxy * __formal, bool _Try_aligned_allocation) Line 89   C++
    OpenCover.Profiler.dll!std::allocator<std::_Container_proxy>::allocate(unsigned int _Count) Line 645    C++
    OpenCover.Profiler.dll!std::_Wrap_alloc<std::allocator<std::_Container_proxy> >::allocate(unsigned int _Count) Line 901 C++
    OpenCover.Profiler.dll!std::_String_alloc<std::_String_base_types<wchar_t,std::allocator<wchar_t> > >::_Alloc_proxy() Line 637  C++
    OpenCover.Profiler.dll!std::_String_alloc<std::_String_base_types<wchar_t,std::allocator<wchar_t> > >::_String_alloc<std::_String_base_types<wchar_t,std::allocator<wchar_t> > >(const std::allocator<wchar_t> & _Al) Line 600  C++
    OpenCover.Profiler.dll!std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >() Line 783   C++
    OpenCover.Profiler.dll!CCodeCoverage::JITCompilationStarted(unsigned int functionId, int fIsSafeToBlock) Line 257   C++
    ntdll.dll!ExecuteHandler2@20() Unknown
    ntdll.dll!ExecuteHandler@20()  Unknown
    ntdll.dll!_RtlDispatchException@8()    Unknown
    ntdll.dll!_KiUserExceptionDispatcher@8()   Unknown
    OpenCover.Profiler.dll!ProfilerCommunication::AddVisitPointToThreadBuffer(unsigned long uniqueId, MSG_IdType msgType) Line 243  C++
    OpenCover.Profiler.dll!CCodeCoverage::AddVisitPoint(unsigned long uniqueId) Line 205    C++
    OpenCover.Profiler.dll!InstrumentPointVisit(unsigned long seq) Line 186 C++
    [Managed to Native Transition]  
    Tests.dll!Tests.Tests.TestUtil.CallHiddenMethod(string assembly, string type, string methodName, object instance)   Unknown

FYI, CallHiddenMethod, uses MethodInfo object to call any hidden method. Maybe is this also the cause for sometimes getting an AccessViolationException! So would think here is something strange.

assert_debugheap

Edit: was wrong callstack

    user32.dll!_NtUserWaitMessage@0()  Unknown
    user32.dll!_DialogBox2@16()    Unknown
    user32.dll!_InternalDialogBox@24() Unknown
    user32.dll!_SoftModalMessageBox@4()    Unknown
    user32.dll!_MessageBoxWorker@4()   Unknown
    user32.dll!_MessageBoxTimeoutW@24()    Unknown
    user32.dll!_MessageBoxExW@20() Unknown
    user32.dll!_MessageBoxW@16()   Unknown
>   OpenCover.Profiler.dll!__acrt_MessageBoxW(HWND__ * hwnd, const wchar_t * text, const wchar_t * caption, unsigned int type) Line 713 C++
    OpenCover.Profiler.dll!__crt_char_traits<wchar_t>::message_box<HWND__ *,wchar_t const * const &,wchar_t const * const &,unsigned int const &>(HWND__ * && <args_0>, const wchar_t * const & <args_1>, const wchar_t * const & <args_2>, const unsigned int & <args_3>) Line 121 C++
    OpenCover.Profiler.dll!common_show_message_box<wchar_t>(const wchar_t * const text, const wchar_t * const caption, const unsigned int type) Line 116    C++
    OpenCover.Profiler.dll!__acrt_show_wide_message_box(const wchar_t * text, const wchar_t * caption, unsigned int type) Line 134  C++
    OpenCover.Profiler.dll!common_message_window<wchar_t>(const int report_type, void * const return_address, const wchar_t * const file_name, const wchar_t * const line_number, const wchar_t * const module_name, const wchar_t * const user_message) Line 404   C++
    OpenCover.Profiler.dll!__acrt_MessageWindowW(const int report_type, void * const return_address, const wchar_t * const file_name, const wchar_t * const line_number, const wchar_t * const module_name, const wchar_t * const user_message) Line 451    C++
    OpenCover.Profiler.dll!_VCrtDbgReportW(int nRptType, void * returnAddress, const wchar_t * szFile, int nLine, const wchar_t * szModule, const wchar_t * szFormat, char * arglist) Line 642  C++
    OpenCover.Profiler.dll!_CrtDbgReportW(int report_type, const wchar_t * file_name, int line_number, const wchar_t * module_name, const wchar_t * format, ...) Line 273   C++
    OpenCover.Profiler.dll!free_dbg_nolock(void * const block, const int block_use) Line 888    C++
    OpenCover.Profiler.dll!_free_dbg(void * block, int block_use) Line 1011 C++
    OpenCover.Profiler.dll!operator delete(void * block) Line 17    C++
    OpenCover.Profiler.dll!std::_Deallocate<std::_List_node<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *>,void *> >(std::_List_node<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *>,void *> * _Ptr, unsigned int _Count) Line 138   C++
    OpenCover.Profiler.dll!std::allocator<std::_List_node<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *>,void *> >::deallocate(std::_List_node<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *>,void *> * _Ptr, unsigned int _Count) Line 640 C++
    OpenCover.Profiler.dll!std::_Wrap_alloc<std::allocator<std::_List_node<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *>,void *> > >::deallocate(std::_List_node<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *>,void *> * _Ptr, unsigned int _Count) Line 912  C++
    OpenCover.Profiler.dll!std::_List_buy<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *>,std::allocator<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> > >::_Freenode(std::_List_node<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *>,void *> * _Pnode) Line 853 C++
    OpenCover.Profiler.dll!std::list<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *>,std::allocator<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> > >::erase(std::_List_const_iterator<std::_List_val<std::_List_simple_types<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> > > > _Where) Line 1465    C++
    OpenCover.Profiler.dll!std::_Hash<std::_Umap_traits<unsigned long,_MSG_SendVisitPoints_Request *,std::_Uhash_compare<unsigned long,std::hash<unsigned long>,std::equal_to<unsigned long> >,std::allocator<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> >,0> >::_Destroy_if_not_nil(std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> > > > _Plist) Line 698 C++
    OpenCover.Profiler.dll!std::_Hash<std::_Umap_traits<unsigned long,_MSG_SendVisitPoints_Request *,std::_Uhash_compare<unsigned long,std::hash<unsigned long>,std::equal_to<unsigned long> >,std::allocator<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> >,0> >::_Insert<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> &,std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> > > > >(std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> & _Val, std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> > > > _Pnode) Line 730 C++
    OpenCover.Profiler.dll!std::_Hash<std::_Umap_traits<unsigned long,_MSG_SendVisitPoints_Request *,std::_Uhash_compare<unsigned long,std::hash<unsigned long>,std::equal_to<unsigned long> >,std::allocator<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> >,0> >::_Reinsert() Line 890   C++
    OpenCover.Profiler.dll!std::_Hash<std::_Umap_traits<unsigned long,_MSG_SendVisitPoints_Request *,std::_Uhash_compare<unsigned long,std::hash<unsigned long>,std::equal_to<unsigned long> >,std::allocator<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> >,0> >::_Check_size() Line 880 C++
    OpenCover.Profiler.dll!std::_Hash<std::_Umap_traits<unsigned long,_MSG_SendVisitPoints_Request *,std::_Uhash_compare<unsigned long,std::hash<unsigned long>,std::equal_to<unsigned long> >,std::allocator<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> >,0> >::_Insert<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> &,std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> > > > >(std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> & _Val, std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> > > > _Pnode) Line 747 C++
    OpenCover.Profiler.dll!std::_Hash<std::_Umap_traits<unsigned long,_MSG_SendVisitPoints_Request *,std::_Uhash_compare<unsigned long,std::hash<unsigned long>,std::equal_to<unsigned long> >,std::allocator<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> >,0> >::emplace<std::piecewise_construct_t const &,std::tuple<unsigned long const &>,std::tuple<> >(const std::piecewise_construct_t & <_Val_0>, std::tuple<unsigned long const &> && <_Val_1>, std::tuple<> && <_Val_2>) Line 271 C++
    OpenCover.Profiler.dll!std::unordered_map<unsigned long,_MSG_SendVisitPoints_Request *,std::hash<unsigned long>,std::equal_to<unsigned long>,std::allocator<std::pair<unsigned long const ,_MSG_SendVisitPoints_Request *> > >::operator[](const unsigned long & _Keyval) Line 419  C++
    OpenCover.Profiler.dll!ProfilerCommunication::AllocateVisitMap(unsigned long osThreadID) Line 203   C++
    OpenCover.Profiler.dll!ProfilerCommunication::ThreadCreated(unsigned int threadID, unsigned long osThreadID) Line 197   C++
    OpenCover.Profiler.dll!CCodeCoverage::ThreadAssignedToOSThread(unsigned int managedThreadId, unsigned long osThreadId) Line 42  C++
    kernel32.dll!@BaseThreadInitThunk@12() Unknown
    ntdll.dll!___RtlUserThreadStart@8()    Unknown
    ntdll.dll!__RtlUserThreadStart@8() Unknown

I can provide you also a debugview log, but there you see only many TheradCreate, ThreadAssignToOSThread and ThreadDestroy.

00070321    12421.90917969  [1156] OpenCover: (Profiler) ::JITCompilationStarted(742B1B8, ...) => 100663306, 9806FCC => D:\Tests\bin\x86\Release\Tests.dll
00070322    12421.90917969  [2984] Getting Sequence points for System.Void PagesBase_Tests.Tests.Unit_Tests.A_LogicTests::A_LogicTests_T()(100663306) 
00070323    12421.91113281  [2984] Getting Branch points for System.Void PagesBase_Tests.Tests.Unit_Tests.A_LogicTests::A_LogicTests_T()(100663306) 
00070324    12421.91113281  [1156] c:\users\trivalik\downloads\opencover-master\opencover-master\main\opencover.profiler\method.cpp(54) : atlTraceGeneral - FAT(254) => (596 + 12) : 3
00070325    12421.93750000  [1156] OpenCover: (Profiler) ::JITCompilationStarted(...) => Instrumenting...
00070326    12421.93945313  [1156] OpenCover: (Profiler) ::RegisterSafeCuckooMethod(9806FCC) => SafeVisited
00070327    12422.14648438  [1156] OpenCover: (Profiler) ::ThreadCreated(253023168)
00070328    12422.14648438  [1156] OpenCover: (Profiler) ::ThreadAssignedToOSThread(253023168, 3804)
00070329    12435.91992188  [1164] OpenCover: (Profiler) ::ThreadDestroyed(99719848)
00070330    12441.03222656  [1164] OpenCover: (Profiler) ::ThreadCreated(99716928)
00070331    12441.03320313  [1164] OpenCover: (Profiler) ::ThreadAssignedToOSThread(99716928, 1820)
00070332    12456.02832031  [1164] OpenCover: (Profiler) ::ThreadDestroyed(99718872)
00070333    12461.05859375  [1164] OpenCover: (Profiler) ::ThreadCreated(99727208)
00070334    12461.05859375  [1164] OpenCover: (Profiler) ::ThreadAssignedToOSThread(99727208, 9040)

here comes thousand of ThreadCreate, Destroy
MaceWindu commented 8 years ago

Second stack trace shows that it also the same issue as in #373 - broken map structure

trivalik commented 8 years ago

I applied only the following code from lanfeust69 and this fixes all problems:

MSG_SendVisitPoints_Request* ProfilerCommunication::GetVisitMapForOSThread(ULONG osThreadID){
    ATL::CComCritSecLock<ATL::CComAutoCriticalSection> lock(m_critThreads);
    return m_visitmap[osThreadID];
}
sawilde commented 8 years ago

@trivalik thanks for the update

sawilde commented 8 years ago

Can you try this release to see if it corrects your issue https://www.nuget.org/packages/OpenCover/4.6.247-rc https://github.com/OpenCover/opencover/releases/tag/4.6.247-rc

trivalik commented 8 years ago

I installed the version today.

trivalik commented 8 years ago

Since installation of prerelease 4.6.261 no problems anymore. Thanks.

sawilde commented 8 years ago

thanks for testing