This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

STL Vector problem - Abort on push_back()

Other Parts Discussed in Thread: TMS320C6748

In my current project, I am working on a TMS320C6748 and am in the process of implementing UART functionality. The UART is working great, and I decided to wrap it up a bit for my specific application, so I decided to have any messages sent to the chip be read in groups of 4 bytes. To do this, I have it set up so that whenever there is an interrupt raised for the FIFO meeting the trigger level, the application grabs each byte in the buffer and stores it in a vector (to be further compacted into "message" objects and acted on).

However, I have found that while I can create vectors, I cannot use their functions. In particular, push_back() causes the application to abort and run to its exit() function. I read in another thread that this might be caused by having no heap memory available, so I made sure to check that first and set my heap size to 0x2000, but this did not solve my problem.

Any suggestions for what might be happening? Below is the related part of the code:

void cUartManager::handleCommands()
{
    std::vector<uint8_t> words;
    uint8_t temp;
    uint8_t count;

    // Grab all bytes in FIFO buffer
    while( CHKBIT( DEBUG_PORT->LSR, DR ) )
    {
        // Read a byte and place it into vector
        rxByte( &temp );
        words.push_back( temp );            //  Crashes here
    }

    // Find the size of the vector
    count = words.size();

.... etc

}

Thanks,
Charles

  • How many bytes can you successfully push before crashing? 

    If you can afford the space, try compiling with exceptions enabled, and put the push_back in a try/catch block to see if you're running out of heap memory.

  • Currently, I cannot push any bytes at all; crashes on the first push_back().

    Not really sure how to work with handling exceptions in this environment. Is there a guide/example/set of steps for doing so, or is it as simple as using the standar:

    try
    {
          words.push_back( temp );
    }
    catch( std::bad_alloc& ba)
    {
          Log_info1( "Bad allocation: %s", ba.what() );
    }

    Thanks

  • Yes, but you'll also need to add the --exceptions command-line argument.

    Since we don't know exactly what the problem is, I'd add a catch to catch any exception:

    try
    {
          words.push_back( temp );
    }
    catch( std::bad_alloc& ba)
    {
          Log_info1( "Bad allocation: %s", ba.what() );
    }
    catch( std::exception &e)
    {
          Log_info1( "Unhandled exception: %s", e.what() );
    }
    catch( ... )
    {
          Log_info1( "Unknown exception" );
    }
  • I turned exceptions on and gave this a try, but oddly enough it still immediately jumps to "abort() at exit.c" and doesn't execute any of the catch{} clauses.

    Further suggestions?

  • It's not jumping straight to abort, you're just not seeing the intervening functions because the RTS library isn't built with debugging enabled.

    Set a breakpoint on malloc and calloc and see if either one returns NULL.  You'll probably want to examine the value of B3 upon entry to malloc, set another breakpoint there, and run to it.