Author Topic: C::B crash (Settings-->Editor)  (Read 36925 times)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2186
Re: C::B crash (Settings-->Editor)
« Reply #30 on: April 16, 2006, 02:20:06 am »
Michael,

would you look in default.conf (or which ever the one you're using)
and show us your <codestat> entry.

Sorry, but where it is located on Linux?

Best wishes,
Michael


I believe it's in your home directory under ".codeblocks"
named default.conf


thanks
pecan


Actually, I want to know what is in your default.conf
under the key <codestat> to see why
Code: [Select]
int LoadSettings(LanguageDef languages[NB_FILETYPES_MAX])
{
    ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("codestat"));
    int nb_languages = cfg->ReadInt(_T("/nb_languages"), 0);

nb_languages ends up being 0.
For example, my default.conf key <codestat> contains
Code: [Select]
<codestat>
<NB_LANGUAGES int="7" />
<l0>
<NAME>
<str>C/C++</str>
</NAME>
<EXT>
<str>c cpp h hpp </str>
</EXT>
<SINGLE_LINE_COMMENT>
<str>//</str>
</SINGLE_LINE_COMMENT>
<MULTIPLE_LINE_COMMENT_BEGIN>
<str>/*</str>
</MULTIPLE_LINE_COMMENT_BEGIN>
<MULTIPLE_LINE_COMMENT_END>
<str>*/</str>
</MULTIPLE_LINE_COMMENT_END>
</l0>
<l1>
<NAME>
<str>Java</str>
</NAME>
<EXT>
<str>java </str>
</EXT>
<SINGLE_LINE_COMMENT>
<str>//</str>
</SINGLE_LINE_COMMENT>
<MULTIPLE_LINE_COMMENT_BEGIN>
<str>/*</str>
</MULTIPLE_LINE_COMMENT_BEGIN>
<MULTIPLE_LINE_COMMENT_END>
<str>*/</str>
</MULTIPLE_LINE_COMMENT_END>
</l1>
<l2>
<NAME>
<str>Python</str>
</NAME>
<EXT>
<str>py </str>
</EXT>
<SINGLE_LINE_COMMENT>
<str>#</str>
</SINGLE_LINE_COMMENT>
<MULTIPLE_LINE_COMMENT_BEGIN>
<str />
</MULTIPLE_LINE_COMMENT_BEGIN>
<MULTIPLE_LINE_COMMENT_END>
<str />
</MULTIPLE_LINE_COMMENT_END>
</l2>
<l3>
<NAME>
<str>Perl</str>
</NAME>
<EXT>
<str>pl </str>
</EXT>
<SINGLE_LINE_COMMENT>
<str>#</str>
</SINGLE_LINE_COMMENT>
<MULTIPLE_LINE_COMMENT_BEGIN>
<str />
</MULTIPLE_LINE_COMMENT_BEGIN>
<MULTIPLE_LINE_COMMENT_END>
<str />
</MULTIPLE_LINE_COMMENT_END>
</l3>
<l4>
<NAME>
<str>ASM</str>
</NAME>
<EXT>
<str>asm </str>
</EXT>
<SINGLE_LINE_COMMENT>
<str>;</str>
</SINGLE_LINE_COMMENT>
<MULTIPLE_LINE_COMMENT_BEGIN>
<str />
</MULTIPLE_LINE_COMMENT_BEGIN>
<MULTIPLE_LINE_COMMENT_END>
<str />
</MULTIPLE_LINE_COMMENT_END>
</l4>
<l5>
<NAME>
<str>Pascal</str>
</NAME>
<EXT>
<str>pas </str>
</EXT>
<SINGLE_LINE_COMMENT>
<str />
</SINGLE_LINE_COMMENT>
<MULTIPLE_LINE_COMMENT_BEGIN>
<str>{</str>
</MULTIPLE_LINE_COMMENT_BEGIN>
<MULTIPLE_LINE_COMMENT_END>
<str>}</str>
</MULTIPLE_LINE_COMMENT_END>
</l5>
<l6>
<NAME>
<str>Matlab</str>
</NAME>
<EXT>
<str>m </str>
</EXT>
<SINGLE_LINE_COMMENT>
<str>%</str>
</SINGLE_LINE_COMMENT>
<MULTIPLE_LINE_COMMENT_BEGIN>
<str />
</MULTIPLE_LINE_COMMENT_BEGIN>
<MULTIPLE_LINE_COMMENT_END>
<str />
</MULTIPLE_LINE_COMMENT_END>
</l6>
</codestat>

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: C::B crash (Settings-->Editor)
« Reply #31 on: April 16, 2006, 02:34:16 am »
Hello,

What I have found is that language[NB_FILETYPES_MAX] and nb_languages are private members of the class CodeStatConfigDlg (in codestatconfig.h).

The problem with the Settings-->Editor come from here CodeStatConfigDlg::CodeStatConfigDlg(wxWindow* parent) (codestatconfig.cpp, lignes 35-45).

When in LoadDefaultSettings C::B tries languages[0].name = _T("C/C++"); it crashes.

In my config file I do not have this. MAy be because when C::B crashes, modification are not stored into the config file?

I just will try to add part of your config to mine. [EDIT]: It still crashes :(.

Best wishes,
Michael
« Last Edit: April 16, 2006, 02:41:44 am by Michael »

Offline Zlika

  • Plugin developer
  • Multiple posting newcomer
  • ****
  • Posts: 59
Re: C::B crash (Settings-->Editor)
« Reply #32 on: April 17, 2006, 08:13:22 pm »
Hi
The default settings are stored in the config file at the first use of codestat (in the LoadSettings function, the "int nb_languages = cfg->ReadInt(_T("/nb_languages"), 0);" should return 0 and then the LoadDefaultSettings function is called to load and save the default settings of the plugin). So it's normal that your config file doen't contains any codestat settings (until it works correctly...).

However, your crash is very strange because I can't understand where there can be an error in "languages[0].name = _T("C/C++");", just before your crash. There is no problem of memory allocation because "languages" is an array of fixed size.

I'll try to investigate the problem but it's very difficult because I can't reproduce the error. Tell me if you have more info about it.

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: C::B crash (Settings-->Editor)
« Reply #33 on: April 17, 2006, 08:42:41 pm »
However, your crash is very strange because I can't understand where there can be an error in "languages[0].name = _T("C/C++");", just before your crash. There is no problem of memory allocation because "languages" is an array of fixed size.

I'll try to investigate the problem but it's very difficult because I can't reproduce the error. Tell me if you have more info about it.

Hello,

I am not fully sure, but it seems to me that the problem is related to the operator =.

Quote
#0  0xb7a4a349 in wxStringBase::AllocBeforeWrite ()
   from /usr/lib/libwx_baseu-2.6.so.0
#1  0xb7a4acb0 in wxStringBase::AssignCopy ()
   from /usr/lib/libwx_baseu-2.6.so.0
#2  0xb7a4ad34 in wxStringBase::operator= () from /usr/lib/libwx_baseu-2.6.so.0
#3  0x0806da16 in wxString::operator= (this=0x98db36c, psz=0xb5cd1210)
    at string.h:854
#4  0xb5cba35e in LoadDefaultSettings (languages=0x98db36c)
    at codestatconfig.cpp:224
[...]

Anyway, it should be a local problem (may b e from my wxGTK library). I will try to investigate and see what i cna find out.

Best wishes,
Michael

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2186
Re: C::B crash (Settings-->Editor)
« Reply #34 on: April 17, 2006, 10:03:14 pm »
Code: [Select]
"languages[0].name = _T("C/C++");"

To see if it's a wxGTK error in wxString operator=() try
the following on the first assignment statement and
see if the crash moves to the second assignment.

Code: [Select]
"languages[0].name = wxString(_T("C/C++"));"

This forces the creation of the string form operator=
to wxString::Clear() and then to wxString::Append().

This is looking more and more like a wxGTK error, but
I couldn't find anything about an assignment bug on
google or wxWidgets.

thanks
pecan

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2186
Re: C::B crash (Settings-->Editor)
« Reply #35 on: April 17, 2006, 10:09:09 pm »
Quote
However, your crash is very strange because I can't understand where there can be an error in "languages[0].name = _T("C/C++");", just before your crash. There is no problem of memory allocation because "languages" is an array of fixed size.

The allocation crash is not in the allocation of the lanugages
array, it's in the allocation of memory for the creation of the
wxString. wxGTK is allocating 2 byte at a time and copying
"C/C++" into a wxString at AllocBeforWrite().

pecan


Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: C::B crash (Settings-->Editor)
« Reply #36 on: April 17, 2006, 10:28:09 pm »
Code: [Select]
"languages[0].name = _T("C/C++");"

To see if it's a wxGTK error in wxString operator=() try
the following on the first assignment statement and
see if the crash moves to the second assignment.

Code: [Select]
"languages[0].name = wxString(_T("C/C++"));"

This forces the creation of the string form operator=
to wxString::Clear() and then to wxString::Append().

This is looking more and more like a wxGTK error, but
I couldn't find anything about an assignment bug on
google or wxWidgets.

It still crash, but with a difference:

Quote
#0  0xb7a4a349 in wxStringBase::AllocBeforeWrite ()
   from /usr/lib/libwx_baseu-2.6.so.0
#1  0xb7a4acb0 in wxStringBase::AssignCopy ()
   from /usr/lib/libwx_baseu-2.6.so.0
#2  0xb7a4ad34 in wxStringBase::operator= () from /usr/lib/libwx_baseu-2.6.so.0
#3  0x0806da16 in wxString::operator= (this=0x98db36c, psz=0xb5cd1210)
    at string.h:854
#4  0xb5cba35e in LoadDefaultSettings (languages=0x98db36c)
    at codestatconfig.cpp:224
[...]

The cause for the SIGSEGV seems now to be the wxStringBase::operator= () from /usr/lib/libwx_baseu-2.6.so.0.

Best wishes,
Michael

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2186
Re: C::B crash (Settings-->Editor)
« Reply #37 on: April 18, 2006, 12:11:38 am »
Here's the code executed during the assignment.
Notice that the assignment can fail if memory allocation fails.
No message will occur because wxFail_Msg is issued only in
__wxDEBUG__ mode.
Code: [Select]
// assigns C string
wxStringBase& wxStringBase::operator=(const wxChar *psz)
{
  if ( !AssignCopy(wxStrlen(psz), psz) ) {
    wxFAIL_MSG( _T("out of memory in wxStringBase::operator=(const wxChar *)") );
  }
  return *this;
}

// helper function: does real copy
bool wxStringBase::AssignCopy(size_t nSrcLen, const wxChar *pszSrcData)
{
  if ( nSrcLen == 0 ) {
    Reinit();
  }
  else {
    if ( !AllocBeforeWrite(nSrcLen) ) {
      // allocation failure handled by caller
      return false;
    }
    memcpy(m_pchData, pszSrcData, nSrcLen*sizeof(wxChar));
    GetStringData()->nDataLength = nSrcLen;
    m_pchData[nSrcLen] = wxT('\0');
  }
  return true;
}



Is it possible that your're giving out of memory? How much memory
do you have on that system?

pecan
« Last Edit: April 18, 2006, 04:06:12 am by Pecan »

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: C::B crash (Settings-->Editor)
« Reply #38 on: April 18, 2006, 12:24:30 am »
Is it possible that your're giving out of memory? How much memory
do you have on that system?

After the System Monitor I have 504.4MB User Memory and 528.0MB Used swap.

I would exclude a lack of memory.

Best wishes,
Michael

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2186
Re: C::B crash (Settings-->Editor)
« Reply #39 on: April 18, 2006, 04:40:01 am »
Michael,
Would you change statement at line 224 to the following to see
if wxgtk is miscalculating the string length.

Code: [Select]
    languages[0].name = wxString(_T("C/C++"),14);

thanks
pecan

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: C::B crash (Settings-->Editor)
« Reply #40 on: April 18, 2006, 12:59:07 pm »
Michael,
Would you change statement at line 224 to the following to see
if wxgtk is miscalculating the string length.

Code: [Select]
    languages[0].name = wxString(_T("C/C++"),14);

Done.

I get the same error(s) as depicted above.

Best wishes,
Michael

Offline Zlika

  • Plugin developer
  • Multiple posting newcomer
  • ****
  • Posts: 59
Re: C::B crash (Settings-->Editor)
« Reply #41 on: April 18, 2006, 06:38:31 pm »
Just to be sure, do you have the same problem when executing the plugin? (it should execute the same function if the settings are missing, but I want to be sure the error is not related to the way CB load the "settings->editor" forms).

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: C::B crash (Settings-->Editor)
« Reply #42 on: April 18, 2006, 09:39:27 pm »
Just to be sure, do you have the same problem when executing the plugin? (it should execute the same function if the settings are missing, but I want to be sure the error is not related to the way CB load the "settings->editor" forms).

I not yet give a try to it in Linux. In Windows I have used it 2-3 times. Let me check and I will report.

[EDIT]: If I try to use codestats plugin, C::B crashes with the same errors as Settings-->Editor.

Best wishes,
Michael
« Last Edit: April 19, 2006, 12:37:48 am by Michael »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2186
Re: C::B crash (Settings-->Editor)
« Reply #43 on: April 19, 2006, 09:33:59 pm »
The following is the backtrace and code causing the crash.
the "name" string data pointer inside the languages array is never initialized to wxEmptyString on gtk.

GetStringData() is returning m_pchData as 0x0 -1 or (0xfffffff4) as
the address of the languages[].name wxString data.

The culprit is Statement 801: GetStringData()->Unlock();
Now...
Why is languages[].name data pointer not being constructed? Its being set to
all 0x0's

Is it possible that name *is* being constructed, then the non wxWidget array
"languages" is being cleared because languages is not holding pointers
but objects?

I'll test that conjecture next.

Code: [Select]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1230338368 (LWP 30464)]
0x0806e494 in wxStringData::IsEmpty (this=0xfffffff4) at string.h:219
219       bool  IsEmpty()   const { return (nRefs == -1); }
(gdb) bt
#0  0x0806e494 in wxStringData::IsEmpty (this=0xfffffff4) at string.h:219
#1  0x0806e4fc in wxStringData::Unlock (this=0xfffffff4) at string.h:236
#2  0xb78e5569 in wxStringBase::operator= (this=0x8822644,
    [email protected]) at ../src/common/string.cpp:801
