Browse Source

debugger wip

Xanathar 11 years ago
parent
commit
0198fd8259
44 changed files with 1691 additions and 283 deletions
  1. 478 22
      src/MoonSharp.Debugger/MainForm.Designer.cs
  2. 144 2
      src/MoonSharp.Debugger/MainForm.cs
  3. 72 16
      src/MoonSharp.Debugger/MainForm.resx
  4. 55 0
      src/MoonSharp.Debugger/MoonSharp.Debugger.csproj
  5. 202 60
      src/MoonSharp.Debugger/Properties/Resources.Designer.cs
  6. 53 3
      src/MoonSharp.Debugger/Properties/Resources.resx
  7. BIN
      src/MoonSharp.Debugger/Resources/AddConnection_477.png
  8. BIN
      src/MoonSharp.Debugger/Resources/AddMark_10580.png
  9. BIN
      src/MoonSharp.Debugger/Resources/Breakall_6323.png
  10. BIN
      src/MoonSharp.Debugger/Resources/BreakpointEnabled_6584_16x.png
  11. BIN
      src/MoonSharp.Debugger/Resources/Clearallrequests_8816.png
  12. BIN
      src/MoonSharp.Debugger/Resources/DisassemblyWindow_6536.png
  13. BIN
      src/MoonSharp.Debugger/Resources/FindSymbol_6263.png
  14. BIN
      src/MoonSharp.Debugger/Resources/Help_6522.png
  15. BIN
      src/MoonSharp.Debugger/Resources/Open_6529.png
  16. BIN
      src/MoonSharp.Debugger/Resources/RPCThread_10388.png
  17. BIN
      src/MoonSharp.Debugger/Resources/Restart_6322.png
  18. BIN
      src/MoonSharp.Debugger/Resources/StepIn_6326.png
  19. BIN
      src/MoonSharp.Debugger/Resources/StepOver_6328.png
  20. BIN
      src/MoonSharp.Debugger/Resources/Stepout_6327.png
  21. BIN
      src/MoonSharp.Debugger/Resources/startwithoutdebugging_6556.png
  22. 21 4
      src/MoonSharp.Debugger/SourceCodeDebugControl.cs
  23. 102 0
      src/MoonSharp.Debugger/WatchInputDialog.Designer.cs
  24. 32 0
      src/MoonSharp.Debugger/WatchInputDialog.cs
  25. 120 0
      src/MoonSharp.Debugger/WatchInputDialog.resx
  26. 28 0
      src/MoonSharp.Interpreter/Debugging/DebuggerAction.cs
  27. 2 0
      src/MoonSharp.Interpreter/Debugging/IDebugger.cs
  28. 18 0
      src/MoonSharp.Interpreter/Debugging/WatchItem.cs
  29. 15 0
      src/MoonSharp.Interpreter/Debugging/WatchType.cs
  30. 5 5
      src/MoonSharp.Interpreter/Execution/DataTypes/Closure.cs
  31. 6 0
      src/MoonSharp.Interpreter/Execution/DataTypes/Table.cs
  32. 23 0
      src/MoonSharp.Interpreter/Execution/Scopes/ClosureContext.cs
  33. 29 7
      src/MoonSharp.Interpreter/Execution/Scopes/RuntimeScope.cs
  34. 3 2
      src/MoonSharp.Interpreter/Execution/VM/CallStackItem.cs
  35. 4 0
      src/MoonSharp.Interpreter/Execution/VM/Chunk.cs
  36. 2 0
      src/MoonSharp.Interpreter/Execution/VM/Instruction.cs
  37. 2 1
      src/MoonSharp.Interpreter/Execution/VM/OpCode.cs
  38. 42 0
      src/MoonSharp.Interpreter/Execution/VM/Processor/Processor.cs
  39. 144 0
      src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_Debugger.cs
  40. 9 152
      src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_InstructionLoop.cs
  41. 58 0
      src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_UtilityFunctions.cs
  42. 9 1
      src/MoonSharp.Interpreter/MoonSharp.Interpreter.csproj
  43. 4 6
      src/MoonSharp.Interpreter/Tree/Expressions/FunctionDefinitionExpression.cs
  44. 9 2
      src/MoonSharp.Interpreter/Tree/Statements/FunctionDefinitionStatement.cs

+ 478 - 22
src/MoonSharp.Debugger/MainForm.Designer.cs

@@ -28,10 +28,12 @@
 		/// </summary>
 		private void InitializeComponent()
 		{
+			this.components = new System.ComponentModel.Container();
 			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
 			this.menuStrip1 = new System.Windows.Forms.MenuStrip();
 			this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+			this.connectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
 			this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -40,7 +42,6 @@
 			this.debugToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.stepOverToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.stepInToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
-			this.stepOutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
 			this.toggleBreakpointToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator();
@@ -48,17 +49,64 @@
 			this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.toolStrip1 = new System.Windows.Forms.ToolStrip();
+			this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
+			this.toolStripButton2 = new System.Windows.Forms.ToolStripButton();
+			this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
+			this.toolStripButton3 = new System.Windows.Forms.ToolStripButton();
+			this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
+			this.toolStripButton6 = new System.Windows.Forms.ToolStripButton();
+			this.toolStripButton4 = new System.Windows.Forms.ToolStripButton();
+			this.toolStepIN = new System.Windows.Forms.ToolStripButton();
+			this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
+			this.toolStripButton5 = new System.Windows.Forms.ToolStripButton();
 			this.statusStrip1 = new System.Windows.Forms.StatusStrip();
 			this.splitContainer1 = new System.Windows.Forms.SplitContainer();
 			this.splitContainer2 = new System.Windows.Forms.SplitContainer();
+			this.tabControl2 = new System.Windows.Forms.TabControl();
+			this.tabPage3 = new System.Windows.Forms.TabPage();
+			this.lvWatches = new System.Windows.Forms.ListView();
+			this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.toolStrip2 = new System.Windows.Forms.ToolStrip();
+			this.btnAddWatch = new System.Windows.Forms.ToolStripButton();
+			this.btnRemoveWatch = new System.Windows.Forms.ToolStripButton();
+			this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
+			this.btnViewWatch = new System.Windows.Forms.ToolStripButton();
+			this.label3 = new System.Windows.Forms.Label();
+			this.tabPage4 = new System.Windows.Forms.TabPage();
+			this.label2 = new System.Windows.Forms.Label();
+			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
+			this.tabControl1 = new System.Windows.Forms.TabControl();
+			this.tabPage1 = new System.Windows.Forms.TabPage();
+			this.lvCallStack = new System.Windows.Forms.ListView();
+			this.colAddress = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.colName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.colReturn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.colBP = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.tabPage2 = new System.Windows.Forms.TabPage();
+			this.label1 = new System.Windows.Forms.Label();
 			this.codeView = new MoonSharp.Debugger.SourceCodeDebugControl();
-			this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
+			this.lvVStack = new System.Windows.Forms.ListView();
+			this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.menuStrip1.SuspendLayout();
 			this.toolStrip1.SuspendLayout();
 			this.splitContainer1.Panel1.SuspendLayout();
 			this.splitContainer1.Panel2.SuspendLayout();
 			this.splitContainer1.SuspendLayout();
+			this.splitContainer2.Panel1.SuspendLayout();
+			this.splitContainer2.Panel2.SuspendLayout();
 			this.splitContainer2.SuspendLayout();
+			this.tabControl2.SuspendLayout();
+			this.tabPage3.SuspendLayout();
+			this.toolStrip2.SuspendLayout();
+			this.tabPage4.SuspendLayout();
+			this.tabControl1.SuspendLayout();
+			this.tabPage1.SuspendLayout();
+			this.tabPage2.SuspendLayout();
 			this.SuspendLayout();
 			// 
 			// menuStrip1
@@ -78,6 +126,7 @@
 			// 
 			this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
             this.openToolStripMenuItem,
+            this.connectToolStripMenuItem,
             this.toolStripMenuItem1,
             this.exitToolStripMenuItem});
 			this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
@@ -86,12 +135,20 @@
 			// 
 			// openToolStripMenuItem
 			// 
+			this.openToolStripMenuItem.Image = global::MoonSharp.Debugger.Properties.Resources.Open_6529;
 			this.openToolStripMenuItem.Name = "openToolStripMenuItem";
 			this.openToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
 			this.openToolStripMenuItem.Size = new System.Drawing.Size(155, 22);
 			this.openToolStripMenuItem.Text = "&Open...";
 			this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
 			// 
+			// connectToolStripMenuItem
+			// 
+			this.connectToolStripMenuItem.Image = global::MoonSharp.Debugger.Properties.Resources.AddConnection_477;
+			this.connectToolStripMenuItem.Name = "connectToolStripMenuItem";
+			this.connectToolStripMenuItem.Size = new System.Drawing.Size(155, 22);
+			this.connectToolStripMenuItem.Text = "Connect...";
+			// 
 			// toolStripMenuItem1
 			// 
 			this.toolStripMenuItem1.Name = "toolStripMenuItem1";
@@ -131,7 +188,6 @@
 			this.debugToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
             this.stepOverToolStripMenuItem,
             this.stepInToolStripMenuItem,
-            this.stepOutToolStripMenuItem,
             this.toolStripMenuItem2,
             this.toggleBreakpointToolStripMenuItem,
             this.toolStripMenuItem3,
@@ -142,6 +198,7 @@
 			// 
 			// stepOverToolStripMenuItem
 			// 
+			this.stepOverToolStripMenuItem.Image = global::MoonSharp.Debugger.Properties.Resources.StepOver_6328;
 			this.stepOverToolStripMenuItem.Name = "stepOverToolStripMenuItem";
 			this.stepOverToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F10;
 			this.stepOverToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
@@ -149,17 +206,12 @@
 			// 
 			// stepInToolStripMenuItem
 			// 
+			this.stepInToolStripMenuItem.Image = global::MoonSharp.Debugger.Properties.Resources.StepIn_6326;
 			this.stepInToolStripMenuItem.Name = "stepInToolStripMenuItem";
 			this.stepInToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F11;
 			this.stepInToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
 			this.stepInToolStripMenuItem.Text = "Step-In";
-			// 
-			// stepOutToolStripMenuItem
-			// 
-			this.stepOutToolStripMenuItem.Name = "stepOutToolStripMenuItem";
-			this.stepOutToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F12;
-			this.stepOutToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
-			this.stepOutToolStripMenuItem.Text = "Step-Out";
+			this.stepInToolStripMenuItem.Click += new System.EventHandler(this.stepInToolStripMenuItem_Click);
 			// 
 			// toolStripMenuItem2
 			// 
@@ -168,6 +220,7 @@
 			// 
 			// toggleBreakpointToolStripMenuItem
 			// 
+			this.toggleBreakpointToolStripMenuItem.Image = global::MoonSharp.Debugger.Properties.Resources.BreakpointEnabled_6584_16x;
 			this.toggleBreakpointToolStripMenuItem.Name = "toggleBreakpointToolStripMenuItem";
 			this.toggleBreakpointToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F9;
 			this.toggleBreakpointToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
@@ -180,6 +233,7 @@
 			// 
 			// gOToolStripMenuItem
 			// 
