Author Topic: Crash when changing active target  (Read 6972 times)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Crash when changing active target
« on: February 02, 2007, 12:31:55 pm »
andLinux SVN 3558 gcc 4.0.4 Linux/unicode

Occasionaly when I change a project target via the toolbar: crash

Code
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1230625104 (LWP 1566)]
0x08073a87 in wxStringBase::size (this=0x8ddd940)
    at /usr/include/wx-2.6/wx/string.h:367
367       size_type size() const { return GetStringData()->nDataLength; }
(gdb) bt
#0  0x08073a87 in wxStringBase::size (this=0x8ddd940)
    at /usr/include/wx-2.6/wx/string.h:367
#1  0x08073b2b in wxStringBase::length (this=0x8ddd940)
    at /usr/include/wx-2.6/wx/string.h:369
#2  0x0809f3e1 in wxString::Len (this=0x8ddd940)
    at /usr/include/wx-2.6/wx/string.h:689
#3  0x0809f543 in operator== (s1=@0xbfa40484, s2=@0x8ddd940)
    at /usr/include/wx-2.6/wx/string.h:1437
#4  0xb76de3d8 in cbProject::SetActiveBuildTarget (this=0x8ddd818,
    name=@0xbfa40484) at sdk/cbproject.cpp:1587
#5  0xb479f8b8 in CompilerGCC::DoUpdateTargetMenu (this=0x88e48a8,
    targetIndex=2) at plugins/compilergcc/compilergcc.cpp:1235
#6  0xb47a4ce9 in CompilerGCC::OnSelectTarget (this=0x88e48a8,
    event=@0xbfa40748) at plugins/compilergcc/compilergcc.cpp:2921
#7  0xb7993655 in wxAppConsole::HandleEvent ()
   from /usr/lib/libwx_baseu-2.6.so.0
#8  0xb7a22b52 in wxEvtHandler::ProcessEventIfMatches ()
   from /usr/lib/libwx_baseu-2.6.so.0
#9  0xb7a22c9d in wxEventHashTable::HandleEvent ()
   from /usr/lib/libwx_baseu-2.6.so.0
#10 0xb7a22e1f in wxEvtHandler::ProcessEvent ()
   from /usr/lib/libwx_baseu-2.6.so.0
#11 0xb7a22dbe in wxEvtHandler::ProcessEvent ()
---Type <return> to continue, or q <return> to quit---q
 from /usr/lib/libwx_baseu-2.6.soQuit
(gdb) f 4
#4  0xb76de3d8 in cbProject::SetActiveBuildTarget (this=0x8ddd818,
    name=@0xbfa40484) at sdk/cbproject.cpp:1587
1587        if (name == m_ActiveTarget)
(gdb) p name
$1 = (const wxString &) @0xbfa40484: {<wxStringBase> = {
    static npos = 4294967295, m_pchData = 0x8e75cdc}, <No data fields>}
(gdb) p m_ActiveTarget
$2 = {<wxStringBase> = {static npos = 4294967295,
    m_pchData = 0x67}, <No data fields>}
(gdb)


« Last Edit: February 02, 2007, 12:34:03 pm by Pecan »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Crash when changing active target
« Reply #1 on: February 02, 2007, 01:40:28 pm »
Sounds like the project pointer used is invalid...
Although I can't reproduce it, can you try the following?

In src/plugins/compilergcc/compilergcc.cpp:1234, there is this code:
Code
    if (m_Project)
        m_Project->SetActiveBuildTarget(GetTargetString(m_TargetIndex));

Replace it with this:
Code
    if (Manager::Get()->GetProjectManager()->GetActiveProject())
        Manager::Get()->GetProjectManager()->GetActiveProject()->SetActiveBuildTarget(GetTargetString(m_TargetIndex));

Test it out for a while (a day or two) and if the crash is gone tell me to commit it.
Be patient!
This bug will be fixed soon...

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Crash when changing active target
« Reply #2 on: February 08, 2007, 09:14:50 pm »
Sounds like the project pointer used is invalid...
Although I can't reproduce it, can you try the following?

In src/plugins/compilergcc/compilergcc.cpp:1234, there is this code:
Code
    if (m_Project)
        m_Project->SetActiveBuildTarget(GetTargetString(m_TargetIndex));

Replace it with this:
Code
    if (Manager::Get()->GetProjectManager()->GetActiveProject())
        Manager::Get()->GetProjectManager()->GetActiveProject()->SetActiveBuildTarget(GetTargetString(m_TargetIndex));

Test it out for a while (a day or two) and if the crash is gone tell me to commit it.

This fix seems to have done the job.

I noticed that the original problem occured while I was building a large project with a lot of targets and switching back and forth without doing an intervening save.

thanks, it saved a lot of time.
pecan


Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: Crash when changing active target
« Reply #3 on: February 08, 2007, 09:56:41 pm »
It makes me think of a bug I submitted to BerliOS :
https://developer.berlios.de/bugs/?func=detailbug&group_id=5358&bug_id=9655

I had a crash switching from a project to another one during debug sesion.

The difference is that I switched from a project to another instead of a target to another but context and crash are very similar...

Dje


Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Crash when changing active target
« Reply #4 on: February 08, 2007, 10:13:51 pm »
It makes me think of a bug I submitted to BerliOS :
https://developer.berlios.de/bugs/?func=detailbug&group_id=5358&bug_id=9655

I had a crash switching from a project to another one during debug sesion.

The difference is that I switched from a project to another instead of a target to another but context and crash are very similar...

Dje

I think you'll find that bug fixed here:
http://forums.codeblocks.org/index.php?topic=5120.msg40163#msg40163
debugger stop button on Linux console pgm crashes CB

It's caused by a "delete m_pDirver" being called while data is still in the GDBOuput queue.

I made the fix for Linux only, but there's no reason it wouldn't work for XP.
It's a temporary fix until mandrav decides how he wants to handle it.
« Last Edit: February 08, 2007, 10:26:49 pm by Pecan »

Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: Crash when changing active target
« Reply #5 on: February 08, 2007, 10:17:52 pm »
Ok, thanks.
It was on Windows SP2.

If you think it's the same problem (and it looks), "my" bug should be closed...

I can't do it.

Dje

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Crash when changing active target
« Reply #6 on: February 08, 2007, 10:28:54 pm »
Ok, thanks.
It was on Windows SP2.

If you think it's the same problem (and it looks), "my" bug should be closed...

I can't do it.

Dje

I think we should let Yiannis make that decision.

I don't think my fix encompases all the possible ramifications of delaying the GDB_Driver close.

But it will allow us to stop/restart/continue/switch/close while debugging a console task with no crashes.

He'll know better than I.
« Last Edit: February 08, 2007, 10:46:06 pm by Pecan »