Error management : backtrace problem


#1

Hi everybody,

I tried to get backtrace after an exception (ADL_INIT_REBOOT_FROM_EXCEPTION event in adl_main). I want to display the backtrace in the terminal emulator.
I used bug_GetBkTrcBuffer to get the backtrace buffer. The problem is that adl_errRetrieveNextBacktrace returns always -11 ADL_RET_ERR_DONE… I don’t analyze theses backtraces before. When a cause an exception, there isn’t new backtrace available…

I’m using an Q2686H with OpenAT 4.

Does someone have an idea ?

Thanks

u8 * bug_GetBkTrcBuffer ( u8 BktrId, u16 * Size, u8 * Count )
{
    u8 * TotalBuffer = NULL;
    
    // Initialize backtraces analysis
    s8 AnalysisHandle = adl_errStartBacktraceAnalysis();
    
    TRACE (( 2, "[bug_GetBkTrcBuffer] start analysis : %d", AnalysisHandle ));
    
    // Initialize variables
    *Count = 0;
    *Size = 0;

    // Check handle
    if ( AnalysisHandle >= OK )
    {
        s32 sReturn = OK;
        s32 NextBufferSize;
        
        // Start loop to retrieve all backtraces
        while ( sReturn == OK )
        {
            // Get size
            sReturn = NextBufferSize = adl_errRetrieveNextBacktrace ( AnalysisHandle, NULL, 0 );
            TRACE (( 2, "[bug_GetBkTrcBuffer] required size : %d", NextBufferSize ));
            
            // Check if there is something to get
            if ( NextBufferSize > 0 )
            {
                u8 * NewBuffer;
                
                // Check for mode
                if ( !BktrId )
                {
                    // "Cumulative" mode
                    // Reallocate memory
                    NewBuffer = adl_memGet ( NextBufferSize + *Size );
                    
                    // Copy old buffer (if any)
                    if ( *Size && TotalBuffer )
                    {
                        wm_memcpy ( NewBuffer, TotalBuffer, *Size );
                        
                        // Release old buffer
                        adl_memRelease ( TotalBuffer );
                    }
                    
                    // Update total buffer
                    TotalBuffer = NewBuffer;
                }
                else
                {
                    // Get memory just for the current one
                    TotalBuffer = adl_memGet ( NextBufferSize );
                }
                
                // Get backtrace
                sReturn = adl_errRetrieveNextBacktrace ( AnalysisHandle, TotalBuffer + *Size, NextBufferSize );
                TRACE (( 2, "[bug_GetBkTrcBuffer] retrieve backtrace result : %d", sReturn ));
                
                // Check for mode
                if ( !BktrId )
                {
                    // Update total size
                    *Size += NextBufferSize;
                }
                else
                {
                    // Check if it is the required one
                    if ( ( BktrId - 1 ) == *Count )
                    {
                        // Yes : update size and exit
                        *Size = NextBufferSize;
                        *Count = 1;
                        break;
                    }
                    else
                    {
                        // Not the required one : release memory
                        adl_memRelease ( TotalBuffer );
                    }
                }
                
                // Increase backtrace count if retrieve OK
                if ( sReturn == OK )
                {
                    *Count += 1;
                }
            }
        }
    }
    
    TRACE (( 2, "[bug_GetBkTrcBuffer] count : %d ; size : %d", *Count, *Size ));
    
    return TotalBuffer;
}

#2

I supose this code keep traces in the modem. But, how you retrieve it to view traces in a pc which the modem is conected??


#3

Hi nebuchanazer,

You can use de TRACE function who display the trace in the target monitoring tool.

The bug sample didn’t work in debug mode. You must compile it in wismo target mode, upload the dwl and run the sample. Works perfectly after :wink:

Regards,

gdt