示例#1
0
 void Dump( String & s, char const * buf, int len )
 {
     if( len == 0 ) return;
     s.Append( "\n--------  0  1  2  3 | 4  5  6  7 | 8  9  A  B | C  D  E  F" );
     int i = 0;
     for( ; i < len; ++i )
     {
         if( ( i % 16 ) == 0 )
         {
             if( i )
             {           // output ascii to the end of the line
                 s.Append( "  " );
                 DumpCore( s, buf + i - 16, 16 );
             }
             s.Append( '\n' );
             s.AppendHex( i );
             s.Append( "  " );
         }
         else if( i && ( i % 4 == 0 ) )
         {
             s.Append( "  " );
         }
         else s.Append( ' ' );
         s.AppendHex( (uint8)buf[ i ] );
     }
     int left = i % 16;
     if( left == 0 ) left = 16;
     if( left )
     {
         len = len + 16 - left;
         for( ; i < len; ++i )
         {
             if( i && ( i % 4 == 0 ) )
                 s.Append( "  " );
             else s.Append( ' ' );
             s.Append( "  " );
         }
         s.Append( "  " );
         DumpCore( s, buf + i - 16, left );
     }
 }
示例#2
0
文件: niceabort.c 项目: bentley/magic
void
niceabort()
{
    static int timesCalled = 0;

    timesCalled++;
    TxPrintf("-------------------- Error #%d\n", timesCalled);
    if (timesCalled > 10) 
    {
	TxPrintf("\nAbort called more than 10 times -- things are really hosed!\n");
	TxPrintf("Recommendation:\n");
	TxPrintf("  1) Copy all your files to another directory.\n");
	TxPrintf("  2) Send magic a SIGTERM signal and it will ATTEMPT to write out your files.\n");
	TxPrintf("     (It might trash them, though.)\n");
	TxPrintf("Magic going to sleep now for 10 hours -- please kill me.\n");
	sleep(3600);  
    }

    TxPrintf("Magic has encountered a major internal inconsistency:\n\n");
    TxPrintf("     %s\n", AbortMessage);

#ifdef FANCY_ABORT
    /* If mainDebug is set, dbx is presumably being used, so don't generate
     * core dump or ask for comment,
     */
    if (timesCalled == 1) {
	if(mainDebug)
	{
	    TxPrintf("-D is set, so magic won't dump core.\n");
	    return;
	}
	DumpCore();
    }
#endif

    if (AbortFatal) {
	TxPrintf("Magic can't recover from this error.  Goodbye.\n\n");
    } else {
	TxPrintf("It will try to recover, but you should save all your\n");
	TxPrintf("files as soon as possible and quit magic.\n\n");
    }
    TxPrintf("--------------------\n");

}