Example #1
0
void BaseFilter ( LPEXCEPTION_POINTERS info )
{
	FILE* outfile = OpenStackFile ();

	FILE* out;
	if( outfile == nullptr )
	{
		out = stderr;
	}
	else
	{
		out = outfile;
	}

	fprintf ( out, "Caught Unhandled Exception code %X :\nFlags : %X\nAddress : %X\n", 
			  info->ExceptionRecord->ExceptionCode,
			  info->ExceptionRecord->ExceptionFlags,
			  info->ExceptionRecord->ExceptionAddress );

	StackWalker_OutFile sw ( out );
	sw.ShowCallstack (GetCurrentThread(), info->ContextRecord);

	if( outfile )
		fclose ( outfile );
}
Example #2
0
void abortHandler ( int signum )
{
#ifdef GNUC
	FILE* outfile = OpenStackFile ();

	FILE* out;
	if( outfile == nullptr )
	{
		printf( "Unable to open !stacktrace.txt\n" );
		out = stdout;
	}
	else
	{
		out = outfile;
	}

	// associate each signal with a signal name string.
	const char* name = NULL;
	switch( signum )
	{
		case SIGABRT: name = "SIGABRT";  break;
		case SIGSEGV: name = "SIGSEGV";  break;
		case SIGBUS:  name = "SIGBUS";   break;
		case SIGILL:  name = "SIGILL";   break;
		case SIGFPE:  name = "SIGFPE";   break;
		default:  name = "Unknown signum"; break;
	}

	// Notify the user which signal was caught. We use printf, because this is the 
	// most basic output function. Once you get a crash, it is possible that more 
	// complex output systems like streams and the like may be corrupted. So we 
	// make the most basic call possible to the lowest level, most 
	// standard print function.
	if( name )
		fprintf ( out, "Caught signal %d (%s)\n\n", signum, name );
	else
		fprintf ( out, "Caught signal %d\n\n", signum );

	// Dump a stack trace.
	// This is the function we will be implementing next.
	printStackTrace ( out );

	// If you caught one of the above signals, it is likely you just 
	// want to quit your program right now.

	if( outfile )
		fclose ( outfile );

	exit(signum);
#else
	throw signum; // Just use C++ UnhandledException filters on windows.
				 // This allows us to get current thread context without
				 // the need to use assembly code.
#endif
}
Example #3
0
void BaseFilter ( LPEXCEPTION_POINTERS info )
{
	FILE* outfile = OpenStackFile ();

	FILE* out;
	if( outfile == nullptr )
	{
		out = stderr;
	}
	else
	{
		out = outfile;
	}

	fprintf ( out,  "Caught Unhandled Exception code 0x%X :\n"
					"Flags : 0x%X\n"
					"Address : 0x%X\n"
					"Dr0 : 0x%X, Dr1 : 0x%X, Dr2 : 0x%X, Dr3 : 0x%X, Dr6 : 0x%X, Dr7 : 0x%X\n"
					"eax : 0x%X, ebp : 0x%X, ecx : 0x%X, edi : 0x%X\n"
					"edx : 0x%X, eip : 0x%X, esi : 0x%X, esp : 0x%X\n",
			  info->ExceptionRecord->ExceptionCode,
			  info->ExceptionRecord->ExceptionFlags,
			  (DWORD)info->ExceptionRecord->ExceptionAddress,
				info->ContextRecord->Dr0,
				info->ContextRecord->Dr1,
				info->ContextRecord->Dr2,
				info->ContextRecord->Dr3,
				info->ContextRecord->Dr6,
				info->ContextRecord->Dr7,
				info->ContextRecord ->Eax,
				info->ContextRecord ->Ebp,
				info->ContextRecord ->Ecx,
				info->ContextRecord ->Edi,
				info->ContextRecord ->Edx,
				info->ContextRecord ->Eip,
				info->ContextRecord ->Esi,
				info->ContextRecord ->Esp
		);

	StackWalker_OutFile sw ( out );
	sw.ShowCallstack (GetCurrentThread(), info->ContextRecord);

	if( outfile )
		fclose ( outfile );
}