+			this.gOToolStripMenuItem.Image = global::MoonSharp.Debugger.Properties.Resources.startwithoutdebugging_6556;
 			this.gOToolStripMenuItem.Name = "gOToolStripMenuItem";
 			this.gOToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F5;
 			this.gOToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
@@ -202,13 +256,102 @@
 			// toolStrip1
 			// 
 			this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
-            this.toolStripButton1});
+            this.toolStripButton1,
+            this.toolStripButton2,
+            this.toolStripSeparator1,
+            this.toolStripButton3,
+            this.toolStripSeparator2,
+            this.toolStripButton6,
+            this.toolStripButton4,
+            this.toolStepIN,
+            this.toolStripSeparator3,
+            this.toolStripButton5});
 			this.toolStrip1.Location = new System.Drawing.Point(0, 24);
 			this.toolStrip1.Name = "toolStrip1";
 			this.toolStrip1.Size = new System.Drawing.Size(1094, 25);
 			this.toolStrip1.TabIndex = 1;
 			this.toolStrip1.Text = "toolStrip1";
 			// 
+			// toolStripButton1
+			// 
+			this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+			this.toolStripButton1.Image = global::MoonSharp.Debugger.Properties.Resources.Open_6529;
+			this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolStripButton1.Name = "toolStripButton1";
+			this.toolStripButton1.Size = new System.Drawing.Size(23, 22);
+			this.toolStripButton1.Text = "toolStripButton1";
+			// 
+			// toolStripButton2
+			// 
+			this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+			this.toolStripButton2.Image = global::MoonSharp.Debugger.Properties.Resources.AddConnection_477;
+			this.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolStripButton2.Name = "toolStripButton2";
+			this.toolStripButton2.Size = new System.Drawing.Size(23, 22);
+			this.toolStripButton2.Text = "toolStripButton2";
+			// 
+			// toolStripSeparator1
+			// 
+			this.toolStripSeparator1.Name = "toolStripSeparator1";
+			this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
+			// 
+			// toolStripButton3
+			// 
+			this.toolStripButton3.Checked = true;
+			this.toolStripButton3.CheckState = System.Windows.Forms.CheckState.Checked;
+			this.toolStripButton3.Image = global::MoonSharp.Debugger.Properties.Resources.DisassemblyWindow_6536;
+			this.toolStripButton3.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolStripButton3.Name = "toolStripButton3";
+			this.toolStripButton3.Size = new System.Drawing.Size(76, 22);
+			this.toolStripButton3.Text = "Bytecode";
+			// 
+			// toolStripSeparator2
+			// 
+			this.toolStripSeparator2.Name = "toolStripSeparator2";
+			this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
+			// 
+			// toolStripButton6
+			// 
+			this.toolStripButton6.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+			this.toolStripButton6.Image = global::MoonSharp.Debugger.Properties.Resources.startwithoutdebugging_6556;
+			this.toolStripButton6.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolStripButton6.Name = "toolStripButton6";
+			this.toolStripButton6.Size = new System.Drawing.Size(23, 22);
+			this.toolStripButton6.Text = "toolStripButton6";
+			// 
+			// toolStripButton4
+			// 
+			this.toolStripButton4.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+			this.toolStripButton4.Image = global::MoonSharp.Debugger.Properties.Resources.StepOver_6328;
+			this.toolStripButton4.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolStripButton4.Name = "toolStripButton4";
+			this.toolStripButton4.Size = new System.Drawing.Size(23, 22);
+			this.toolStripButton4.Text = "toolStripButton4";
+			// 
+			// toolStepIN
+			// 
+			this.toolStepIN.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+			this.toolStepIN.Image = global::MoonSharp.Debugger.Properties.Resources.StepIn_6326;
+			this.toolStepIN.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolStepIN.Name = "toolStepIN";
+			this.toolStepIN.Size = new System.Drawing.Size(23, 22);
+			this.toolStepIN.Text = "Step-In";
+			this.toolStepIN.Click += new System.EventHandler(this.toolStripButton1_Click);
+			// 
+			// toolStripSeparator3
+			// 
+			this.toolStripSeparator3.Name = "toolStripSeparator3";
+			this.toolStripSeparator3.Size = new System.Drawing.Size(6, 25);
+			// 
+			// toolStripButton5
+			// 
+			this.toolStripButton5.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+			this.toolStripButton5.Image = global::MoonSharp.Debugger.Properties.Resources.BreakpointEnabled_6584_16x;
+			this.toolStripButton5.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolStripButton5.Name = "toolStripButton5";
+			this.toolStripButton5.Size = new System.Drawing.Size(23, 22);
+			this.toolStripButton5.Text = "toolStripButton5";
+			// 
 			// statusStrip1
 			// 
 			this.statusStrip1.Location = new System.Drawing.Point(0, 712);
@@ -240,10 +383,252 @@
 			this.splitContainer2.Location = new System.Drawing.Point(0, 0);
 			this.splitContainer2.Name = "splitContainer2";
 			this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
+			// 
+			// splitContainer2.Panel1
+			// 
+			this.splitContainer2.Panel1.Controls.Add(this.tabControl2);
+			// 
+			// splitContainer2.Panel2
+			// 
+			this.splitContainer2.Panel2.Controls.Add(this.tabControl1);
 			this.splitContainer2.Size = new System.Drawing.Size(364, 663);
 			this.splitContainer2.SplitterDistance = 307;
 			this.splitContainer2.TabIndex = 0;
 			// 
+			// tabControl2
+			// 
+			this.tabControl2.Controls.Add(this.tabPage3);
+			this.tabControl2.Controls.Add(this.tabPage4);
+			this.tabControl2.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.tabControl2.ImageList = this.imageList1;
+			this.tabControl2.Location = new System.Drawing.Point(0, 0);
+			this.tabControl2.Name = "tabControl2";
+			this.tabControl2.SelectedIndex = 0;
+			this.tabControl2.Size = new System.Drawing.Size(364, 307);
+			this.tabControl2.TabIndex = 1;
+			// 
+			// tabPage3
+			// 
+			this.tabPage3.Controls.Add(this.lvWatches);
+			this.tabPage3.Controls.Add(this.toolStrip2);
+			this.tabPage3.Controls.Add(this.label3);
+			this.tabPage3.ImageIndex = 3;
+			this.tabPage3.Location = new System.Drawing.Point(4, 23);
+			this.tabPage3.Name = "tabPage3";
+			this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
+			this.tabPage3.Size = new System.Drawing.Size(356, 280);
+			this.tabPage3.TabIndex = 0;
+			this.tabPage3.Text = "Watches";
+			this.tabPage3.UseVisualStyleBackColor = true;
+			// 
+			// lvWatches
+			// 
+			this.lvWatches.BackColor = System.Drawing.SystemColors.Window;
+			this.lvWatches.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+            this.columnHeader1,
+            this.columnHeader2,
+            this.columnHeader3,
+            this.columnHeader4});
+			this.lvWatches.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.lvWatches.FullRowSelect = true;
+			this.lvWatches.GridLines = true;
+			this.lvWatches.Location = new System.Drawing.Point(3, 28);
+			this.lvWatches.Name = "lvWatches";
+			this.lvWatches.Size = new System.Drawing.Size(350, 249);
+			this.lvWatches.TabIndex = 4;
+			this.lvWatches.UseCompatibleStateImageBehavior = false;
+			this.lvWatches.View = System.Windows.Forms.View.Details;
+			// 
+			// columnHeader1
+			// 
+			this.columnHeader1.Text = "Name";
+			this.columnHeader1.Width = 72;
+			// 
+			// columnHeader2
+			// 
+			this.columnHeader2.Text = "Type";
+			this.columnHeader2.Width = 57;
+			// 
+			// columnHeader3
+			// 
+			this.columnHeader3.Text = "Value";
+			this.columnHeader3.Width = 111;
+			// 
+			// columnHeader4
+			// 
+			this.columnHeader4.Text = "Symbol loc.";
+			this.columnHeader4.Width = 72;
+			// 
+			// toolStrip2
+			// 
+			this.toolStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.btnAddWatch,
+            this.btnRemoveWatch,
+            this.toolStripSeparator4,
+            this.btnViewWatch});
+			this.toolStrip2.Location = new System.Drawing.Point(3, 3);
+			this.toolStrip2.Name = "toolStrip2";
+			this.toolStrip2.Size = new System.Drawing.Size(350, 25);
+			this.toolStrip2.TabIndex = 3;
+			this.toolStrip2.Text = "toolStrip2";
+			// 
+			// btnAddWatch
+			// 
+			this.btnAddWatch.Image = global::MoonSharp.Debugger.Properties.Resources.AddMark_10580;
+			this.btnAddWatch.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.btnAddWatch.Name = "btnAddWatch";
+			this.btnAddWatch.Size = new System.Drawing.Size(49, 22);
+			this.btnAddWatch.Text = "Add";
+			this.btnAddWatch.Click += new System.EventHandler(this.btnAddWatch_Click);
+			// 
+			// btnRemoveWatch
+			// 
+			this.btnRemoveWatch.Image = global::MoonSharp.Debugger.Properties.Resources.Clearallrequests_8816;
+			this.btnRemoveWatch.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.btnRemoveWatch.Name = "btnRemoveWatch";
+			this.btnRemoveWatch.Size = new System.Drawing.Size(70, 22);
+			this.btnRemoveWatch.Text = "Remove";
+			this.btnRemoveWatch.Click += new System.EventHandler(this.btnRemoveWatch_Click);
+			// 
+			// toolStripSeparator4
+			// 
+			this.toolStripSeparator4.Name = "toolStripSeparator4";
+			this.toolStripSeparator4.Size = new System.Drawing.Size(6, 25);
+			// 
+			// btnViewWatch
+			// 
+			this.btnViewWatch.Image = global::MoonSharp.Debugger.Properties.Resources.FindSymbol_6263;
+			this.btnViewWatch.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.btnViewWatch.Name = "btnViewWatch";
+			this.btnViewWatch.Size = new System.Drawing.Size(52, 22);
+			this.btnViewWatch.Text = "View";
+			// 
+			// label3
+			// 
+			this.label3.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.label3.Location = new System.Drawing.Point(3, 3);
+			this.label3.Name = "label3";
+			this.label3.Size = new System.Drawing.Size(350, 274);
+			this.label3.TabIndex = 2;
+			this.label3.Text = "Not Implemented Yet";
+			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+			// 
+			// tabPage4
+			// 
+			this.tabPage4.Controls.Add(this.lvVStack);
+			this.tabPage4.Controls.Add(this.label2);
+			this.tabPage4.ImageIndex = 1;
+			this.tabPage4.Location = new System.Drawing.Point(4, 23);
+			this.tabPage4.Name = "tabPage4";
+			this.tabPage4.Padding = new System.Windows.Forms.Padding(3);
+			this.tabPage4.Size = new System.Drawing.Size(356, 280);
+			this.tabPage4.TabIndex = 1;
+			this.tabPage4.Text = "V-Stack";
+			this.tabPage4.UseVisualStyleBackColor = true;
+			// 
+			// label2
+			// 
+			this.label2.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.label2.Location = new System.Drawing.Point(3, 3);
+			this.label2.Name = "label2";
+			this.label2.Size = new System.Drawing.Size(350, 274);
+			this.label2.TabIndex = 1;
+			this.label2.Text = "Not Implemented Yet";
+			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+			// 
+			// imageList1
+			// 
+			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
+			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
+			this.imageList1.Images.SetKeyName(0, "CallStackWindow_6561.png");
+			this.imageList1.Images.SetKeyName(1, "Centered_11691.png");
+			this.imageList1.Images.SetKeyName(2, "CodeCoverageResults_8592.png");
+			this.imageList1.Images.SetKeyName(3, "LocalsWindow_6562.png");
+			// 
+			// tabControl1
+			// 
+			this.tabControl1.Controls.Add(this.tabPage1);
+			this.tabControl1.Controls.Add(this.tabPage2);
+			this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.tabControl1.ImageList = this.imageList1;
+			this.tabControl1.Location = new System.Drawing.Point(0, 0);
+			this.tabControl1.Name = "tabControl1";
+			this.tabControl1.SelectedIndex = 0;
+			this.tabControl1.Size = new System.Drawing.Size(364, 352);
+			this.tabControl1.TabIndex = 0;
+			// 
+			// tabPage1
+			// 
+			this.tabPage1.Controls.Add(this.lvCallStack);
+			this.tabPage1.ImageIndex = 0;
+			this.tabPage1.Location = new System.Drawing.Point(4, 23);
+			this.tabPage1.Name = "tabPage1";
+			this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
+			this.tabPage1.Size = new System.Drawing.Size(356, 325);
+			this.tabPage1.TabIndex = 0;
+			this.tabPage1.Text = "Call Stack";
+			this.tabPage1.UseVisualStyleBackColor = true;
+			// 
+			// lvCallStack
+			// 
+			this.lvCallStack.BackColor = System.Drawing.SystemColors.Window;
+			this.lvCallStack.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+            this.colAddress,
+            this.colName,
+            this.colReturn,
+            this.colBP});
+			this.lvCallStack.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.lvCallStack.FullRowSelect = true;
+			this.lvCallStack.GridLines = true;
+			this.lvCallStack.Location = new System.Drawing.Point(3, 3);
+			this.lvCallStack.Name = "lvCallStack";
+			this.lvCallStack.Size = new System.Drawing.Size(350, 319);
+			this.lvCallStack.TabIndex = 0;
+			this.lvCallStack.UseCompatibleStateImageBehavior = false;
+			this.lvCallStack.View = System.Windows.Forms.View.Details;
+			// 
+			// colAddress
+			// 
+			this.colAddress.Text = "Address";
+			this.colAddress.Width = 72;
+			// 
+			// colName
+			// 
+			this.colName.Text = "Name";
+			this.colName.Width = 106;
+			// 
+			// colReturn
+			// 
+			this.colReturn.Text = "Return";
+			this.colReturn.Width = 72;
+			// 
+			// colBP
+			// 
+			this.colBP.Text = "Base Ptr";
+			this.colBP.Width = 72;
+			// 
+			// tabPage2
+			// 
+			this.tabPage2.Controls.Add(this.label1);
+			this.tabPage2.ImageIndex = 2;
+			this.tabPage2.Location = new System.Drawing.Point(4, 23);
+			this.tabPage2.Name = "tabPage2";
+			this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
+			this.tabPage2.Size = new System.Drawing.Size(356, 325);
+			this.tabPage2.TabIndex = 1;
+			this.tabPage2.Text = "Coroutines";
+			this.tabPage2.UseVisualStyleBackColor = true;
+			// 
+			// label1
+			// 
+			this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.label1.Location = new System.Drawing.Point(3, 3);
+			this.label1.Name = "label1";
+			this.label1.Size = new System.Drawing.Size(350, 319);
+			this.label1.TabIndex = 1;
+			this.label1.Text = "Not Implemented Yet";
+			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+			// 
 			// codeView
 			// 
 			this.codeView.ActiveLine = -1;
