Archived

This topic is now archived and is closed to further replies.

Weird Core Dumps

This topic is 5627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. In my spare time at work I am developing a scripting engine in C++ which I can use with my games. All I have access to is Unix so I am developing it on this platform. Its all C++ so it should be easy to get it to work with Win32 when I am ready. I am getting a very weird error/core dump and it is driving me crazy trying to think of why this would happen. Here is the function in which it is core dumping
  
bool Declaration::Execute( HashTable &htVariables )
{
    DeclarAssignSegment* AssPtr = AssHead;

    while( AssPtr != NULL )
    {
        AssPtr->DestVar->SetValue( AssPtr->AssignExpr->Execute( htVariables ) );
        AssPtr = AssPtr->Next;
    }
    return true;
}
  
The output from gdb doesnt show much besides that it dumped here. I then added a few cout statements to try and see exactly where it is dumping, and it wouldnt dump anymore, so I found that if I add 1 cout statement as follows
  
bool Declaration::Execute( HashTable &htVariables )
{
    DeclarAssignSegment* AssPtr = AssHead;

    while( AssPtr != NULL )
    {
        AssPtr->DestVar->SetValue( AssPtr->AssignExpr->Execute( htVariables ) );
        AssPtr = AssPtr->Next;
    }

    cout<<"Returning"<<endl;
    return true;
}
  
it doesnt core dump. How can this be? What difference would a cout statement make to a program dumping or running? Giant "Only two things are infinite, the universe and human stupidity, and I''m not sure about the former." --Albert Einstein

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Weird bugs like that are usually the result of problems in memory allocation. You probably forgot to allocate memory for something one of your pointers is pointing to, or (less likely) you are using memory you already freed. When you add the string to the code, the memory allocated by the compiler to hold it changes the layout of memory in such a way that you temporarily get away with the bug.

p.s. the term for a bug that changes when you try to inspect it is "Heisenbug" :}

Share this post


Link to post
Share on other sites