Debug C::B under C::B using gdb, then set a bp in the function: int CodeCompletion::CodeComplete() (around line 2061 of codecompletion.cpp), then run several steps (or step int some functions like MarkItemsByAI()), then continue running will cause the debugee C::B crash in the line
ed->GetControl()->AutoCompShow(pos - start, final);
I debugged some time, and find that the above line try to pop-up the autocompletion window. But when the debugee C::B stops at a bp which is before call the function AutoCompShow(), there will be a window switch. I mean, the debugee C::B will receive a KillFocus event.
What I see the crash backtrace is:
[debug]#0 0x61a08afa in wxSCIListBoxWin::GetLB (this=0x0) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\PlatWX.cpp:1043
[debug]#1 0x619eb809 in GETLB (win=0x0) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\PlatWX.cpp:1218
[debug]#2 0x618e2f70 in ListBoxImpl::Length (this=0x3dbf1d8) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\PlatWX.cpp:1414
[debug]#3 0x6198e9e8 in AutoComplete::Select (this=0x1c20fb0, word=0x3ea8d84 "ac") at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\scintilla\src\AutoComplete.cxx:148
[debug]#4 0x61978e76 in ScintillaBase::AutoCompleteMoveToCurrentWord (this=0x1c205c0) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\scintilla\src\ScintillaBase.cxx:300
[debug]#5 0x61978d14 in ScintillaBase::AutoCompleteStart (this=0x1c205c0, lenEntered=2, list=0x3ddd290 "accB?1\naccess(): int __cdecl?13\naccumulate?40\nacos(): double __cdecl?13\nacosf(): float __cdecl?13\nacosh(): double __cdecl?13\nacoshf(): float __cdecl?13\nacoshl(): long double __cdecl?13\nacosl(): long d"...) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\scintilla\src\ScintillaBase.cxx:277
[debug]#6 0x6197a491 in ScintillaBase::WndProc (this=0x1c205c0, iMessage=2100, wParam=2, lParam=64869008) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\scintilla\src\ScintillaBase.cxx:666
[debug]#7 0x618def3f in ScintillaWX::WndProc (this=0x1c205c0, iMessage=2100, wParam=2, lParam=64869008) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\ScintillaWX.cpp:883
[debug]#8 0x618d02b9 in wxScintilla::SendMsg (this=0x3d9ef40, msg=2100, wp=2, lp=64869008) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\wxscintilla.cpp:270
[debug]#9 0x618d21e3 in wxScintilla::AutoCompShow (this=0x3d9ef40, lenEntered=2, itemList="accB?1\naccess(): int __cdecl?13\naccumulate?40\nacos(): double __cdecl?13\nacosf(): float __cdecl?13\nacosh(): double __cdecl?13\nacoshf(): float __cdecl?13\nacoshl(): long double __cdecl?13\nacosl(): long d"...) at E:\code\cb\cleantrunk\src\sdk\wxscintilla\src\wxscintilla.cpp:1203
[debug]#10 0x65e8d7a7 in CodeCompletion::CodeComplete (this=0x39c6180) at E:\code\cb\cleantrunk\src\plugins\codecompletion\codecompletion.cpp:2240
[debug]#11 0x65e976b3 in CodeCompletion::DoCodeComplete (this=0x39c6180) at E:\code\cb\cleantrunk\src\plugins\codecompletion\codecompletion.cpp:4127
[debug]#12 0x65e910d5 in CodeCompletion::EditorEventHook (this=0x39c6180, editor=0x3c8f0a8, event=...) at E:\code\cb\cleantrunk\src\plugins\codecompletion\codecompletion.cpp:2947
[debug]#13 0x65f29c7d in EditorHooks::HookFunctor<CodeCompletion>::Call (this=0x3bf1540, editor=0x3c8f0a8, event=...) at E:\code\cb\cleantrunk\src\include\editor_hooks.h:49
[debug]#14 0x6189a021 in EditorHooks::CallHooks (editor=0x3c8f0a8, event=...) at E:\code\cb\cleantrunk\src\sdk\editor_hooks.cpp:69
[debug]#15 0x6183b03d in cbEditor::OnScintillaEvent (this=0x3c8f0a8, event=...) at E:\code\cb\cleantrunk\src\sdk\cbeditor.cpp:3280
[debug]#16 0x6183a335 in cbEditor::OnEditorCharAdded (this=0x3c8f0a8, event=...) at E:\code\cb\cleantrunk\src\sdk\cbeditor.cpp:3037
[debug]#17 0x00e7ff27 in wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () from E:\code\cb\cleantrunk\src\devel\wxmsw28u_gcc_custom.dll
It crash at the function:
inline wxSCIListBoxWin* GETLBW(WindowID win) {
return ((wxSCIListBoxWin*)win);
}
inline wxListView* GETLB(WindowID win) {
return GETLBW(win)->GetLB();
}
.....
int ListBoxImpl::Length()
{
return GETLB(wid)->GetItemCount();
}
But the "wid" is currently 0. I found the reason is, when a KillFocus is received, it will finally let the auto-completion canceled. So
void Window::Destroy()
{
if (wid) {
Show(false);
GETWIN(wid)->Destroy();
}
wid = 0;
}
will be called.
The interesting thing is: If you set two bps in the switch statement below(one for each case), you will see firstly it entered a SCI_AUTOCSHOW, and later a SCI_AUTOCCANCEL.
sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
switch (iMessage) {
case SCI_AUTOCSHOW:
listType = 0;
AutoCompleteStart(wParam, reinterpret_cast<const char *>(lParam));
break;
case SCI_AUTOCCANCEL:
ac.Cancel();
break;
My question is: how to solve this issue? Thanks.
(Another question is: how to build C::B which can link to a debug version of wxWidgets library, so that I can see/track the messages more clearly, currently, gdb's bt command always stop at [debug]#17 0x00e7ff27 in wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () from E:\code\cb\cleantrunk\src\devel\wxmsw28u_gcc_custom.dll)