@@ -257,17 +642,39 @@
 			this.codeView.Name = "codeView";
 			this.codeView.Size = new System.Drawing.Size(726, 663);
 			this.codeView.SourceCode = null;
-			this.codeView.TabIndex = 1;
+			this.codeView.TabIndex = 0;
 			// 
-			// toolStripButton1
+			// lvVStack
 			// 
-			this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
-			this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image")));
-			this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
-			this.toolStripButton1.Name = "toolStripButton1";
-			this.toolStripButton1.Size = new System.Drawing.Size(23, 22);
-			this.toolStripButton1.Text = "Step-In";
-			this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click);
+			this.lvVStack.BackColor = System.Drawing.SystemColors.Window;
+			this.lvVStack.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+            this.columnHeader5,
+            this.columnHeader6,
+            this.columnHeader7});
+			this.lvVStack.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.lvVStack.FullRowSelect = true;
+			this.lvVStack.GridLines = true;
+			this.lvVStack.Location = new System.Drawing.Point(3, 3);
+			this.lvVStack.Name = "lvVStack";
+			this.lvVStack.Size = new System.Drawing.Size(350, 274);
+			this.lvVStack.TabIndex = 5;
+			this.lvVStack.UseCompatibleStateImageBehavior = false;
+			this.lvVStack.View = System.Windows.Forms.View.Details;
+			// 
+			// columnHeader5
+			// 
+			this.columnHeader5.Text = "Stack ofs";
+			this.columnHeader5.Width = 72;
+			// 
+			// columnHeader6
+			// 
+			this.columnHeader6.Text = "Type";
+			this.columnHeader6.Width = 94;
+			// 
+			// columnHeader7
+			// 
+			this.columnHeader7.Text = "Value";
+			this.columnHeader7.Width = 157;
 			// 
 			// MainForm
 			// 
@@ -289,7 +696,18 @@
 			this.splitContainer1.Panel1.ResumeLayout(false);
 			this.splitContainer1.Panel2.ResumeLayout(false);
 			this.splitContainer1.ResumeLayout(false);
+			this.splitContainer2.Panel1.ResumeLayout(false);
+			this.splitContainer2.Panel2.ResumeLayout(false);
 			this.splitContainer2.ResumeLayout(false);
+			this.tabControl2.ResumeLayout(false);
+			this.tabPage3.ResumeLayout(false);
+			this.tabPage3.PerformLayout();
+			this.toolStrip2.ResumeLayout(false);
+			this.toolStrip2.PerformLayout();
+			this.tabPage4.ResumeLayout(false);
+			this.tabControl1.ResumeLayout(false);
+			this.tabPage1.ResumeLayout(false);
+			this.tabPage2.ResumeLayout(false);
 			this.ResumeLayout(false);
 			this.PerformLayout();
 
@@ -302,7 +720,6 @@
 		private System.Windows.Forms.StatusStrip statusStrip1;
 		private System.Windows.Forms.SplitContainer splitContainer1;
 		private System.Windows.Forms.SplitContainer splitContainer2;
-		private SourceCodeDebugControl codeView;
 		private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
 		private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
 		private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
@@ -310,7 +727,6 @@
 		private System.Windows.Forms.ToolStripMenuItem debugToolStripMenuItem;
 		private System.Windows.Forms.ToolStripMenuItem stepOverToolStripMenuItem;
 		private System.Windows.Forms.ToolStripMenuItem stepInToolStripMenuItem;
-		private System.Windows.Forms.ToolStripMenuItem stepOutToolStripMenuItem;
 		private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
 		private System.Windows.Forms.ToolStripMenuItem toggleBreakpointToolStripMenuItem;
 		private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3;
@@ -320,7 +736,47 @@
 		private System.Windows.Forms.ToolStripMenuItem viewToolStripMenuItem;
 		private System.Windows.Forms.ToolStripMenuItem scriptCodeToolStripMenuItem;
 		private System.Windows.Forms.ToolStripMenuItem bytecodeToolStripMenuItem;
+		private System.Windows.Forms.ToolStripButton toolStepIN;
+		private SourceCodeDebugControl codeView;
+		private System.Windows.Forms.TabControl tabControl2;
+		private System.Windows.Forms.TabPage tabPage3;
+		private System.Windows.Forms.Label label3;
+		private System.Windows.Forms.TabPage tabPage4;
+		private System.Windows.Forms.Label label2;
+		private System.Windows.Forms.TabControl tabControl1;
+		private System.Windows.Forms.TabPage tabPage1;
+		private System.Windows.Forms.TabPage tabPage2;
+		private System.Windows.Forms.Label label1;
+		private System.Windows.Forms.ListView lvCallStack;
+		private System.Windows.Forms.ColumnHeader colAddress;
+		private System.Windows.Forms.ColumnHeader colName;
+		private System.Windows.Forms.ColumnHeader colBP;
+		private System.Windows.Forms.ColumnHeader colReturn;
+		private System.Windows.Forms.ImageList imageList1;
 		private System.Windows.Forms.ToolStripButton toolStripButton1;
+		private System.Windows.Forms.ToolStripButton toolStripButton2;
+		private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
+		private System.Windows.Forms.ToolStripButton toolStripButton3;
+		private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
+		private System.Windows.Forms.ToolStripButton toolStripButton6;
+		private System.Windows.Forms.ToolStripButton toolStripButton4;
+		private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
+		private System.Windows.Forms.ToolStripButton toolStripButton5;
+		private System.Windows.Forms.ToolStripMenuItem connectToolStripMenuItem;
+		private System.Windows.Forms.ListView lvWatches;
+		private System.Windows.Forms.ColumnHeader columnHeader1;
+		private System.Windows.Forms.ColumnHeader columnHeader2;
+		private System.Windows.Forms.ColumnHeader columnHeader3;
+		private System.Windows.Forms.ColumnHeader columnHeader4;
+		private System.Windows.Forms.ToolStrip toolStrip2;
+		private System.Windows.Forms.ToolStripButton btnAddWatch;
+		private System.Windows.Forms.ToolStripButton btnRemoveWatch;
+		private System.Windows.Forms.ToolStripButton btnViewWatch;
+		private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
+		private System.Windows.Forms.ListView lvVStack;
+		private System.Windows.Forms.ColumnHeader columnHeader5;
+		private System.Windows.Forms.ColumnHeader columnHeader6;
+		private System.Windows.Forms.ColumnHeader columnHeader7;
 
 
 	}

+ 144 - 2
src/MoonSharp.Debugger/MainForm.cs