#3  0x0806ea4b in wxString::operator= (this=0x8822644) at string.h:610
#4  0xb52767b1 in LoadDefaultSettings (languages=0x8822644)
    at codestatconfig.cpp:224
#5  0xb52770c3 in LoadSettings (languages=0x8822644) at codestatconfig.cpp:297
#6  0xb527787c in CodeStatConfigDlg (this=0x88224e0, parent=0x8a5e518)
    at codestatconfig.cpp:42
#7  0xb527275d in CodeStat::GetConfigurationPanel (this=0x88540b0,
    parent=0x8a5e518) at codestat.cpp:80
#8  0xb76b20f0 in PluginManager::GetConfigurationPanels (this=0x8a040b0,
    group=4, parent=0x8a5e518, [email protected])
    at sdk/pluginmanager.cpp:454
#9  0xb7655632 in EditorConfigurationDlg::AddPluginPanels (this=0xbfa66f98)
    at sdk/editorconfigurationdlg.cpp:258
#10 0xb765adaa in EditorConfigurationDlg (this=0xbfa66f98, parent=0x8338098)
    at sdk/editorconfigurationdlg.cpp:234
#11 0xb766d512 in EditorManager::Configure (this=0x846ac38)
    at sdk/editormanager.cpp:264
#12 0x08093cd5 in MainFrame::OnSettingsEditor (this=0x8338098,
    [email protected]) at src/main.cpp:2976
