//////////////////////////////////////////////////
//Title    : wxc_debug.c
//Auhtor   : Liu Wei
//Desc     : wxc debug api implemetation   
//Created  : 2007-05-01
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include <unistd.h>
#include "./include/pub_debug.h"

/*@ignore@*/

void WxcDump( int nSigno )
{
    char    buf[1024];
    char    cmd[1024];
    FILE   *fh;

    snprintf ( buf, sizeof ( buf ), "/proc/%d/cmdline", getpid (  ) );
    fh = fopen ( buf, "r" );
    if (  fh == NULL )
        exit ( 0 );
    if ( NULL == (fgets ( buf, sizeof ( buf ), fh ) ))
        exit ( 0 );
    fclose ( fh );
    if ( buf[strlen ( buf ) - 1] == '\n' )
        buf[strlen ( buf ) - 1] = '\0';
    snprintf ( cmd, sizeof ( cmd ), "gdb %s %d", buf, getpid (  ) );
    system ( cmd );

    exit ( 0 );
}

void WxcBackTrace(  )
{
    int     i;
    void   *array[25];
    int     nSize = backtrace ( array, 25 );
    char  **symbols = backtrace_symbols ( array, nSize );

    for ( i = 0; i < nSize; i++ )
    {
        printf ( "%s \n", symbols[i] );
    }
    free ( symbols );
}

/*@end@*/