@@ -18,6 +18,8 @@ namespace MoonSharp.Debugger
 {
 	public partial class MainForm : Form, IDebugger
 	{
+		List<string> m_Watches = new List<string>();
+
 		public MainForm()
 		{
 			InitializeComponent();
@@ -51,12 +53,22 @@ namespace MoonSharp.Debugger
 			m_Script.AttachDebugger(this);
 
 			Thread m_Debugger = new Thread(DebugMain);
+			m_Debugger.Name = "Moon# Execution Thread";
+			m_Debugger.IsBackground = true;
 			m_Debugger.Start();
+
 		}
 
 		void IDebugger.SetSourceCode(Chunk byteCode, string[] code)
 		{
-			codeView.SourceCode = byteCode.Code.Select(s => s.ToString()).ToArray();
+			string[] source = new string[byteCode.Code.Count];
+
+			for (int i = 0; i < byteCode.Code.Count; i++)
+			{
+				source[i] = string.Format("{0:X8}  {1}", i, byteCode.Code[i]);
+			}
+
+			codeView.SourceCode = source;
 		}
 
 		DebuggerAction m_NextAction;
@@ -86,7 +98,9 @@ namespace MoonSharp.Debugger
 		{
 			m_NextAction = action;
 			m_WaitLock.Set();
-			m_WaitBack.WaitOne();
+
+			if (!m_WaitBack.WaitOne(1000))
+				MessageBox.Show(this, "Operation timed out", "Timeout");
 		}
 
 
@@ -96,8 +110,136 @@ namespace MoonSharp.Debugger
 		}
 
 		private void toolStripButton1_Click(object sender, EventArgs e)
+		{
+			StepIN();
+		}
+
+		private void StepIN()
 		{
 			DebugAction(new DebuggerAction() { Action = DebuggerAction.ActionType.StepIn });
 		}
+
+
+		void IDebugger.Update(WatchType watchType, List<WatchItem> items)
+		{
+			if (watchType == WatchType.CallStack)
+				m_Ctx.Post(UpdateCallStack, items);
+			if (watchType == WatchType.Watches)
+				m_Ctx.Post(UpdateWatches, items);
+			if (watchType == WatchType.VStack)
+				m_Ctx.Post(UpdateVStack, items);
+		}
+		void UpdateVStack(object o)
+		{
+			List<WatchItem> items = (List<WatchItem>)o;
+
+			lvVStack.BeginUpdate();
+			lvVStack.Items.Clear();
+
+			foreach (var item in items)
+			{
+				var lvi = BuildListViewItem(
+					item.Address.ToString("X4"),
+					(item.Value != null) ? item.Value.Type.ToString() : "(undefined)",
+					(item.Value != null) ? item.Value.ToString() : "(undefined)"
+					);
+				lvVStack.Items.Add(lvi);
+			}
+
+			lvVStack.EndUpdate();
+
+		}
+
+
+		void UpdateWatches(object o)
+		{
+			List<WatchItem> items = (List<WatchItem>)o;
+
+			lvWatches.BeginUpdate();
+			lvWatches.Items.Clear();
+
+			foreach (var item in items)
+			{
+				var lvi = BuildListViewItem(
+					item.Name ?? "(???)",
+					(item.Value != null) ? item.Value.Type.ToLuaTypeString() : "(undefined)",
+					(item.Value != null) ? item.Value.ToString() : "(undefined)",
+					(item.LValue != null) ? item.LValue.ToString() : "(undefined)"
+					);
+				lvWatches.Items.Add(lvi);
+			}
+
+			lvWatches.EndUpdate();
+
+		}
+
+		void UpdateCallStack(object o)
+		{
+			List<WatchItem> items = (List<WatchItem>)o;
+
+			lvCallStack.BeginUpdate();
+			lvCallStack.Items.Clear();
+			foreach (var item in items)
+			{
+				var lvi = BuildListViewItem(
+					item.Address.ToString("X8"),
+					item.Name ?? "(???)",
+					item.RetAddress.ToString("X8"),
+					item.BasePtr.ToString("X8")
+					);
+				lvCallStack.Items.Add(lvi);
+			}
+
+			lvCallStack.Items.Add(BuildListViewItem("---", "(main)", "---", "---"));
+
+			lvCallStack.EndUpdate();
+		}
+
+		private ListViewItem BuildListViewItem(params string[] texts)
+		{
+			ListViewItem lvi = new ListViewItem();
+			lvi.Text = texts[0];
+
+			for (int i = 1; i < texts.Length; i++)
+			{
+				ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem();
+				lvsi.Text = texts[i];
+				lvi.SubItems.Add(lvsi);
+			}
+
+			return lvi;
+		}
+
+
+		List<string> IDebugger.GetWatchItems()
+		{
+			return m_Watches;
+		}
+
+		private void stepInToolStripMenuItem_Click(object sender, EventArgs e)
+		{
+			StepIN();
+		}
+
+		private void btnAddWatch_Click(object sender, EventArgs e)
+		{
+			string text = WatchInputDialog.GetNewWatchName();
+
+			if (!string.IsNullOrEmpty(text))
+			{
+				m_Watches.AddRange(text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
+				DebugAction(new DebuggerAction() { Action = DebuggerAction.ActionType.Refresh });
+			}
+		}
+
+		private void btnRemoveWatch_Click(object sender, EventArgs e)
+		{
+			HashSet<string> itemsToRemove = new HashSet<string>(lvWatches.SelectedItems.OfType<ListViewItem>().Select(lvi => lvi.Text));
+
+			int i = m_Watches.RemoveAll(w => itemsToRemove.Contains(w));
+
+			if (i != 0)
+				DebugAction(new DebuggerAction() { Action = DebuggerAction.ActionType.Refresh });
+		}
 	}
 }

+ 72 - 16
src/MoonSharp.Debugger/MainForm.resx

@@ -123,23 +123,79 @@
   <metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>132, 17</value>
   </metadata>
-  <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-  <data name="toolStripButton1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
-    <value>
-        iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
-        YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
-        YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
-        0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
-        bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
-        VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
-        c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
-        Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
-        mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
-        kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
-        TgDQASA1MVpwzwAAAABJRU5ErkJggg==
-</value>
-  </data>
   <metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>237, 17</value>
   </metadata>
+  <metadata name="toolStrip2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>463, 17</value>
+  </metadata>
+  <metadata name="imageList1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>353, 17</value>
+  </metadata>
+  <data name="imageList1.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64">
+    <value>
+        AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
+        LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
+        ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAACe
+        DQAAAk1TRnQBSQFMAgEBBAEAAcgBAAHIAQABEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA
+        AwABIAMAAQEBAAEgBgABIP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8AIgADDAEQA1kBvwP2
+        Af8D9gH/A1kBvwMqAUADKgFAAyoBQAMqAUADKgFAAyoBQAMqAUADKgFAAyoBQAMqAUADKgFAEAAD9gH/
+        A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/5AAA1kBvwOcAf8DKQH/AykB/wP2Af8D9gH/A/YB/wP2
+        Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/xAAA/YB/wMpAf8DKQH/AykB/wMpAf8DKQH/
+        AykB/wP2Af+QAAP2Af8DKQH/AykB/wMpAf8D9gH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMp
+        Af8DKQH/AykB/wP2Af8QAAP2Af8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8D9gH/FAAD9gH/A/YB/wP2
+        Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8cAAP2Af8D9gH/A/YB/wP2Af8D9gH/CAADIQEwAyEBMAQA
+        A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/AykB/wMpAf8DKQH/A/YB/wMpAf8DKQH/AykB/wMpAf8DKQH/
+        AykB/wMpAf8DKQH/AykB/wMpAf8D9gH/EAAD9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/xQA
+        A/YB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8D9gH/HAAD9gH/AykB/wMpAf8DKQH/A/YB/wQA
+        AyEBMANiAe8DYgHvAyEBMAP2Af8DKQH/AykB/wMpAf8D9gH/A/YB/wMpAf8D9gH/A/YB/wP2Af8DKQH/
+        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/A/YB/wgAA/YB/wP2Af8D9gH/A/YB/wP2
+        Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/DAAD9gH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/
+        AykB/wP2Af8cAAP2Af8DKQH/A/YB/wP2Af8D9gH/AyEBMANiAe8DhgH/A0sB/wNiAe8D9gH/A/YB/wP2
+        Af8DKQH/A/YB/wP2Af8DKQH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2
+        Af8D9gH/A/YB/wP2Af8IAAP2Af8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/
+        A/YB/wwAA/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8UAAP2Af8DKQH/
+        A/YB/wQAAyEBMAM6AWADYgHvA4YB/wMpAf8DSwH/A2IB7wMhATAD9gH/AykB/wP2Af8D9gH/AykB/wP2
+        Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/CAAD9gH/
+        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wP2Af8UAAP2Af8DKQH/AykB/wMp
+        Af8DKQH/AykB/wMpAf8DKQH/A/YB/xQAA/YB/wMpAf8D9gH/AyEBMANiAe8DYgHvAzoBYANiAe8DhgH/
+        A0sB/wNiAe8DIQEwA/YB/wMpAf8D9gH/A/YB/wMpAf8D9gH/A/YB/wP2Af8DKQH/AykB/wMpAf8DKQH/
+        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/A/YB/wgAA/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2
+        Af8D9gH/A/YB/wP2Af8D9gH/FAAD9gH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wP2Af8UAAP2
+        Af8DKQH/A/YB/wNiAe8DhgH/A0sB/wNiAe8DOgFgA2IB7wP2Af8DYgHvAyEBMAP2Af8DKQH/A/YB/wP2
+        Af8DKQH/AykB/wMpAf8D9gH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wP2
+        Af8MAAP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8YAAP2Af8D9gH/A/YB/wP2
+        Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wgAA/YB/wMpAf8D9gH/A4YB/wMpAf8DKQH/
+        A0sB/wNiAe8DYgHvA4YB/wNLAf8DYgHvA/YB/wMpAf8D9gH/A/YB/wMpAf8DKQH/AykB/wP2Af8DKQH/
+        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/A/YB/wwAA/YB/wMpAf8DKQH/AykB/wMp
+        Af8DKQH/AykB/wMpAf8DKQH/A/YB/xgAA/YB/wMpAf8DKQH/AykB/wMpAf8DKQH/A/YB/wMpAf8DKQH/
+        AykB/wMpAf8D9gH/CAAD9gH/AykB/wP2Af8DhgH/AykB/wMpAf8DKQH/A0sB/wPrAf8DhgH/AykB/wNL
+        Af8D9gH/AykB/wP2Af8DWQG/A5wB/wMpAf8DKQH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2
+        Af8D9gH/A/YB/wP2Af8D9gH/DAAD9gH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8D9gH/
+        GAAD9gH/AykB/wMpAf8DKQH/AykB/wMpAf8D9gH/AykB/wMpAf8DKQH/AykB/wP2Af8IAAP2Af8DKQH/
+        A/YB/wNiAe8DhgH/AykB/wMpAf8DSwH/A2IB7wNiAe8DhgH/A0sB/wP2Af8DKQH/A/YB/wMMARAD9gH/
+        A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8MAAP2
+        Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8QAAP2Af8D9gH/A/YB/wP2Af8D9gH/
+        A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/CAAD9gH/AykB/wP2Af8DIQEwA2IB7wOG
+        Af8DSwH/A2IB7wMhATADIQEwA2IB7wNcAd8D9gH/AykB/wP2Af8EAAP2Af8DKQH/AykB/wMpAf8DKQH/
+        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/
+        A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8EAAP2Af8DKQH/AykB/wMp
+        Af8DKQH/AykB/wP2Af8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8D9gH/CAAD9gH/AykB/wP2Af8D9gH/
+        A/YB/wNiAe8DYgHvAyEBMAgAA/YB/wP2Af8D9gH/AykB/wP2Af8EAAP2Af8DKQH/AykB/wMpAf8DKQH/
+        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/A/YB/wP2Af8DKQH/AykB/wMpAf8DKQH/
+        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wP2Af8EAAP2Af8DKQH/AykB/wMp
+        Af8DKQH/AykB/wP2Af8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8D9gH/CAAD9gH/AykB/wMpAf8DKQH/
+        A/YB/wMhATADIQEwDAAD9gH/AykB/wMpAf8DKQH/A/YB/wQAA/YB/wMpAf8DKQH/AykB/wMpAf8DKQH/
+        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8D9gH/A/YB/wMpAf8DKQH/AykB/wMpAf8DKQH/
+        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/A/YB/wQAA/YB/wP2Af8D9gH/A/YB/wP2
+        Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8IAAP2Af8D9gH/A/YB/wP2Af8D9gH/
+        FAAD9gH/A/YB/wP2Af8D9gH/A/YB/wQAA/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/
+        A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/
+        A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/4AAAUIBTQE+BwABPgMAASgDAAFAAwABIAMAAQEBAAEB
+        BgABARYAA/+DAAHwAQ8E/wIAAfABDwT/AgAB8AEPAYABPwGDASACAAHwAQ8BgAE/AYIDAAHAAQMBgAE/
+        AYADAAHAAQMBgAEPAYgDAAHAAQMB4AEPAYADAAHAAQMB4AEPAYADAAHgAQcB4AEBAYADAAHgAQcB4AEB
+        AYADAAHgAQcB4AEBAYADAAHgAQcBgAEBAYABAAGAAwABgAEBAYABYAGAAwABgAEBAYAB4AGAAwABgAEB
+        AYMB4AGAAwAE/ws=
+</value>
+  </data>
 </root>