#13 0xb7885a99 in wxAppConsole::HandleEvent (this=0x8130ea0,
    handler=0x8338098, func=
      {__pfn = 0x8093ca8 <MainFrame::OnSettingsEditor(wxCommandEvent&)>, __delta = 0}, [email protected]) at ../src/common/appbase.cpp:320
#14 0xb79246d2 in wxEvtHandler::ProcessEventIfMatches ([email protected],
    handler=0x8338098, [email protected]) at ../src/common/event.cpp:1185
#15 0xb7924abb in wxEventHashTable::HandleEvent (this=0x80eb4d8,
    [email protected], self=0x8338098) at ../src/common/event.cpp:867
#16 0xb7925a33 in wxEvtHandler::ProcessEvent (this=0x8338098,
---Type <return> to continue, or q <return> to quit---q
[email protected])Quit
(gdb) l
867     ../src/common/event.cpp: No such file or directory.
        in ../src/common/event.cpp
(gdb)

// assigns one string to another
wxStringBase& wxStringBase::operator=(const wxStringBase& stringSrc)
{
  wxASSERT( stringSrc.GetStringData()->IsValid() );

  // don't copy string over itself
  if ( m_pchData != stringSrc.m_pchData ) {
    if ( stringSrc.GetStringData()->IsEmpty() ) {
      Reinit();
    }
    else {
      // adjust references
      GetStringData()->Unlock();    <==== crash victim =====
      m_pchData = stringSrc.m_pchData;
      GetStringData()->Lock();
    }
  }

  return *this;
}

