Although this bug is already reported on the BerliOs-ProjectPage, I decided to start a new thread because I've found a way to reproduce this crash and to show that this bug is still existant in current svn-versions.
The problem: CodeBlocks crashes quite often when doing copy & paste. I don't know if it depends on the text which should be pasted, but this is the way I can reproduce the crash:
1. start C::B and open or create an empty cpp-file.
2. paste the following code "as it is" into the empty cpp-file
#include <gtkmm.h>
#include <gtkmm/button.h>
#include <gtkmm/image.h>
#include <libglademm-2.4/libglademm/xml.h>
#include <iostream>
3. mark the complete code in the cpp-file.
4. press copy and then paste and C::B should crash.
The crash happens very often and not only when pasting this special piece of code, but this special case was the only one I found to reproduce it.
I'm using Arch-Linux 0.7.2:
uname -a
2.6.18-ARCH #1 SMP PREEMPT Thu Nov 30 21:32:54 CET 2006 i686 AMD Athlon(tm) 64 Processor 3200+ AuthenticAMD GNU/Linux
The bug occured with
svn build rev 3353 (2006-12-07 14:49:33) gcc 4.1.2 Linux/unicode
as well as with a version from the 3rd of december (don't remember the version-number).
Here's the backtrace:
codeblocks -d
*** glibc detected *** codeblocks: double free or corruption (!prev): 0x08c5a0d8 ***
======= Backtrace: =========
/lib/libc.so.6[0xb72fdb10]
/lib/libc.so.6(__libc_free+0x89)[0xb72ff1a9]
/usr/lib/libwx_gtk2u_core-2.6.so.0[0xb773fe3c]
/usr/lib/libgtk-x11-2.0.so.0[0xb6ff89c6]
/usr/lib/libgobject-2.0.so.0(g_closure_invoke+0x13b)[0xb6e3007b]
/usr/lib/libgobject-2.0.so.0[0xb6e404e9]
/usr/lib/libgobject-2.0.so.0(g_signal_emit_valist+0x899)[0xb6e419a9]
/usr/lib/libgobject-2.0.so.0(g_signal_emit_by_name+0xee)[0xb6e4475e]
/usr/lib/libgtk-x11-2.0.so.0[0xb70556e4]
/usr/lib/libgtk-x11-2.0.so.0(gtk_selection_convert+0x145)[0xb7056565]
/usr/lib/libwx_gtk2u_core-2.6.so.0(_ZN11wxClipboard7GetDataER12wxDataObject+0x1ec)[0xb774009c]
/usr/local/lib/libcodeblocks.so.0(_ZN11ScintillaWX5PasteEv+0x17f)[0xb7d9a04f]
/usr/local/lib/libcodeblocks.so.0(_ZN6Editor7WndProcEjml+0x1c5a)[0xb7dc77ba]
/usr/local/lib/libcodeblocks.so.0(_ZN13ScintillaBase7WndProcEjml+0x2b7)[0xb7e4c437]
/usr/local/lib/libcodeblocks.so.0(_ZN11ScintillaWX7WndProcEjml+0x44)[0xb7d985c4]
/usr/local/lib/libcodeblocks.so.0(_ZN11wxScintilla7SendMsgEill+0x2f)[0xb7d9ca0f]
/usr/local/lib/libcodeblocks.so.0(_ZN11wxScintilla5PasteEv+0x32)[0xb7d9f062]
/usr/local/lib/libcodeblocks.so.0(_ZN8cbEditor5PasteEv+0x25)[0xb7bd6d95]
codeblocks(_ZN9MainFrame11OnEditPasteER14wxCommandEvent+0x38)[0x807aff8]
/usr/lib/libwx_baseu-2.6.so.0(_ZNK12wxAppConsole11HandleEventEP12wxEvtHandlerMS0_FvR7wxEventES3_+0x35)[0xb7533395]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler21ProcessEventIfMatchesERK21wxEventTableEntryBasePS_R7wxEvent+0x92)[0xb75bf662]
/usr/lib/libwx_baseu-2.6.so.0(_ZN16wxEventHashTable11HandleEventER7wxEventP12wxEvtHandler+0x7b)[0xb75bf7ab]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0xcf)[0xb75bf91f]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_baseu-2.6.so.0(_ZN12wxEvtHandler12ProcessEventER7wxEvent+0x6e)[0xb75bf8be]
/usr/lib/libwx_gtk2u_core-2.6.so.0[0xb77c0568]
/usr/lib/libgobject-2.0.so.0(g_cclosure_marshal_VOID__VOID+0x4b)[0xb6e3d41b]
/usr/lib/libgobject-2.0.so.0(g_closure_invoke+0x13b)[0xb6e3007b]
/usr/lib/libgobject-2.0.so.0[0xb6e404e9]
/usr/lib/libgobject-2.0.so.0(g_signal_emit_valist+0x899)[0xb6e419a9]
/usr/lib/libgobject-2.0.so.0(g_signal_emit+0x29)[0xb6e41b59]
/usr/lib/libgtk-x11-2.0.so.0[0xb711002d]
/usr/lib/libgobject-2.0.so.0(g_closure_invoke+0x13b)[0xb6e3007b]
/usr/lib/libgobject-2.0.so.0[0xb6e404e9]
/usr/lib/libgobject-2.0.so.0(g_signal_emit_valist+0x678)[0xb6e41788]
======= Memory map: ========
08048000-080df000 r-xp 00000000 03:02 121214 /usr/local/bin/codeblocks
080df000-080e5000 rwxp 00096000 03:02 121214 /usr/local/bin/codeblocks
080e5000-08cd4000 rwxp 080e5000 00:00 0 [heap]
b285b000-b285c000 ---p b285b000 00:00 0
b285c000-b305c000 rwxp b285c000 00:00 0
b305c000-b3068000 r-xp 00000000 03:02 121681 /usr/share/fonts/TTF/VeraMoBd.ttf
b3068000-b3069000 ---p b3068000 00:00 0
b3069000-b3869000 rwxp b3069000 00:00 0
b3869000-b3876000 r-xp 00000000 03:02 121680 /usr/share/fonts/TTF/VeraMono.ttf
b3876000-b388c000 r-xp 00000000 03:02 121460 /usr/local/share/codeblocks/plugins/libcb_koders.so
b388c000-b388d000 rwxp 00016000 03:02 121460 /usr/local/share/codeblocks/plugins/libcb_koders.so
b388d000-b388e000 ---p b388d000 00:00 0
b388e000-b408e000 rwxp b388e000 00:00 0
b408e000-b4130000 r-xp 00000000 03:02 121260 /usr/local/share/codeblocks/plugins/libcodecompletion.so
b4130000-b4135000 rwxp 000a1000 03:02 121260 /usr/local/share/codeblocks/plugins/libcodecompletion.so
b4135000-b413d000 rwxp b4135000 00:00 0
b413d000-b4150000 r-xp 00000000 03:02 121491 /usr/local/share/codeblocks/plugins/libhelp_plugin.so
b4150000-b4151000 rwxp 00013000 03:02 121491 /usr/local/share/codeblocks/plugins/libhelp_plugin.so
b4151000-b4161000 r-xp 00000000 03:02 121231 /usr/local/share/codeblocks/plugins/libclasswizard.so
b4161000-b4162000 rwxp 00010000 03:02 121231 /usr/local/share/codeblocks/plugins/libclasswizard.so
b4162000-b4170000 r-xp 00000000 03:02 121485 /usr/local/shaAbgebrochen
Hi,
Couple of months ago I encountered the same problem I posted this issue at wxCode forum, but unfortunaly I got no replies but one, but I did managed to find a solution for this
(it is, in my opinion wxScintilla bug)
the bug report and the solution can be found here:
http://wxforum.shadonet.com/viewtopic.php?t=9907 (http://wxforum.shadonet.com/viewtopic.php?t=9907)
A quick solution is to replace the Paste function with this one: (ScintillWX.cpp):
void ScintillaWX::Paste() {
pdoc->BeginUndoAction();
ClearSelection();
#if wxUSE_DATAOBJ
wxTextDataObject data;
wxString textString;
wxWX2MBbuf buf;
int len = 0;
bool rectangular = false;
if (wxTheClipboard->Open()) {
wxTheClipboard->UsePrimarySelection(false);
wxCustomDataObject selData(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_PRIVATE);
bool gotRectData = wxTheClipboard->GetData(selData);
if (gotRectData && selData.GetSize()>1) {
const char* rectBuf = (const char*)selData.GetData();
rectangular = rectBuf[0] == (char)1;
len = selData.GetDataSize()-1;
char* buffer = new char[len];
memcpy (buffer, rectBuf+1, len);
textString = sci2wx(buffer, len);
delete buffer;
} else {
bool gotData = wxTheClipboard->GetData(data);
if (gotData) {
textString = wxTextBuffer::Translate (data.GetText(),
wxConvertEOLMode(pdoc->eolMode));
}
}
data.SetText(wxEmptyString); // free the data object content
wxTheClipboard->Close();
}
buf = (wxWX2MBbuf)wx2sci(textString);
len = strlen(buf);
int newPos = 0;
if (rectangular) {
int newLine = pdoc->LineFromPosition (currentPos) + wxCountLines (buf, pdoc->eolMode);
int newCol = pdoc->GetColumn(currentPos);
PasteRectangular (currentPos, buf, len);
newPos = pdoc->FindColumn (newLine, newCol);
} else {
pdoc->InsertString (currentPos, buf, len);
newPos = currentPos + len;
}
SetEmptySelection (newPos);
#endif // wxUSE_DATAOBJ
pdoc->EndUndoAction();
NotifyChange();
Redraw();
}
Eran
Eran,
Who is wxCountLines? It seems that it is not defined.
From ScintillaWX.cxx right after the wxConvertEOLMode method; this is from code written after C::B version of it.
static int wxCountLines(const char* text, int scintillaMode)
{
char eolchar;
switch (scintillaMode) {
case wxSCI_EOL_CRLF:
case wxSCI_EOL_LF:
eolchar = '\n';
break;
case wxSCI_EOL_CR:
eolchar = '\r';
break;
default:
return 0;
}
int count = 0;
int i = 0;
while (text[i] != 0) {
if (text[i] == eolchar) {
count++;
}
i++;
}
return count;
}
This is bugging me too. I'm using C::B Revison 3593, OpenSUSE 10.2, wxGTK-2.6.3.1 and wx is compiled as Release-Dynamic-Unicode-Monolithic.
@Biplab
C::B crashes after using Ctrl+V or Edit>Paste.
Since you're getting this crash, could you trap it and give us a backtrace.
You can use the follow (or like) bash shell to trap the crash.
#!/bin/sh
echo run>run.txt
APP_DIR=`pwd`
export LD_LIBRARY_PATH=$APP_DIR:$LD_LIBRARY_PATH
gdb --command=run.txt --args $APP_DIR/codeblocks $@
If you're using windows, just run codeblocks under gdb, like
gdb codeblocks
run
You can make a .cmd file for it like:
echo run>run.txt
gdb -command=run.txt codeblocks
@Biplab:
When in wndows, run it from the src/devel.
When in Linux run it from where the codeblocks executable is.
Else just change the APP_DIR=`pwd` to the dir of codeblocks, and run it from anywhere.
For example, here's one without gdb running the nightly install (not my compiled svn install) from /home/pecan/cbNightly/usr/bin with the LIB also changed.
I cd to /home/pecan/cbNightly/usr/bin and issue ./run.sh
#!/bin/sh
APP_DIR=`pwd`
export LD_LIBRARY_PATH=$APP_DIR/lib:$LD_LIBRARY_PATH
$APP_DIR/bin/codeblocks --prefix=$APP_DIR $@
When the crash finally occurs, issue the command:
bt full
and keep hitting enter (not quit) until the backtrace finishes with a (gdb) prompt.
copy and paste to taste. I like to open an external editor and paste the whole monte so I can restart CB and read the trace later.
@Pecan
My sincere thanks for the help. I'll try my best to learn GDB. :D
I tried for about 10 minutes, but didn't find any crash. It's strange I'm using the same application. I ran the application with the following script (from ur example).
#!/bin/sh
APP_DIR=/usr/local
export LD_LIBRARY_PATH=$APP_DIR/lib:$LD_LIBRARY_PATH
$APP_DIR/bin/codeblocks --prefix=$APP_DIR $@
I usually run the App using the following Desktop Shortcut (I'm not sure about it's Linux name)
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=Code::Blocks
Comment=
Comment[en_US]=
Exec='/usr/local/bin/codeblocks'
GenericName=Code::Blocks IDE
GenericName[en_US]=Code::Blocks IDE
Icon=
MimeType=;
Name[en_US]=Code::Blocks
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-DCOP-ServiceType=
X-KDE-SubstituteUID=false
X-KDE-Username=
I've to leave my lab right now (It's 12am and the AC is switched off ;)) But please point out any problem you find.
I'll keep trying to reproduce crash report, if any.
Thanks & Regards,
Biplab
Thanks for the instruction. :D
But I would like to ask another question regarding debugging of wxWidgets based app with GDB in Linux. I read the following post in wxWidgets forum.
http://wxforum.shadonet.com/viewtopic.php?t=12530
It says that the user can't see the contents of wxString with GDB in Unicode mode. I tried it and found that in C::B too, in Watches Window I can't see the wxString contents. AFAIK it's possible to view the contents of wxString in Unicode mode with MS Debugger. Why is it so? :)
I suppose because unicode is so full of zeros. It makes it look like the string is empty.
You would need a script to call cbU2C(my watched string) to make it into a c_str.
Just a guess.
I'm no script wizard, not even a novice, but you might be able to issue these commands to gdb and show the results:
bool testwxApp::OnInit()
{
testwxFrame* frame = new testwxFrame(0L, _("wxWidgets Application Template"));
frame->SetIcon(wxICON(aaaa)); // To Set App Icon
frame->Show();
wxString msg;
msg = wxT("test unicode string");
asm("int3");
return true;
}
C:\temp\testwx\bin>gdb testwx.exe
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-mingw32"...
(gdb) run
Starting program: C:\temp\testwx\bin/testwx.exe
gdb: do_initial_child_stuff: process 1572
gdb: kernel event for pid=1572 tid=288 code=CREATE_PROCESS_DEBUG_EVENT)
gdb: child_resume.SetThreadContext: thread 1572.0x120
ContinueDebugEvent (cpid=1572, ctid=288, DBG_CONTINUE);
<snip>
Program received signal SIGTRAP, Trace/breakpoint trap.
testwxApp::OnInit (this=0xb59290) at C:/temp/testwx/testwxApp.cpp:32
32 return true;
Current language: auto; currently c++
(gdb) l
27 frame->Show();
28
29 wxString msg;
30 msg = wxT("test unicode string");
31 asm("int3");
32 return true;
33 }
(gdb) p msg
$1 = {<wxStringBase> = {static npos = 4294967295,
m_pchData = 0xb6a654}, <No data fields>}
(gdb) p msg.m_pchData
$2 = (wxChar *) 0xb6a654
(gdb) x/20s msg.m_pchData
0xb6a654: "t"
0xb6a656: "e"
0xb6a658: "s"
0xb6a65a: "t"
0xb6a65c: " "
0xb6a65e: "u"
0xb6a660: "n"
0xb6a662: "i"
0xb6a664: "c"
0xb6a666: "o"
0xb6a668: "d"
0xb6a66a: "e"
0xb6a66c: " "
0xb6a66e: "s"
0xb6a670: "t"
0xb6a672: "r"
0xb6a674: "i"
0xb6a676: "n"
0xb6a678: "g"
0xb6a67a: ""
(gdb)