+ 55 - 0
src/MoonSharp.Debugger/MoonSharp.Debugger.csproj

@@ -57,6 +57,12 @@
     <Compile Include="SourceCodeDebugControl.Designer.cs">
       <DependentUpon>SourceCodeDebugControl.cs</DependentUpon>
     </Compile>
+    <Compile Include="WatchInputDialog.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="WatchInputDialog.Designer.cs">
+      <DependentUpon>WatchInputDialog.cs</DependentUpon>
+    </Compile>
     <EmbeddedResource Include="MainForm.resx">
       <DependentUpon>MainForm.cs</DependentUpon>
     </EmbeddedResource>
@@ -68,10 +74,14 @@
     <Compile Include="Properties\Resources.Designer.cs">
       <AutoGen>True</AutoGen>
       <DependentUpon>Resources.resx</DependentUpon>
+      <DesignTime>True</DesignTime>
     </Compile>
     <EmbeddedResource Include="SourceCodeDebugControl.resx">
       <DependentUpon>SourceCodeDebugControl.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="WatchInputDialog.resx">
+      <DependentUpon>WatchInputDialog.cs</DependentUpon>
+    </EmbeddedResource>
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
       <LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -88,6 +98,51 @@
       <Name>MoonSharp.Interpreter</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\Restart_6322.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\StepIn_6326.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\Stepout_6327.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\StepOver_6328.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\Breakall_6323.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\BreakpointEnabled_6584_16x.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\Open_6529.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\RPCThread_10388.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\DisassemblyWindow_6536.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\Help_6522.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\startwithoutdebugging_6556.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\AddConnection_477.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\AddMark_10580.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\Clearallrequests_8816.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\FindSymbol_6263.png" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.

+ 202 - 60
src/MoonSharp.Debugger/Properties/Resources.Designer.cs

@@ -8,64 +8,206 @@
 // </auto-generated>
 //------------------------------------------------------------------------------
 