« Last Edit: April 19, 2006, 09:44:03 pm by Pecan »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2186
Re: C::B crash (Settings-->Editor)
« Reply #44 on: April 19, 2006, 10:52:48 pm »
Quote
Is it possible that name *is* being constructed, then the non wxWidget array
"languages" is being cleared because languages is not holding pointers
but objects?

Bad news. languages[].name is actually being constructed as
as an array and being set to 0x0.

Note that all the other strings
are being constructed as wxEmptyString's.

Here are the results just after languages is constructed in CodeStatConfigDlg.
Code: [Select]
0xb76b957f in LanguageDef (this=0x86ec874) at sdk/projectfileoptionsdlg.cpp:54
54      {
(gdb) n
CodeStatConfigDlg (this=0x86ec6f0, parent=0x85a7788) at codestatconfig.cpp:39
39          wxXmlResource::Get()->LoadPanel(this, parent, _("dlgCodeStatConfig"));(gdb) l
34
35      /** Load the language settings and display the configuration dialog.
36       */
37      CodeStatConfigDlg::CodeStatConfigDlg(wxWindow* parent)
38      {
39          wxXmlResource::Get()->LoadPanel(this, parent, _("dlgCodeStatConfig"));40
41          // Load the languages parameters
42          nb_languages = LoadSettings(languages);
43
(gdb) p languages[0].name
$1 = {<wxStringBase> = {static npos = 4294967295,
    m_pchData = 0x0}, <No data fields>}  <==== constructed to 0x0 =====
(gdb) p languages[0].single_line_comment
$2 = {<wxStringBase> = {static npos = 4294967295,
    m_pchData = 0xb795235c}, <No data fields>}
(gdb) p languages[0].multiple_line_comment[0]
$3 = {<wxStringBase> = {static npos = 4294967295,
    m_pchData = 0xb795235c}, <No data fields>}
(gdb)

I'll spend some time trying to find why this is happening.
Then I'll work on a workaround.
« Last Edit: April 19, 2006, 10:54:37 pm by Pecan »