Hi, as a developer of Codeblocks(
www.codeblocks.org), I try to migrate my wxWidgets library from 2.8.12 to 3.0.2.
I can build and wxWidgets 3.0.2 and Codeblocks(which link to wx library) successfully, but I get a crash if I try to close C::B or sometimes disable or enable some core plugins.
The crash happens in the condition that:
Condition A:
1, wxWidgets 3.0.2 is build as release mode(mingw32-make.exe ...BUILD=release)
2, OS: windows XP
result: C::B random crash!
Condition B:
1, wxWidgets 3.0.2 is build as release mode(mingw32-make.exe ...BUILD=release)
2, OS: windows 7 32bit or 64 bit
result: C::B no crash.
Condition C:
1, build wxWidgets 3.0.2 in debug mode (mingw32-make.exe ...BUILD=debug)
2, OS: windows XP
result: C::B no crash.
This is quite wired, since only the release version of wx library on winXP system cause the crash.
To hunt the crash bug, I even build a release version of wx which has "-g" option:
mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1 USE_OPENGL=1 VENDOR=cb CXXFLAGS=" -g -fno-keep-inline-dllexport -Wno-unused-local-typedefs -Wno-deprecated-declarations" >log-release-g.txt 2>&1
Thus, I can get a detailed crash call stack in the GDB, the call stack are:
#0 0x6474c5e5 in wxClassInfo::IsKindOf (info=<optimized out>, this=<optimized out>) at D:\wx3\include\wx\rtti.h:91
#1 wxCheckDynamicCast (classInfo=<optimized out>, obj=<optimized out>) at D:\wx3\include\wx\object.h:450
#2 wxWindow::FindItemByHWND (this=<optimized out>, hWnd=hWnd@entry=0x208a4, controlOnly=controlOnly@entry=true) at D:\wx3\src\msw\window.cpp:408
#3 0x6474dc28 in wxWindow::HandleCtlColor (this=<optimized out>, brush=brush@entry=0x22cff0, hDC=hDC@entry=0xa50116c3, hWnd=hWnd@entry=0x208a4) at D:\wx3\src\msw\window.cpp:4537
#4 0x6475911b in wxWindow::MSWHandleMessage (this=0x5a0a5e0, result=0x22d100, message=307, wParam=2768312003, lParam=133284) at D:\wx3\src\msw\window.cpp:3286
#5 0x647497a0 in wxWindow::MSWWindowProc (this=this@entry=0x5a0a5e0, message=message@entry=307, wParam=wParam@entry=
2768312003, lParam=lParam@entry=133284) at D:\wx3\src\msw\window.cpp:3645
#6 0x64741f96 in wxTopLevelWindowMSW::MSWWindowProc (this=this@entry=0x5a0a5e0, message=message@entry=307, wParam=wParam@entry=
2768312003, lParam=lParam@entry=133284) at D:\wx3\src\msw\toplevel.cpp:467
#7 0x647a8046 in wxFrame::MSWWindowProc (this=0x5a0a5e0, message=307, wParam=
2768312003, lParam=133284) at D:\wx3\src\msw\frame.cpp:887
#8 0x64751223 in wxWndProc(HWND__*, unsigned int, unsigned int, long)@16 (hWnd=0x20678, message=307, wParam=
2768312003, lParam=133284) at D:\wx3\src\msw\window.cpp:2711
#9 0x7e418734 in USER32!GetDC () from C:\WINDOWS\system32\user32.dll
#10 0x00020678 in ?? ()
#11 0x7e418816 in USER32!GetDC () from C:\WINDOWS\system32\user32.dll
#12 0x647511b0 in wxWindow::SubclassWin(HWND__*) () at D:\wx3\include\wx\object.h:361
#13 0x7e42927b in USER32!GetParent () from C:\WINDOWS\system32\user32.dll
#14 0x00000000 in ?? ()
Which point to the line:
// Climb upwards through inheritance hierarchy.
// Dual inheritance is catered for.
bool IsKindOf(const wxClassInfo *info) const
{
return info != 0 &&
( info == this ||
( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) ); //**********HERE********
}
Since the release of wx is build with "-O2" option, I can't figure out what cause the issue.
It looks like some function are in-lined.
Here is the disas of the crash(the result of the command "disas /rs" under GDB),
0x6474c5e5 is the crash program address.
...
90 ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
0x6474c5b0 <+544>: c7 04 24 00 60 46 65 mov DWORD PTR [esp],0x65466000
0x6474c5b7 <+551>: e8 74 51 91 00 call 0x65061730 <wxClassInfo::IsKindOf(wxClassInfo const*) const>
0x6474c5bc <+556>: 83 ec 04 sub esp,0x4
0x6474c5bf <+559>: 84 c0 test al,al
0x6474c5c1 <+561>: 0f 85 e9 fd ff ff jne 0x6474c3b0 <wxWindow::FindItemByHWND(HWND__*, bool) const+32>
91 ( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) );
0x6474c5c7 <+567>: 8b 4b 10 mov ecx,DWORD PTR [ebx+0x10]
90 ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
0x6474c5ca <+570>: 85 c9 test ecx,ecx
0x6474c5cc <+572>: 74 17 je 0x6474c5e5 <wxWindow::FindItemByHWND(HWND__*, bool) const+597>
91 ( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) );
0x6474c5ce <+574>: c7 04 24 00 60 46 65 mov DWORD PTR [esp],0x65466000
0x6474c5d5 <+581>: e8 56 51 91 00 call 0x65061730 <wxClassInfo::IsKindOf(wxClassInfo const*) const>
0x6474c5da <+586>: 83 ec 04 sub esp,0x4
0x6474c5dd <+589>: 84 c0 test al,al
0x6474c5df <+591>: 0f 85 cb fd ff ff jne 0x6474c3b0 <wxWindow::FindItemByHWND(HWND__*, bool) const+32>
=> 0x6474c5e5 <+597>: 8b 52 10 mov edx,DWORD PTR [edx+0x10]
90 ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
0x6474c5e8 <+600>: 85 d2 test edx,edx
0x6474c5ea <+602>: 0f 84 e7 fd ff ff je 0x6474c3d7 <wxWindow::FindItemByHWND(HWND__*, bool) const+71>
88 return info != 0 &&
0x6474c5f0 <+608>: 81 fa 00 60 46 65 cmp edx,0x65466000
0x6474c5f6 <+614>: 0f 84 b4 fd ff ff je 0x6474c3b0 <wxWindow::FindItemByHWND(HWND__*, bool) const+32>
90 ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
0x6474c5fc <+620>: 8b 5a 0c mov ebx,DWORD PTR [edx+0xc]
89 ( info == this ||
0x6474c5ff <+623>: 85 db test ebx,ebx
0x6474c601 <+625>: 0f 84 aa 00 00 00 je 0x6474c6b1 <wxWindow::FindItemByHWND(HWND__*, bool) const+801>
88 return info != 0 &&
0x6474c607 <+631>: 81 fb 00 60 46 65 cmp ebx,0x65466000
0x6474c60d <+637>: 0f 84 9d fd ff ff je 0x6474c3b0 <wxWindow::FindItemByHWND(HWND__*, bool) const+32>
90 ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
0x6474c613 <+643>: 8b 73 0c mov esi,DWORD PTR [ebx+0xc]
...
Here, the edx is 0, so it try to access a memory address of 0x00000010.
Does this cause by a GCC bug, if this is true, why the same app(which crash on winXP) works fine under Win7 system?
Does this cause by a wxWidgets bug only related to winXP, if so, why the debug version of wx library don't cause the crash on winXP?
Any one can give me a hint? Thanks.
The original discussion are here in Codeblocks' forum:
All -
http://forums.codeblocks.org/index.php/topic,20607.0/all.html
Asmwarrior