Ver Fonte

Add source-code based breakpoints

Hugh Sanderson há 13 anos atrás
pai
commit
bb23098ef8
2 ficheiros alterados com 95 adições e 24 exclusões
  1. 90 17
      std/cpp/vm/DebugStdio.hx
  2. 5 7
      std/cpp/vm/Debugger.hx

+ 90 - 17
std/cpp/vm/DebugStdio.hx

@@ -6,10 +6,12 @@ class DebugStdio
    var inDebugger:Bool;
    var inputThread:Thread;
    var debugQueue:Deque<Dynamic>;
+   var files:Array<String>;
    
 
    public function new()
    {
+		files = Debugger.getFiles();
       inDebugger = false;
       Debugger.setHandler(onDebug);
       debugQueue= new Deque<Dynamic>();
@@ -18,6 +20,7 @@ class DebugStdio
 
    function onDebug()
    {
+      Sys.println("stopped.");
       inDebugger = true;
       while(inDebugger)
       {
@@ -51,6 +54,42 @@ class DebugStdio
       Sys.println("Frame " + inI + " : " + result );
    }
 
+   function showFiles()
+   {
+ 		if (files!=null)
+			for(idx in 0...files.length)
+            Sys.println("file " + idx + " : " + files[idx] );
+   }
+
+   function showBreakpoints()
+   {
+      var bps = Debugger.getBreakpoints();
+ 		if (bps!=null)
+			for(idx in 0...bps.length)
+            Sys.println("breakpoint " + idx + " : " + bps[idx] );
+   }
+
+
+   function addBreakpoint(inFile:String, inLine:String)
+	{
+		var id = Std.parseInt(inFile);
+		if (id==null)
+		{
+			for(idx in 0...files.length)
+				if (files[idx]==inFile)
+				{
+					id = idx;
+					break;
+				}
+		}
+
+ 		if (id==null)
+         Sys.println("Could not find file for " + inFile );
+		else
+			Debugger.addBreakpoint(id,Std.parseInt(inLine));
+			
+	}
+
 
    function inputLoop()
    {
@@ -60,27 +99,40 @@ class DebugStdio
          Sys.print("debug >");
          var command = input.readLine();
          var words = command.split(" ");
-         if (words.length>0) switch(words[0])
+         switch(words[0])
          {
-            case "exit":
-               Debugger.exit();
+            case "":
+               // Do nothing
 
-            case "break":
-               if (inDebugger)
-                  Sys.println("already stopped.");
-               else
-               {
-                  Debugger.setBreak(Debugger.BRK_ASAP,inputThread);
-                  waitDebugger();
-               }
+            case "exit","quit":
+               Debugger.exit();
 
-            case "cont":
+            case "break","b":
+					if (words.length==1)
+					{
+               	if (inDebugger)
+                  	Sys.println("already stopped.");
+               	else
+               	{
+                  	Debugger.setBreak(Debugger.BRK_ASAP,inputThread);
+                  	waitDebugger();
+               	}
+					}
+					else if (words.length==3)
+					{
+						addBreakpoint(words[1],words[2]);
+					}
+					else
+						Sys.println("Usage: break [file line] - pause execution of one thread [when at certain point]");
+
+
+            case "cont","c":
                if (!inDebugger)
                   Sys.println("Already running.");
                else
                   debugQueue.add( function() inDebugger = false );
 
-            case "vars":
+            case "vars","v":
                if (!inDebugger)
                   Sys.println("Must break first.");
                else
@@ -91,7 +143,7 @@ class DebugStdio
                }
               
 
-            case "where":
+            case "where","w":
                if (!inDebugger)
                   Sys.println("Must break first.");
                else
@@ -100,16 +152,37 @@ class DebugStdio
                   waitDebugger();
                }
 
-            case "help":
+            case "files","f":
+               showFiles();
+
+            case "breakpoints","bp":
+               showBreakpoints();
+
+            case "delete","d":
+               if (words[1]==null)
+					{
+						Sys.println("Usage : delete N");
+ 					}
+					else
+					{
+                  var i = Std.parseInt(words[1]);
+						Debugger.deleteBreakpoint(i);
+					}
+
+            case "help","h","?":
                Sys.println("help  - print this message");
-               Sys.println("break - pause execution of one thread");
+               Sys.println("break [file line] - pause execution of one thread [when at certain point]");
+               Sys.println("breakpoints - list breakpoints");
+               Sys.println("delete N - delete breakpoint N");
                Sys.println("cont  - continue execution");
                Sys.println("where - print call stack");
+               Sys.println("files - print file list that may be used with breakpoints");
                Sys.println("vars N - print local vars for frame N");
                Sys.println("exit  - exit programme");
 
+
             default:
-               Sys.println("Unknown command:" + command);
+               Sys.println("Unknown command:" + words);
          }
       }
    }

+ 5 - 7
std/cpp/vm/Debugger.hx

@@ -1,8 +1,6 @@
 package cpp.vm;
 
-// TODO: implement this
-typedef Breakpoint = Dynamic;
-typedef StackFrame = Dynamic;
+import haxe.Stack;
 
 class Debugger
 {
@@ -31,12 +29,12 @@ class Debugger
    }
 
    // Breakpoint
-   public static function addBreakpoint(inBreakpoint:Breakpoint)
+   public static function addBreakpoint(inFileId:Int, inLine:Int)
    {
-      untyped __global__.__hxcpp_breakpoints_add(inBreakpoint);
+      untyped __global__.__hxcpp_breakpoints_add(inFileId, inLine);
    }
 
-   public static function getBreakpoints() : Array<Breakpoint>
+   public static function getBreakpoints() : Array<String>
    {
       return untyped __global__.__hxcpp_dbg_breakpoints_get();
    }
@@ -50,7 +48,7 @@ class Debugger
    // public static function suspendAll()
 
    // Callstack
-   public static function getStackFrames() : Array<StackFrame>
+   public static function getStackFrames() : Array<haxe.StackItem>
    {
       return untyped __global__.__hxcpp_dbg_stack_frames_get();
    }