Browse Source

Debugging improvements.

Mark Sibly 8 years ago
parent
commit
83b9f32b12
3 changed files with 41 additions and 34 deletions
  1. 10 1
      modules/monkey/native/bbarray.h
  2. 13 12
      modules/monkey/native/bbdebug.cpp
  3. 18 21
      modules/monkey/native/bbdebug.h

+ 10 - 1
modules/monkey/native/bbarray.h

@@ -34,6 +34,15 @@ template<class T,int D> struct bbArray{
 		virtual void gcMark(){
 			for( int i=0;i<_sizes[D-1];++i ) bbGCMark( _data[i] );
 		}
+		
+		virtual void dbEmit(){
+			int n=_sizes[D-1];if( n>100 ) n=100;
+			for( int i=0;i<n;++i ){
+				char buf[16];
+				sprintf( buf,"[%i]",i );
+				bbDBEmit( buf,&_data[i] );
+			}
+		}
 	};
 	
 	Rep *_rep=nullptr;
@@ -219,7 +228,7 @@ template<class T,int D> bbString bbDBType( bbArray<T,D> *p ){
 template<class T,int D> bbString bbDBValue( bbArray<T,D> *p ){
 	char buf[64];
 	sprintf( buf,"@%p",*(void**)(&p->_rep) );
-	return buf;
+	return bbString( buf )+"["+bbString( p->length() )+"]";
 }
 
 template<class T,int D> void bbGCMark( bbArray<T,D> arr ){

+ 13 - 12
modules/monkey/native/bbdebug.cpp

@@ -20,7 +20,8 @@ namespace bbDB{
 	
 #if !_WIN32
 	void breakHandler( int sig ){
-		currentContext->stopped=0x10000000;
+	
+		currentContext->stopped=1;
 	}
 #endif
 
@@ -65,7 +66,7 @@ namespace bbDB{
 		    	for( ;; ){
 		    		WaitForSingleObject( breakEvent,INFINITE );
 //	    			bb_printf( "Break event!\n" );fflush( stdout );
-		    		currentContext->stopped=0x10000000;
+					currentContext->stopped=1;
 		    	}
 		    } ).detach();
 		}
@@ -74,8 +75,7 @@ namespace bbDB{
 #endif
 
 #endif
-
-	}
+}
 	
 	void emitVar( bbDBVar *v ){
 		bbString id=v->name;
@@ -101,8 +101,9 @@ namespace bbDB{
 	}
 	
 	void stop(){
-
-		currentContext->stopped=0;
+		stopped();
+//		stepMode=0;
+//		stepnext=1;
 	}
 	
 	void emit( const char *e ){
@@ -120,7 +121,7 @@ namespace bbDB{
 	}
 	
 	void stopped(){
-
+	
 		bb_printf( "{{!DEBUG!}}\n" );
 		
 		emitStack();
@@ -135,10 +136,10 @@ namespace bbDB{
 			if( !e ) exit( -1 );
 			
 			switch( e[0] ){
-			case 's':currentContext->stopped=0;return;
-			case 'e':currentContext->stopped=1;return;
-			case 'l':currentContext->stopped=-1;return;
-			case 'r':currentContext->stopped=-0x10000000;return;
+			case 'r':currentContext->stopped=0;currentContext->stepMode=0;return;
+			case 'e':currentContext->stopped=1;currentContext->stepMode=0;return;
+			case 's':currentContext->stopped=1;currentContext->stepMode='s';return;
+			case 'l':currentContext->stopped=0;currentContext->stepMode='l';return;
 			case '@':emit( e+1 );continue;
 			case 'q':exit( 0 );return;
 			}
@@ -150,8 +151,8 @@ namespace bbDB{
 	void error( bbString msg ){
 		
 		bb_printf( "\n%s\n",msg.c_str() );
+		
 		stopped();
-
 	}
 	
 	bbArray<bbString> stack(){

+ 18 - 21
modules/monkey/native/bbdebug.h

@@ -79,6 +79,7 @@ struct bbDBContext{
 	bbDBFrame *frames=nullptr;
 	bbDBVar *localsBuf=nullptr;
 	bbDBVar *locals=nullptr;
+	int stepMode;
 	int stopped;
 
 	~bbDBContext();
@@ -105,49 +106,45 @@ namespace bbDB{
 	void emitStack();
 }
 
-struct bbDBFrame{
-	bbDBFrame *succ;
+struct bbDBBlock{
 	bbDBVar *locals;
+	bbDBBlock():locals( bbDB::currentContext->locals ){
+		if( bbDB::currentContext->stepMode=='l' ) --bbDB::currentContext->stopped;
+	}
+	~bbDBBlock(){
+		if( bbDB::currentContext->stepMode=='l' ) ++bbDB::currentContext->stopped;
+		bbDB::currentContext->locals=locals;
+	}
+};
+
+struct bbDBFrame : public bbDBBlock{
+	bbDBFrame *succ;
 	const char *decl;
 	const char *srcFile;
 	int srcPos;
 	int seq;
 	
-	bbDBFrame( const char *decl,const char *srcFile ):succ( bbDB::currentContext->frames ),locals( bbDB::currentContext->locals ),decl( decl ),srcFile( srcFile ){
+	bbDBFrame( const char *decl,const char *srcFile ):succ( bbDB::currentContext->frames ),decl( decl ),srcFile( srcFile ),seq( ++bbDB::nextSeq ){
 		bbDB::currentContext->frames=this;
-		--bbDB::currentContext->stopped;
-		seq=++bbDB::nextSeq;
+		if( bbDB::currentContext->stepMode=='s' ) --bbDB::currentContext->stopped;
 	}
 	
 	~bbDBFrame(){
-		++bbDB::nextSeq;
-		++bbDB::currentContext->stopped;
-		bbDB::currentContext->locals=locals;
+		if( bbDB::currentContext->stepMode=='s' ) ++bbDB::currentContext->stopped;
 		bbDB::currentContext->frames=succ;
 	}
 };
 
-struct bbDBBlock{
-	bbDBVar *locals;
-	bbDBBlock():locals( bbDB::currentContext->locals ){
-	}
-	~bbDBBlock(){
-		bbDB::currentContext->locals=locals;
-	}
-};
-
 struct bbDBLoop : public bbDBBlock{
 	bbDBLoop(){
-		--bbDB::currentContext->stopped;
 	}
 	~bbDBLoop(){
-		++bbDB::currentContext->stopped;
 	}
 };
 
 inline void bbDBStmt( int srcPos ){
 	bbDB::currentContext->frames->srcPos=srcPos;
-	if( bbDB::currentContext->stopped>=0 ) bbDB::stopped();
+	if( bbDB::currentContext->stopped>0 ) bbDB::stopped();
 }
 
 template<class T> void bbDBEmit( const char *name,T *var ){
@@ -159,7 +156,7 @@ template<class T> void bbDBEmit( const char *name,bbGCVar<T> *p ){
 	T *var=p->get();return bbDBEmit( name,&var );
 }
 
-template<class T> void bbDBLocal ( const char *name,T *var ){
+template<class T> void bbDBLocal( const char *name,T *var ){
 	bbDB::currentContext->locals->name=name;
 	bbDB::currentContext->locals->type=&bbDBVarType_t<T>::info;
 	bbDB::currentContext->locals->var=var;