Browse Source

Dynamic breakpoint enhancements.

Brucey 5 years ago
parent
commit
c4aa1d2fd7
2 changed files with 69 additions and 65 deletions
  1. 49 0
      appstub.mod/debugger.glue.c
  2. 20 65
      appstub.mod/debugger.tcp.bmx

+ 49 - 0
appstub.mod/debugger.glue.c

@@ -179,3 +179,52 @@ void * bmx_debugger_ref_brl_blitz_NullFunctionError() {
 int bmx_snprintf(char * txt, size_t size, size_t num) {
 	return snprintf(txt, size, "%7d", num);
 }
+
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+int bmx_debugger_AddBreakpoint(BBString * filename, int line) {
+	BBSource * src = bbSourceForName(filename);
+	if (src) {
+		for (int i = 0; i < src->count; i++) {
+			if (line == src->lines[i]) {
+				return 0;
+			}
+		}
+		src->lines[src->count++] = line;
+		return 1;
+	}
+	
+	return 0;
+}
+
+int bmx_debugger_RemoveBreakpoint(BBString * filename, int line) {
+	BBSource * src = bbSourceForName(filename);
+	if (src) {
+		for (int i = 0; i < src->count; i++) {
+			if (line == src->lines[i]) {
+				for (int n = i; n < src->count; n++) {
+					src->lines[n] = src->lines[n+1];
+				}
+				src->count--;
+				return 1;
+			}
+		}
+	}
+	
+	return 0;
+}
+
+int bmx_debugger_DebugBreakOnLine(struct BBDebugStm * stmt) {
+	BBSource * src = bbSourceForId(stmt->id);
+	int count = src->count;
+	if (count > 0) {
+		for (int i = 0; i < count; i++) {
+			if (stmt->line_num == src->lines[i]) {
+				return 1;
+			}
+		}
+	}
+	
+	return 0;
+}

+ 20 - 65
appstub.mod/debugger.tcp.bmx

@@ -5,7 +5,6 @@ Import "debugger.glue.c"
 NoDebug
 
 Import BRL.Socket
-Import BRL.Map
 Import pub.stdc
 
 ?win32
@@ -73,6 +72,7 @@ Extern
 	Function DebugStmFile:String( stm:Int Ptr )="bmx_debugger_DebugStmFile"
 	Function DebugStmLine:Int( stm:Int Ptr )="bmx_debugger_DebugStmLine"
 	Function DebugStmChar:Int( stm:Int Ptr )="bmx_debugger_DebugStmChar"
+	Function DebugBreakOnLine:Int( stm:Int Ptr )="bmx_debugger_DebugBreakOnLine"
 
 	Function bmx_debugger_ref_bbNullObject:Byte Ptr()
 	Function bmx_debugger_ref_bbEmptyArray:Byte Ptr()
@@ -82,6 +82,9 @@ Extern
 	Function bbObjectStructInfo:Byte Ptr(name:Byte Ptr)="BBDebugScope * bbObjectStructInfo( char * )!"
 	Function bmx_debugger_DebugEnumDeclValue:String(decl:Byte Ptr, val:Byte Ptr)
 	
+	Function bmx_debugger_AddBreakpoint:Int(filename:String, line:Int)
+	Function bmx_debugger_RemoveBreakpoint:Int(filename:String, line:Int)
+	
 	Function bmx_snprintf:Int(buf:Byte Ptr, size:Size_T, num:Size_T)
 End Extern
 
@@ -603,7 +606,6 @@ Function bbThreadGetData:TDbgState( index:Int )="BBObject* bbThreadGetData(int )
 End Extern
 ?
 
-Global _breakpointsMap:TMap = New TMap
 Global _bpCount:Int
 Global _debugPort:Int = 31666
 Global _debugWait:Int = True
@@ -1101,20 +1103,13 @@ Function OnDebugEnterStm( stm:Int Ptr )
 					'   b<FILENAME@line>
 					Local off:Int = s.find("@")
 					If off >= 1 Then
+					
 						Local file:String = s[2..off]
-						Local line:TDdebugLine = New TDdebugLine
-						line.line = s[off + 1..s.length - 2].ToInt()
-						
-						Local list:TDdebugLine[] = TDdebugLine[](_breakpointsMap.ValueForKey(file))
-						
-						If Not list Then
-							list = New TDdebugLine[0]
+						Local line:Int = s[off + 1..s.length - 2].ToInt()
+					
+						If bmx_debugger_AddBreakpoint(file, line) Then
+							_bpCount :+ 1
 						End If
-						
-						list :+ [line]
-						
-						_breakpointsMap.Insert(file, list)
-						_bpCount :+ 1
 					End If
 				Else If s[..1].ToLower() = "z" Then
 					' format 
@@ -1123,34 +1118,9 @@ Function OnDebugEnterStm( stm:Int Ptr )
 					If off >= 1 Then
 						Local file:String = s[2..off]
 						Local line:Int = s[off + 1..s.length - 2].ToInt()
-						
-						Local list:TDdebugLine[] = TDdebugLine[](_breakpointsMap.ValueForKey(file))
-						
-						If list Then
-							For Local i:Int = 0 Until list.length
-								If list[i].line = line Then
-									If list.length = 1
-										_breakpointsMap.Remove(file)
-									Else 
-										If i = 0 Then
-											list = list[i + 1..] 
-										Else If i = list.length - 1 Then
-											list = list[..i] 
-										Else
-											list = list[..i] + list[i + 1..]
-										End If
-										
-										_breakpointsMap.Insert(file, list)
-										
-									End If
-									
-									_bpCount :- 1
-
-									Exit
-
-								End If
-							Next
 
+						If bmx_debugger_RemoveBreakpoint(file, line) Then
+							_bpCount :- 1
 						End If
 					End If
 				End If
@@ -1165,27 +1135,16 @@ Function OnDebugEnterStm( stm:Int Ptr )
 			Else If _bpCount Then
 			
 				' breakpoints have been defined
-				Local file:String = DebugStmFile(stm)
-				
-				Local list:TDdebugLine[] = TDdebugLine[](_breakpointsMap.ValueForKey(file))
-				
-				If list Then
-					Local line:Int = DebugStmLine(stm)
+				If DebugBreakOnLine(stm) Then
+					' enter debugging mode!
+					OnDebugStop()
 					
-					For Local i:Int = 0 Until list.length
-						If list[i].line = line Then
-							' enter debugging mode!
-							OnDebugStop()
-							
-							' done debugging. If we are still in BREAK mode, return to Running mode
-							If dbgState.Mode = MODE_BREAK Then
-								dbgState.Mode = MODE_RUN
-							End If
-							
-							Return
-						End If
-					Next
-				
+					' done debugging. If we are still in BREAK mode, return to Running mode
+					If dbgState.Mode = MODE_BREAK Then
+						dbgState.Mode = MODE_RUN
+					End If
+					
+					Return				
 				End If		
 
 				' carry on as before
@@ -1306,10 +1265,6 @@ Function OnDebugUnhandledEx( ex:Object )
 	GCResume	
 End Function
 
-Type TDdebugLine
-	Field line:Int
-End Type
-
 Type TDebugData
 	Field length:Int = 8
 	Field data:Byte[1024]