Преглед на файлове

Moved debug init code and changed windows debug 'break' to use an event

Mark Sibly преди 9 години
родител
ревизия
a9360fdf31
променени са 2 файла, в които са добавени 44 реда и са изтрити 111 реда
  1. 43 16
      modules/monkey/native/bbdebug.cpp
  2. 1 95
      modules/monkey/native/bbmonkey.cpp

+ 43 - 16
modules/monkey/native/bbdebug.cpp

@@ -4,6 +4,7 @@
 
 #if _WIN32
 #include <windows.h>
+#include <thread>
 #else
 #include <signal.h>
 #endif
@@ -16,31 +17,57 @@ namespace bbDB{
 	
 	bbDBContext *currentContext;
 	
-#if _WIN32
-	BOOL WINAPI stopHandler( DWORD dwCtrlType ){
-		if( dwCtrlType==CTRL_BREAK_EVENT ){
-//			printf( "CTRL_BREAK_EVENT\n" );fflush( stdout );
-			currentContext->stopped=0;
-			return TRUE;
-		}
-		return FALSE;
-	}
-#else
-	void sighandler( int sig ){
-//		printf( "SIGTSTP\n" );fflush( stdout );
-		currentContext->stopped=0;
+#if !_WIN32
+	void breakHandler( int sig ){
+		currentContext->stopped=0x10000000;
 	}
 #endif
+
+	void sighandler( int sig  ){
+	
+		const char *err="Unknown signal";
+		switch( sig ){
+		case SIGSEGV:err="Memory access violation";break;
+		case SIGILL:err="Illegal instruction";
+		case SIGFPE:err="Floating point exception";
+	#if !_WIN32
+		case SIGBUS:err="Bus error";
+	#endif	
+		}
+				
+#ifndef NDEBUG
+		error( err );
+		exit( 0 );
+#endif
+		printf( "Caught signal:%s\n",err );
+		exit( -1 );
+	}
 	
 	void init(){
 	
 		currentContext=new bbDBContext;
 		currentContext->init();
 		
+		signal( SIGSEGV,sighandler );
+		signal( SIGILL,sighandler );
+		signal( SIGFPE,sighandler );
+
 #if _WIN32
-		SetConsoleCtrlHandler( stopHandler,TRUE );
+
+		if( HANDLE breakEvent=OpenEvent( EVENT_ALL_ACCESS,false,"MX2_BREAK_EVENT" ) ){
+//			printf( "Found BREAK_EVENT!\n" );fflush( stdout );
+		    std::thread( [=](){
+		    	for( ;; ){
+		    		WaitForSingleObject( breakEvent,INFINITE );
+//	    			printf( "Break event!\n" );fflush( stdout );
+		    		currentContext->stopped=0x10000000;
+		    	}
+		    } ).detach();
+		}
+	
 #else		
-		signal( SIGTSTP,sighandler );
+		signal( SIGBUS,sighandler );
+		signal( SIGTSTP,breakHandler );
 #endif
 	}
 	
@@ -57,7 +84,7 @@ namespace bbDB{
 		
 		for( bbDBFrame *f=currentContext->frames;f;f=f->succ ){
 
-			printf( ">%s;%s;%i;%i\n",f->decl,f->srcFile,f->srcPos,f->seq );
+			printf( ">%s;%s;%i;%i\n",f->decl,f->srcFile,f->srcPos>>12,f->seq );
 			
 			for( bbDBVar *v=f->locals;v!=ev;++v ){
 				emitVar( v );

+ 1 - 95
modules/monkey/native/bbmonkey.cpp

@@ -1,78 +1,6 @@
 
-#include <signal.h>
-
-#if _WIN32
-
-#include <windows.h>
-
-#elif __APPLE__
-
-#include <execinfo.h>
-#include <dlfcn.h>
-#include <cxxabi.h>
-
-#endif
-
 #include "bbmonkey.h"
 
-namespace{
-
-	void sighandler( int sig  ){
-	
-		const char *err="Unknown signal";
-		switch( sig ){
-		case SIGSEGV:err="Memory access violation";break;
-		case SIGILL:err="Illegal instruction";
-		case SIGFPE:err="Floating point exception";
-	#if !_WIN32
-		case SIGBUS:err="Bus error";
-	#endif	
-		}
-				
-#ifndef NDEBUG
-		bbDB::error( err );
-		exit( 0 );
-#endif
-		printf( "Caught signal:%s\n",err );
-		exit( -1 );
-		
-#if __APPLE__
-
-		printf( "Stack trace:\n" );	
-		
-		void *stack[128];
-
-		int frames=backtrace( stack,128 );
-		
-		for( int i=0;i<frames;++i ){
-		
-			Dl_info info{};
-			
-			if( dladdr( stack[i],&info ) ){
-			
-				if( info.dli_sname ){
-				
-					char buf[1024];
-					size_t length=1024;
-					int status=0;
-					
-					const char *str=abi::__cxa_demangle( info.dli_sname,buf,&length,&status );
-					
-					if( str ){
-						printf( "%s\n",str );
-					}else{
-						printf( "%s\n",info.dli_sname );
-					}
-				}
-			}
-		}
-#endif
-
-		fflush( stdout );
-		exit( -1 );
-	}
-}
-
 int bb_argc;
 char **bb_argv;
 
@@ -83,17 +11,6 @@ int main( int argc,char **argv ){
 	bb_argc=argc;
 	bb_argv=argv;
 	
-	signal( SIGSEGV,sighandler );
-	signal( SIGILL,sighandler );
-	signal( SIGFPE,sighandler );
-
-#if !_WIN32
-	signal( SIGBUS,sighandler );
-#endif
-
-//	printf( "bbMain() : sizeof(bbBool)=%i sizeof(bbByte)=%i sizeof(bbShort)=%i sizeof(bbInt)=%i, sizeof(bbLong)=%i, sizeof(bbChar)=%i sizeof(void*)=%i, sizeof(size_t)=%i\n",(int)sizeof(bbBool),(int)sizeof(bbByte),(int)sizeof(bbShort),(int)sizeof(bbInt),(int)sizeof(bbLong),(int)sizeof(bbChar),(int)sizeof(void*),(int)sizeof(size_t) );
-//	fflush( stdout );
-
 	try{
 	
 		bbGC::init();
@@ -104,23 +21,12 @@ int main( int argc,char **argv ){
 			bbDBFrame( "_void()","" );
 			
 			for( bbInit *init=bbInit::first;init;init=init->succ ){
-	//			printf( "Executing initializer '%s'\n",init->info );fflush( stdout );
 				init->init();
 			}
 		}
 		
 		bbMain();
 	
-/*		
-	}catch( bbException *ex ){
-	
-		printf( "\n***** Uncaught Monkey 2 Exception: %s *****\n\n",ex->message().c_str() );
-		
-		for( int i=0;i<ex->debugStack()->length();++i ){
-			printf( "%s\n",ex->debugStack()->at( i ).c_str() );
-		}
-*/
-
 	}catch( bbThrowable *t ){
 	
 		printf( "\n***** Uncaught Monkey 2 Throwable *****\n\n" );
@@ -128,7 +34,7 @@ int main( int argc,char **argv ){
 	}catch(...){
 	
 		printf( "***** Uncaught Native Exception *****\n" );fflush( stdout );
-//		throw;
+		throw;
 	}
 	
 	return 0;