-namespace MoonSharp.Debugger.Properties
-{
-
-
-	/// <summary>
-	///   A strongly-typed resource class, for looking up localized strings, etc.
-	/// </summary>
-	// This class was auto-generated by the StronglyTypedResourceBuilder
-	// class via a tool like ResGen or Visual Studio.
-	// To add or remove a member, edit your .ResX file then rerun ResGen
-	// with the /str option, or rebuild your VS project.
-	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
-	[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-	[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-	internal class Resources
-	{
-
-		private static global::System.Resources.ResourceManager resourceMan;
-
-		private static global::System.Globalization.CultureInfo resourceCulture;
-
-		[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
-		internal Resources()
-		{
-		}
-
-		/// <summary>
-		///   Returns the cached ResourceManager instance used by this class.
-		/// </summary>
-		[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-		internal static global::System.Resources.ResourceManager ResourceManager
-		{
-			get
-			{
-				if ((resourceMan == null))
-				{
-					global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MoonSharp.Debugger.Properties.Resources", typeof(Resources).Assembly);
-					resourceMan = temp;
-				}
-				return resourceMan;
-			}
-		}
-
-		/// <summary>
-		///   Overrides the current thread's CurrentUICulture property for all
-		///   resource lookups using this strongly typed resource class.
-		/// </summary>
-		[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-		internal static global::System.Globalization.CultureInfo Culture
-		{
-			get
-			{
-				return resourceCulture;
-			}
-			set
-			{
-				resourceCulture = value;
-			}
-		}
-	}
+namespace MoonSharp.Debugger.Properties {
+    using System;
+    
+    
+    /// <summary>
+    ///   A strongly-typed resource class, for looking up localized strings, etc.
+    /// </summary>
+    // This class was auto-generated by the StronglyTypedResourceBuilder
+    // class via a tool like ResGen or Visual Studio.
+    // To add or remove a member, edit your .ResX file then rerun ResGen
+    // with the /str option, or rebuild your VS project.
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    internal class Resources {
+        
+        private static global::System.Resources.ResourceManager resourceMan;
+        
+        private static global::System.Globalization.CultureInfo resourceCulture;
+        
+        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+        internal Resources() {
+        }
+        
+        /// <summary>
+        ///   Returns the cached ResourceManager instance used by this class.
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Resources.ResourceManager ResourceManager {
+            get {
+                if (object.ReferenceEquals(resourceMan, null)) {
+                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MoonSharp.Debugger.Properties.Resources", typeof(Resources).Assembly);
+                    resourceMan = temp;
+                }
+                return resourceMan;
+            }
+        }
+        
+        /// <summary>
+        ///   Overrides the current thread's CurrentUICulture property for all
+        ///   resource lookups using this strongly typed resource class.
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Globalization.CultureInfo Culture {
+            get {
+                return resourceCulture;
+            }
+            set {
+                resourceCulture = value;
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap AddConnection_477 {
+            get {
+                object obj = ResourceManager.GetObject("AddConnection_477", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap AddMark_10580 {
+            get {
+                object obj = ResourceManager.GetObject("AddMark_10580", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap Breakall_6323 {
+            get {
+                object obj = ResourceManager.GetObject("Breakall_6323", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap BreakpointEnabled_6584_16x {
+            get {
+                object obj = ResourceManager.GetObject("BreakpointEnabled_6584_16x", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap Clearallrequests_8816 {
+            get {
+                object obj = ResourceManager.GetObject("Clearallrequests_8816", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap DisassemblyWindow_6536 {
+            get {
+                object obj = ResourceManager.GetObject("DisassemblyWindow_6536", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap FindSymbol_6263 {
+            get {
+                object obj = ResourceManager.GetObject("FindSymbol_6263", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap Help_6522 {
+            get {
+                object obj = ResourceManager.GetObject("Help_6522", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap Open_6529 {
+            get {
+                object obj = ResourceManager.GetObject("Open_6529", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap Restart_6322 {
+            get {
+                object obj = ResourceManager.GetObject("Restart_6322", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap RPCThread_10388 {
+            get {
+                object obj = ResourceManager.GetObject("RPCThread_10388", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap startwithoutdebugging_6556 {
+            get {
+                object obj = ResourceManager.GetObject("startwithoutdebugging_6556", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap StepIn_6326 {
+            get {
+                object obj = ResourceManager.GetObject("StepIn_6326", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap Stepout_6327 {
+            get {
+                object obj = ResourceManager.GetObject("Stepout_6327", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap StepOver_6328 {
+            get {
+                object obj = ResourceManager.GetObject("StepOver_6328", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+    }
 }

+ 53 - 3
src/MoonSharp.Debugger/Properties/Resources.resx

@@ -46,7 +46,7 @@
     
     mimetype: application/x-microsoft.net.object.binary.base64
     value   : The object must be serialized with 
-            : System.Serialization.Formatters.Binary.BinaryFormatter
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
             : and then encoded with base64 encoding.
     
     mimetype: application/x-microsoft.net.object.soap.base64
@@ -60,6 +60,7 @@
             : and then encoded with base64 encoding.
     -->
   <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
     <xsd:element name="root" msdata:IsDataSet="true">
       <xsd:complexType>
         <xsd:choice maxOccurs="unbounded">
@@ -68,9 +69,10 @@
               <xsd:sequence>
                 <xsd:element name="value" type="xsd:string" minOccurs="0" />
               </xsd:sequence>
-              <xsd:attribute name="name" type="xsd:string" />
+              <xsd:attribute name="name" use="required" type="xsd:string" />
               <xsd:attribute name="type" type="xsd:string" />
               <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
             </xsd:complexType>
           </xsd:element>
           <xsd:element name="assembly">
@@ -85,9 +87,10 @@
                 <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                 <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
               </xsd:sequence>
-              <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
               <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
               <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
             </xsd:complexType>
           </xsd:element>
           <xsd:element name="resheader">
@@ -114,4 +117,51 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
+  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+  <data name="StepIn_6326" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\StepIn_6326.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="Stepout_6327" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\Stepout_6327.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="Restart_6322" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\Restart_6322.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="StepOver_6328" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\StepOver_6328.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="Open_6529" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\Open_6529.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="DisassemblyWindow_6536" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\DisassemblyWindow_6536.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="AddMark_10580" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\AddMark_10580.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="RPCThread_10388" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\RPCThread_10388.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="AddConnection_477" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\AddConnection_477.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="startwithoutdebugging_6556" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\startwithoutdebugging_6556.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="Help_6522" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\Help_6522.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="BreakpointEnabled_6584_16x" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\BreakpointEnabled_6584_16x.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="Clearallrequests_8816" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\Clearallrequests_8816.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="Breakall_6323" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\Breakall_6323.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+  <data name="FindSymbol_6263" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\FindSymbol_6263.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
 </root>

BIN
src/MoonSharp.Debugger/Resources/AddConnection_477.png


BIN
src/MoonSharp.Debugger/Resources/AddMark_10580.png


BIN
src/MoonSharp.Debugger/Resources/Breakall_6323.png


BIN
src/MoonSharp.Debugger/Resources/BreakpointEnabled_6584_16x.png


BIN
src/MoonSharp.Debugger/Resources/Clearallrequests_8816.png


BIN
src/MoonSharp.Debugger/Resources/DisassemblyWindow_6536.png


BIN
src/MoonSharp.Debugger/Resources/FindSymbol_6263.png


BIN
src/MoonSharp.Debugger/Resources/Help_6522.png


BIN
src/MoonSharp.Debugger/Resources/Open_6529.png


BIN
src/MoonSharp.Debugger/Resources/RPCThread_10388.png


BIN
src/MoonSharp.Debugger/Resources/Restart_6322.png


BIN
src/MoonSharp.Debugger/Resources/StepIn_6326.png


BIN
src/MoonSharp.Debugger/Resources/StepOver_6328.png


BIN
src/MoonSharp.Debugger/Resources/Stepout_6327.png


BIN
src/MoonSharp.Debugger/Resources/startwithoutdebugging_6556.png


+ 21 - 4
src/MoonSharp.Debugger/SourceCodeDebugControl.cs

@@ -17,11 +17,29 @@ namespace MoonSharp.Debugger
 		int m_XOffs = 0;
 		int m_ActiveLine = -1;
 		int m_CursorLine = 0;
+		Brush m_CursorBrush = new SolidBrush(Color.FromArgb(64, Color.White));
 
 		public int ActiveLine
 		{
 			get { return m_ActiveLine; }
-			set { m_ActiveLine = value; Invalidate(); }
+			set 
+			{
+				m_CursorLine = m_ActiveLine = value;
+				ScrollToIncludeLine(m_ActiveLine);
+				Invalidate(); 
+			}
+		}
+
+		private void ScrollToIncludeLine(int line)
+		{
+			if (line == m_Line)
+				return;
+
+			if (line < m_Line)
+				m_Line = line;
+
+			if (line > m_Line + (this.Height / this.Font.Height))
+				m_Line = line;
 		}
 
 		public int CursorLine
@@ -107,6 +125,8 @@ namespace MoonSharp.Debugger
 //					e.Graphics.FillRectangle(Brushes.DarkRed, 0, Y, Width, H);
 				}
 
+				if (i == m_CursorLine)
+					e.Graphics.FillRectangle(m_CursorBrush, -1, Y, Width + 1, H);
 
 				if (m_ActiveLine == i)
 				{
@@ -114,9 +134,6 @@ namespace MoonSharp.Debugger
 					e.Graphics.DrawRectangle(Pens.DarkBlue, 3, Y + 8, 14, 6);
 				}
 
-				if (i == m_CursorLine)
-					e.Graphics.FillRectangle(Brushes.Black, -1, Y, Width + 1, H);
-
 				string str = m_SourceCode[i];
 
 				if (m_XOffs != 0)

+ 102 - 0
src/MoonSharp.Debugger/WatchInputDialog.Designer.cs

@@ -0,0 +1,102 @@
+namespace MoonSharp.Debugger
+{
+	partial class WatchInputDialog
+	{
+		/// <summary>
+		/// Required designer variable.
+		/// </summary>
+		private System.ComponentModel.IContainer components = null;
+
+		/// <summary>
+		/// Clean up any resources being used.
+		/// </summary>
+		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+		protected override void Dispose(bool disposing)
+		{
+			if (disposing && (components != null))
+			{
+				components.Dispose();
+			}
+			base.Dispose(disposing);
+		}
+
+		#region Windows Form Designer generated code
+
+		/// <summary>
+		/// Required method for Designer support - do not modify
+		/// the contents of this method with the code editor.
+		/// </summary>
+		private void InitializeComponent()
+		{
+			this.txtWatch = new System.Windows.Forms.TextBox();
+			this.label1 = new System.Windows.Forms.Label();
+			this.btnOK = new System.Windows.Forms.Button();
+			this.btnCancel = new System.Windows.Forms.Button();
+			this.SuspendLayout();
+			// 
+			// txtWatch
+			// 
+			this.txtWatch.Location = new System.Drawing.Point(79, 15);
+			this.txtWatch.Name = "txtWatch";
+			this.txtWatch.Size = new System.Drawing.Size(238, 20);
+			this.txtWatch.TabIndex = 0;
+			// 
+			// label1
+			// 
+			this.label1.AutoSize = true;
+			this.label1.Location = new System.Drawing.Point(12, 18);
+			this.label1.Name = "label1";
+			this.label1.Size = new System.Drawing.Size(61, 13);
+			this.label1.TabIndex = 1;
+			this.label1.Text = "Add watch:";
+			// 
+			// btnOK
+			// 
+			this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
+			this.btnOK.Location = new System.Drawing.Point(183, 51);
+			this.btnOK.Name = "btnOK";
+			this.btnOK.Size = new System.Drawing.Size(64, 31);
+			this.btnOK.TabIndex = 2;
+			this.btnOK.Text = "OK";
+			this.btnOK.UseVisualStyleBackColor = true;
+			// 
+			// btnCancel
+			// 
+			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+			this.btnCancel.Location = new System.Drawing.Point(253, 51);
+			this.btnCancel.Name = "btnCancel";
+			this.btnCancel.Size = new System.Drawing.Size(64, 31);
+			this.btnCancel.TabIndex = 3;
+			this.btnCancel.Text = "Cancel";
+			this.btnCancel.UseVisualStyleBackColor = true;
+			// 
+			// WatchInputDialog
+			// 
+			this.AcceptButton = this.btnOK;
+			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+			this.CancelButton = this.btnCancel;
+			this.ClientSize = new System.Drawing.Size(338, 98);
+			this.Controls.Add(this.btnCancel);
+			this.Controls.Add(this.btnOK);
+			this.Controls.Add(this.label1);
+			this.Controls.Add(this.txtWatch);
+			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
+			this.MaximizeBox = false;
+			this.MinimizeBox = false;
+			this.Name = "WatchInputDialog";
+			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
+			this.Text = "Add new watch..";
+			this.ResumeLayout(false);
+			this.PerformLayout();
+
+		}
+
+		#endregion
+
+		private System.Windows.Forms.TextBox txtWatch;
+		private System.Windows.Forms.Label label1;
+		private System.Windows.Forms.Button btnOK;
+		private System.Windows.Forms.Button btnCancel;
+	}
+}

+ 32 - 0
src/MoonSharp.Debugger/WatchInputDialog.cs

@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace MoonSharp.Debugger
+{
+	public partial class WatchInputDialog : Form
+	{
+		public WatchInputDialog()
+		{
+			InitializeComponent();
+		}
+
+		public static string GetNewWatchName()
+		{
+			WatchInputDialog dlg = new WatchInputDialog();
+			var res = dlg.ShowDialog();
+
+			if (res == DialogResult.OK)
+				return dlg.txtWatch.Text;
+
+			return null;
+		}
+
+
+	}
+}

+ 120 - 0
src/MoonSharp.Debugger/WatchInputDialog.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 28 - 0
src/MoonSharp.Interpreter/Debugging/DebuggerAction.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.Debugging
+{
+	public class DebuggerAction
+	{
+		public enum ActionType
+		{
+			StepIn,
+			StepOver,
+			Run,
+			ToggleBreakpoint,
+			Refresh,
+			None,
+		}
+
+		public int InstructionPtr { get; set; }
+		public ActionType Action { get; set; }
+
+		public override string ToString()
+		{
+			return string.Format("{0}({1})", Action, InstructionPtr);
+		}
+	}
+}

+ 2 - 0
src/MoonSharp.Interpreter/Debugging/IDebugger.cs

@@ -10,5 +10,7 @@ namespace MoonSharp.Interpreter.Debugging
 	{
 		void SetSourceCode(Chunk byteCode, string[] code);
 		DebuggerAction GetAction(int ip);
+		void Update(WatchType watchType, List<WatchItem> items);
+		List<string> GetWatchItems();
 	}
 }

+ 18 - 0
src/MoonSharp.Interpreter/Debugging/WatchItem.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MoonSharp.Interpreter.Execution;
+
+namespace MoonSharp.Interpreter.Debugging
+{
+	public class WatchItem
+	{
+		public int Address { get; set; }
+		public int BasePtr { get; set; }
+		public int RetAddress { get; set; }
+		public string Name { get; set; }
+		public RValue Value { get; set; }
+		public LRef LValue { get; set; }
+	}
+}

+ 15 - 0
src/MoonSharp.Interpreter/Debugging/WatchType.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.Debugging
+{
+	public enum WatchType
+	{
+		Watches,
+		VStack,
+		CallStack,
+		Coroutines
+	}
+}

+ 5 - 5
src/MoonSharp.Interpreter/Execution/DataTypes/Closure.cs

@@ -9,9 +9,9 @@ namespace MoonSharp.Interpreter.Execution
 	{
 		public int ByteCodeLocation { get; private set; }
 
-		private List<RValue> closureValues = null;
+		private ClosureContext closureCtx = null;
 
-		private static List<RValue> emptyClosure = new List<RValue>();
+		private static ClosureContext emptyClosure = new ClosureContext();
 
 
 		internal Closure(int idx, LRef[] symbols, RuntimeScope scope)
@@ -19,14 +19,14 @@ namespace MoonSharp.Interpreter.Execution
 			ByteCodeLocation = idx;
 
 			if (symbols.Length > 0)
-				closureValues = symbols.Select(s => scope.Get(s)).ToList();
+				closureCtx = new ClosureContext(symbols, symbols.Select(s => scope.Get(s)));
 			else
-				closureValues = emptyClosure;
+				closureCtx = emptyClosure;
 		}
 
 		internal void EnterClosureBeforeCall(RuntimeScope scope)
 		{
-			scope.EnterClosure(closureValues);
+			scope.EnterClosure(closureCtx);
 		}
 
 	}

+ 6 - 0
src/MoonSharp.Interpreter/Execution/DataTypes/Table.cs

@@ -95,6 +95,12 @@ namespace MoonSharp.Interpreter.Execution
 			}
 		}
 
+		public bool HasStringSymbol(string symbol)
+		{
+			return m_StringSymbols.ContainsKey(symbol);
+		}
+
+
 		public RValue this[string key]
 		{
 			get 

+ 23 - 0
src/MoonSharp.Interpreter/Execution/Scopes/ClosureContext.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.Execution
+{
+	public class ClosureContext : List<RValue>
+	{
+		public string[] Symbols { get; private set; }
+
+		public ClosureContext(LRef[] symbols, IEnumerable<RValue> values)
+		{
+			Symbols = symbols.Select(s => s.i_Name).ToArray();
+			this.AddRange(values);
+		}
+
+		public ClosureContext()
+		{
+			Symbols = new string[0];
+		}
+	}
+}

+ 29 - 7
src/MoonSharp.Interpreter/Execution/Scopes/RuntimeScope.cs

@@ -11,9 +11,8 @@ namespace MoonSharp.Interpreter.Execution
 	{
 		Table m_GlobalTable;
 		FastStack<RValue> m_ScopeStack = new FastStack<RValue>(131072); // start with a 512KB scope stack
-//		FastStack<LRef> m_DebugStack = new FastStack<LRef>(131072); // start with a 512KB scope stack
 		FastStack<int> m_LocalBaseIndexes = new FastStack<int>(16384);
-		FastStack<List<RValue>> m_ClosureStack = new FastStack<List<RValue>>(4096);
+		FastStack<ClosureContext> m_ClosureStack = new FastStack<ClosureContext>(4096);
 		FastStack<RuntimeScopeFrame> m_ScopeFrames = new FastStack<RuntimeScopeFrame>(8192);
 
 		public RuntimeScope()
@@ -26,7 +25,7 @@ namespace MoonSharp.Interpreter.Execution
 			set { m_GlobalTable = value; }
 		}
 
-		public void EnterClosure(List<RValue> closureValues)
+		public void EnterClosure(ClosureContext closureValues)
 		{
 			m_ClosureStack.Push(closureValues);
 		}
@@ -64,7 +63,6 @@ namespace MoonSharp.Interpreter.Execution
 			if (size > 0)
 			{
 				m_ScopeStack.RemoveLast(size);
-				//m_DebugStack.RemoveLast(size);
 			}
 
 			if (frame.RestartOfBase)
@@ -125,8 +123,6 @@ namespace MoonSharp.Interpreter.Execution
 
 		public void Assign(LRef symref, RValue value)
 		{
-			// Debug.WriteLine(string.Format("Assigning {0} = {1}", symref, value));
-
 			switch (symref.i_Type)
 			{
 				case LRefType.Global:
@@ -141,7 +137,6 @@ namespace MoonSharp.Interpreter.Execution
 						if (v == null)
 							m_ScopeStack[lastBaseIdx + symref.i_Index] = v = new RValue();
 						v.Assign(value);
-						//m_ScopeStack[lastBaseIdx + symref.Index] = value.CloneAsWritable();
 					}
 					break;
 				case LRefType.Upvalue:
@@ -166,8 +161,35 @@ namespace MoonSharp.Interpreter.Execution
 			}
 		}
 
+		public LRef FindRefByName(string name)
+		{
+			for(int i = m_ScopeFrames.Count - 1; i >= 0; i--)
+			{
+				var frame = m_ScopeFrames[i];
+				
+				foreach(LRef l in frame.m_DebugSymbols)
+					if (l.i_Name == name)
+						return l;
+			
+				if (frame.RestartOfBase)
+					break;
+			}
 
+			if (m_ClosureStack.Count > 0)
+			{
+				var closure = m_ClosureStack.Peek(0);
 
+				for(int i = 0; i < closure.Symbols.Length; i++)
+					if (closure.Symbols[i] == name)
+					{
+						return LRef.Upvalue(name, i);
+					}
+			}
 
+			if (m_GlobalTable.HasStringSymbol(name))
+				return LRef.Global(name);
+
+			return null;
+		}
 	}
 }

+ 3 - 2
src/MoonSharp.Interpreter/Execution/VM/CallStackItem.cs

@@ -8,8 +8,9 @@ namespace MoonSharp.Interpreter.Execution.VM
 
 	public class CallStackItem
 	{
-		public int IP;
-		public int SP;
+		public int BasePointer;
+		public int ReturnAddress;
+		public int Debug_EntryPoint;
 	}
 
 }

+ 4 - 0
src/MoonSharp.Interpreter/Execution/VM/Chunk.cs

@@ -132,6 +132,10 @@ namespace MoonSharp.Interpreter.Execution.VM
 		{
 			Emit(new Instruction() { OpCode = OpCode.Debug, Name = str.Substring(0, Math.Min(32, str.Length)) });
 		}
+		public void DebugFn(string fnname)
+		{
+			Emit(new Instruction() { OpCode = OpCode.DebugFn, Name = fnname });
+		}
 
 		//[Conditional("EMIT_DEBUG_OPS")]
 		public void Debug(Antlr4.Runtime.Tree.IParseTree parseTree)

+ 2 - 0
src/MoonSharp.Interpreter/Execution/VM/Instruction.cs

@@ -33,6 +33,8 @@ namespace MoonSharp.Interpreter.Execution.VM
 				case OpCode.Exit:
 					append = string.Format("{0}{1}", GenSpaces(), FrameToString(Frame));
 					break;
+				case OpCode.DebugFn:
+					return string.Format("[[ function {0} ]]", Name);
 				case OpCode.Debug:
 					return string.Format("[[ {0} ]]", Name);
 				case OpCode.Load:

+ 2 - 1
src/MoonSharp.Interpreter/Execution/VM/OpCode.cs

@@ -11,7 +11,8 @@ namespace MoonSharp.Interpreter.Execution.VM
 		// Meta-opcodes
 		Nop,		// Does not perform any operation.
 		Invalid,	// Crashes the executor with an unrecoverable NotImplementedException.
-		Debug,		// Does not perform any operation.
+		Debug,		// Does not perform any operation. Used to help debugging.
+		DebugFn,	// Does not perform any operation. Used to help the debugger.
 
 		// Stack ops and assignment
 		Pop,		// Discards the topmost n elements from the v-stack. 

+ 42 - 0
src/MoonSharp.Interpreter/Execution/VM/Processor/Processor.cs

@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MoonSharp.Interpreter.DataStructs;
+using MoonSharp.Interpreter.Debugging;
+
+namespace MoonSharp.Interpreter.Execution.VM
+{
+	sealed partial class Processor
+	{
+		Chunk m_RootChunk;
+		Chunk m_CurChunk;
+		int m_InstructionPtr;
+
+		FastStack<RValue> m_ValueStack = new FastStack<RValue>(131072);
+		FastStack<CallStackItem> m_ExecutionStack = new FastStack<CallStackItem>(131072);
+		bool m_Terminate = false;
+		RuntimeScope m_Scope;
+		RValue[] m_TempRegs = new RValue[8];
+
+		IDebugger m_DebuggerAttached = null;
+		DebuggerAction.ActionType m_DebuggerCurrentAction = DebuggerAction.ActionType.None;
+		int m_DebuggerCurrentActionTarget = -1;
+
+		public Processor(Chunk rootChunk)
+		{
+			m_RootChunk = m_CurChunk = rootChunk;
+			m_InstructionPtr = 0;
+			m_Scope = new RuntimeScope();
+		}
+
+		public void Reset(Table global)
+		{
+			m_CurChunk = m_RootChunk;
+			m_InstructionPtr = 0;
+			m_Scope.GlobalTable = global;
+		}
+
+
+	}
+}

+ 144 - 0
src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_Debugger.cs

@@ -0,0 +1,144 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MoonSharp.Interpreter.DataStructs;
+using MoonSharp.Interpreter.Debugging;
+
+namespace MoonSharp.Interpreter.Execution.VM
+{
+	// This part is practically written procedural style - it looks more like C than C#.
+	// This is intentional so to avoid this-calls and virtual-calls as much as possible.
+	// Same reason for the "sealed" declaration.
+	sealed partial class Processor
+	{
+		internal void AttachDebugger(IDebugger debugger)
+		{
+			m_DebuggerAttached = debugger;
+		}
+
+		private void ListenDebugger(Instruction instr)
+		{
+			if (instr.Breakpoint)
+			{
+				m_DebuggerCurrentAction = DebuggerAction.ActionType.None;
+				m_DebuggerCurrentActionTarget = -1;
+			}
+
+			if (m_DebuggerCurrentAction == DebuggerAction.ActionType.Run)
+				return;
+
+			if (m_DebuggerCurrentAction == DebuggerAction.ActionType.StepOver && m_DebuggerCurrentActionTarget != m_InstructionPtr)
+				return;
+
+			RefreshDebugger();
+
+			while (true)
+			{
+				var action = m_DebuggerAttached.GetAction(m_InstructionPtr);
+
+				switch (action.Action)
+				{
+					case DebuggerAction.ActionType.StepIn:
+						m_DebuggerCurrentAction = DebuggerAction.ActionType.StepIn;
+						m_DebuggerCurrentActionTarget = -1;
+						return;
+					case DebuggerAction.ActionType.StepOver:
+						m_DebuggerCurrentAction = DebuggerAction.ActionType.StepOver;
+						m_DebuggerCurrentActionTarget = m_InstructionPtr + 1;
+						return;
+					case DebuggerAction.ActionType.Run:
+						m_DebuggerCurrentAction = DebuggerAction.ActionType.Run;
+						m_DebuggerCurrentActionTarget = -1;
+						return;
+					case DebuggerAction.ActionType.ToggleBreakpoint:
+						m_CurChunk.Code[action.InstructionPtr].Breakpoint = !m_CurChunk.Code[action.InstructionPtr].Breakpoint;
+						break;
+					case DebuggerAction.ActionType.Refresh:
+						RefreshDebugger();
+						break;
+					case DebuggerAction.ActionType.None:
+					default:
+						break;
+				}
+			}
+		}
+
+		private void RefreshDebugger()
+		{
+			List<string> watchList = m_DebuggerAttached.GetWatchItems();
+			List<WatchItem> callStack = Debugger_GetCallStack();
+			List<WatchItem> watches = Debugger_RefreshWatches(watchList);
+			List<WatchItem> vstack = Debugger_RefreshVStack();
+			m_DebuggerAttached.Update(WatchType.CallStack, callStack);
+			m_DebuggerAttached.Update(WatchType.Watches, watches);
+			m_DebuggerAttached.Update(WatchType.VStack, vstack);
+		}
+
+		private List<WatchItem> Debugger_RefreshVStack()
+		{
+			List<WatchItem> lwi = new List<WatchItem>();
+			for (int i = 0; i < Math.Min(16, m_ValueStack.Count); i++)
+			{
+				lwi.Add(new WatchItem()
+				{
+					Address = i,
+					Value = m_ValueStack.Peek(i)
+				});
+			}
+
+			return lwi;
+		}
+
+		private List<WatchItem> Debugger_RefreshWatches(List<string> watchList)
+		{
+			return watchList.Select(w => Debugger_RefreshWatch(w)).ToList();
+		}
+
+		private WatchItem Debugger_RefreshWatch(string name)
+		{
+			LRef L = m_Scope.FindRefByName(name);
+
+			if (L != null)
+			{
+				RValue v = m_Scope.Get(L);
+
+				return new WatchItem()
+				{
+					LValue = L,
+					Value = v,
+					Name = name
+				};
+			}
+			else
+			{
+				return new WatchItem() { Name = name };
+			}
+		}
+
+		private List<WatchItem> Debugger_GetCallStack()
+		{
+			List<WatchItem> wis = new List<WatchItem>();
+
+			for (int i = 0; i < m_ExecutionStack.Count; i++)
+			{
+				var c = m_ExecutionStack.Peek(i);
+
+				var I = m_CurChunk.Code[c.Debug_EntryPoint];
+
+				string callname = I.OpCode == OpCode.DebugFn ? I.Name : null;
+
+
+				wis.Add(new WatchItem()
+				{
+					Address = c.Debug_EntryPoint,
+					BasePtr = c.BasePointer,
+					RetAddress = c.ReturnAddress,
+					Name = callname
+				});
+			}
+
+			return wis;
+		}
+	}
+}

+ 9 - 152
src/MoonSharp.Interpreter/Execution/VM/Processor.cs → src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_InstructionLoop.cs

@@ -7,95 +7,8 @@ using MoonSharp.Interpreter.Debugging;
 
 namespace MoonSharp.Interpreter.Execution.VM
 {
-	sealed class Processor
+	sealed partial class Processor
 	{
-		Chunk m_RootChunk;
-		Chunk m_CurChunk;
-		int m_InstructionPtr;
-
-		FastStack<RValue> m_ValueStack = new FastStack<RValue>(131072);
-		FastStack<CallStackItem> m_ExecutionStack = new FastStack<CallStackItem>(131072);
-		bool m_Terminate = false;
-		RuntimeScope m_Scope;
-		RValue[] m_TempRegs = new RValue[8];
-
-		IDebugger m_DebuggerAttached = null;
-		DebuggerAction.ActionType m_DebuggerCurrentAction = DebuggerAction.ActionType.None;
-		int m_DebuggerCurrentActionTarget = -1;
-
-		public Processor(Chunk rootChunk)
-		{
-			m_RootChunk = m_CurChunk = rootChunk;
-			m_InstructionPtr = 0;
-			m_Scope = new RuntimeScope();
-		}
-
-		public void Reset(Table global)
-		{
-			m_CurChunk = m_RootChunk;
-			m_InstructionPtr = 0;
-			m_Scope.GlobalTable = global;
-		}
-
-
-		private RValue[] StackTopToArray(int items, bool pop)
-		{
-			RValue[] values = new RValue[items];
-
-			if (pop)
-			{
-				for (int i = 0; i < items; i++)
-				{
-					values[i] = m_ValueStack.Pop();
-				}
-			}
-			else
-			{
-				for (int i = 0; i < items; i++)
-				{
-					values[i] = m_ValueStack[m_ValueStack.Count - 1 - i];
-				}
-			}
-
-			return values;
-		}
-
-		private RValue[] StackTopToArrayReverse(int items, bool pop)
-		{
-			RValue[] values = new RValue[items];
-
-			if (pop)
-			{
-				for (int i = 0; i < items; i++)
-				{
-					values[items - 1 - i] = m_ValueStack.Pop();
-				}
-			}
-			else
-			{
-				for (int i = 0; i < items; i++)
-				{
-					values[items - 1 - i] = m_ValueStack[m_ValueStack.Count - 1 - i];
-				}
-			}
-
-			return values;
-		}
-
-		private string DumpValueStack()
-		{
-			int cnt = 6;
-			List<RValue> values = new List<RValue>();
-
-			for (int i = m_ValueStack.Count - 1; i >= 0 && cnt > 0; i--)
-			{
-				values.Add(m_ValueStack[i]);
-				cnt--;
-			}
-
-			return string.Join(", ", values.Select(s => s.ToString()).ToArray());
-		}
-
 		public RValue Execute()
 		{
 			while (m_InstructionPtr < m_CurChunk.Code.Count && !m_Terminate)
@@ -113,6 +26,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 				{
 					case OpCode.Nop:
 					case OpCode.Debug:
+					case OpCode.DebugFn:
 						break;
 					case OpCode.Pop:
 						m_ValueStack.RemoveLast(i.NumVal);
@@ -357,18 +271,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 			}
 		}
 
-		private void DebugInterface(Instruction i)
-		{
-			if (i.OpCode == OpCode.Debug)
-				Console.Write("    {0}", i);
-			else
-				Console.Write("{0:X8}  {1}", m_InstructionPtr, i);
-
-			Console.SetCursorPosition(40, Console.CursorTop);
-			Console.WriteLine("|| VS={1:X4}  XS={2:X4} || {0}", DumpValueStack(), m_ValueStack.Count, m_ExecutionStack.Count);
 
-			//Console.ReadKey();
-		}
 
 
 		private void ExecJFor(Instruction i)
@@ -443,17 +346,17 @@ namespace MoonSharp.Interpreter.Execution.VM
 		private int PopToBasePointer()
 		{
 			var xs = m_ExecutionStack.Pop();
-			m_ValueStack.CropAtCount(xs.SP);
-			return xs.IP;
+			m_ValueStack.CropAtCount(xs.BasePointer);
+			return xs.ReturnAddress;
 		}
 
 		private int PopExecStackAndCheckVStack(int vstackguard)
 		{
 			var xs = m_ExecutionStack.Pop();
-			if (vstackguard != xs.SP)
+			if (vstackguard != xs.BasePointer)
 				throw new InternalErrorException("StackGuard violation");
 
-			return xs.IP;
+			return xs.ReturnAddress;
 		}
 
 		private void ExecArgs(Instruction I)
@@ -480,8 +383,9 @@ namespace MoonSharp.Interpreter.Execution.VM
 				m_ValueStack.Push(new RValue(i.NumVal));
 				m_ExecutionStack.Push(new CallStackItem()
 				{
-					SP = m_ValueStack.Count,
-					IP = m_InstructionPtr,
+					BasePointer = m_ValueStack.Count,
+					ReturnAddress = m_InstructionPtr,
+					Debug_EntryPoint = fn.Function.ByteCodeLocation
 				});
 				m_InstructionPtr = fn.Function.ByteCodeLocation;
 				fn.Function.EnterClosureBeforeCall(m_Scope);
@@ -745,52 +649,5 @@ namespace MoonSharp.Interpreter.Execution.VM
 				}
 			}
 		}
-
-		internal void AttachDebugger(IDebugger debugger)
-		{
-			m_DebuggerAttached = debugger;
-		}
-
-		private void ListenDebugger(Instruction instr)
-		{
-			if (instr.Breakpoint)
-			{
-				m_DebuggerCurrentAction = DebuggerAction.ActionType.None;
-				m_DebuggerCurrentActionTarget = -1;
-			}
-
-			if (m_DebuggerCurrentAction == DebuggerAction.ActionType.Run)
-				return;
-
-			if (m_DebuggerCurrentAction == DebuggerAction.ActionType.StepOver && m_DebuggerCurrentActionTarget != m_InstructionPtr)
-				return;
-
-			var action = m_DebuggerAttached.GetAction(m_InstructionPtr);
-
-			while (true)
-			{
-				switch (action.Action)
-				{
-					case DebuggerAction.ActionType.StepIn:
-						m_DebuggerCurrentAction = DebuggerAction.ActionType.StepIn;
-						m_DebuggerCurrentActionTarget = -1;
-						return;
-					case DebuggerAction.ActionType.StepOver:
-						m_DebuggerCurrentAction = DebuggerAction.ActionType.StepOver;
-						m_DebuggerCurrentActionTarget = m_InstructionPtr + 1;
-						return;
-					case DebuggerAction.ActionType.Run:
-						m_DebuggerCurrentAction = DebuggerAction.ActionType.Run;
-						m_DebuggerCurrentActionTarget = -1;
-						return;
-					case DebuggerAction.ActionType.ToggleBreakpoint:
-						m_CurChunk.Code[action.InstructionPtr].Breakpoint = !m_CurChunk.Code[action.InstructionPtr].Breakpoint;
-						break;
-					case DebuggerAction.ActionType.None:
-					default:
-						break;
-				}
-			}
-		}
 	}
 }

+ 58 - 0
src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_UtilityFunctions.cs

@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MoonSharp.Interpreter.DataStructs;
+using MoonSharp.Interpreter.Debugging;
+
+namespace MoonSharp.Interpreter.Execution.VM
+{
+	sealed partial class Processor
+	{
+
+		private RValue[] StackTopToArray(int items, bool pop)
+		{
+			RValue[] values = new RValue[items];
+
+			if (pop)
+			{
+				for (int i = 0; i < items; i++)
+				{
+					values[i] = m_ValueStack.Pop();
+				}
+			}
+			else
+			{
+				for (int i = 0; i < items; i++)
+				{
+					values[i] = m_ValueStack[m_ValueStack.Count - 1 - i];
+				}
+			}
+
+			return values;
+		}
+
+		private RValue[] StackTopToArrayReverse(int items, bool pop)
+		{
+			RValue[] values = new RValue[items];
+
+			if (pop)
+			{
+				for (int i = 0; i < items; i++)
+				{
+					values[items - 1 - i] = m_ValueStack.Pop();
+				}
+			}
+			else
+			{
+				for (int i = 0; i < items; i++)
+				{
+					values[items - 1 - i] = m_ValueStack[m_ValueStack.Count - 1 - i];
+				}
+			}
+
+			return values;
+		}
+
+	}
+}

+ 9 - 1
src/MoonSharp.Interpreter/MoonSharp.Interpreter.csproj

@@ -59,6 +59,8 @@
     <Compile Include="Debugging\DebuggerAction.cs" />
     <Compile Include="Debugging\IDebugger.cs" />
     <Compile Include="Debugging\SourceCodeType.cs" />
+    <Compile Include="Debugging\WatchItem.cs" />
+    <Compile Include="Debugging\WatchType.cs" />
     <Compile Include="Diagnostics\Debug.cs" />
     <Compile Include="Errors\InternalErrorException.cs" />
     <Compile Include="Execution\Behaviours\Behaviour.cs" />
@@ -71,6 +73,7 @@
     <Compile Include="Execution\ExecutionFlow.cs" />
     <Compile Include="Execution\ExecutionFlowType.cs" />
     <Compile Include="Execution\DataTypes\CallbackFunction.cs" />
+    <Compile Include="Execution\Scopes\ClosureContext.cs" />
     <Compile Include="Execution\Scopes\LoopTracker.cs" />
     <Compile Include="Execution\Scopes\BuildTimeScope.cs" />
     <Compile Include="Execution\Scopes\BuildTimeScopeFrame.cs" />
@@ -90,8 +93,13 @@
     <Compile Include="Execution\VM\LoopTracker.cs" />
     <Compile Include="Execution\VM\Instruction.cs" />
     <Compile Include="Execution\VM\OpCode.cs" />
-    <Compile Include="Execution\VM\Processor.cs" />
     <Compile Include="Execution\VM\CallStackItem.cs" />
+    <Compile Include="Execution\VM\Processor\Processor.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Execution\VM\Processor\Processor_Debugger.cs" />
+    <Compile Include="Execution\VM\Processor\Processor_InstructionLoop.cs" />
+    <Compile Include="Execution\VM\Processor\Processor_UtilityFunctions.cs" />
     <Compile Include="Helpers\List_ExtensionMethods.cs" />
     <Compile Include="Grammar\Lua.g4.lexer.cs">
       <DependentUpon>Lua.g4</DependentUpon>

+ 4 - 6
src/MoonSharp.Interpreter/Tree/Expressions/FunctionDefinitionExpression.cs

@@ -94,14 +94,14 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 
 
 
-		public void Compile(Execution.VM.Chunk bc, Action afterDecl)
+		public void Compile(Chunk bc, Action afterDecl, string friendlyName)
 		{
 			bc.Closure(m_Closure.ToArray(), bc.GetJumpPointForNextInstruction() + 3);
 			afterDecl();
 
 			Instruction I = bc.Jump(OpCode.Jump, -1);
 
-			bc.Debug(this.TreeNode);
+			bc.DebugFn(friendlyName ?? "<anonymous>");
 
 			bc.Enter(m_StackFrame);
 
@@ -119,12 +119,10 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 		}
 
 
-		public override void Compile(Execution.VM.Chunk bc)
+		public override void Compile(Chunk bc)
 		{
-			Compile(bc, () => bc.Nop(null));
+			Compile(bc, () => bc.Nop(null), null);
 		}
 
-
-
 	}
 }

+ 9 - 2
src/MoonSharp.Interpreter/Tree/Statements/FunctionDefinitionStatement.cs

@@ -13,6 +13,7 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		LRef m_FuncName;
 		List<string> m_TableAccessors;
 		string m_MethodName;
+		string m_FriendlyName;
 
 		bool m_Local;
 		FunctionDefinitionExpression m_FuncDef;
@@ -42,10 +43,16 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			if (nameOfMethodAccessor != null || m_TableAccessors.Count > 0)
 			{
 				m_FuncName = lcontext.Scope.Find(fnname.Text);
+
+				m_FriendlyName = fnname.Text + "." + string.Join(".", m_TableAccessors.ToArray());
+
+				if (nameOfMethodAccessor != null)
+					m_FriendlyName += ":" + nameOfMethodAccessor;
 			}
 			else
 			{
 				m_FuncName = LRef.Global(fnname.Text);
+				m_FriendlyName = fnname.Text;
 			}
 
 			if (nameOfMethodAccessor != null)
@@ -66,7 +73,7 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			if (m_Local || m_MethodName == null)
 			{
 				bc.Symbol(m_FuncName);
-				m_FuncDef.Compile(bc, () => bc.Store());
+				m_FuncDef.Compile(bc, () => bc.Store(), m_FriendlyName);
 				return;
 			}
 			else
@@ -83,7 +90,7 @@ namespace MoonSharp.Interpreter.Tree.Statements
 
 				bc.IndexRef();
 
-				m_FuncDef.Compile(bc);
+				m_FuncDef.Compile(bc, () => bc.Nop(null), m_FriendlyName);
 
 				bc.Store();
 			}