private void startDebuggerToolStripMenuItem_Click(object sender, EventArgs e) { if (debugToolStripMenuItem.Enabled) { if (!startDebuggerToolStripMenuItem.Text.Equals("Continue")) { compileToolStripMenuItem_Click(sender, e); //TODO: How do we figure out if an error occured? dataTabs.Controls.Add(debugTabPage); debugTabPage.Focus(); startDebuggerToolStripMenuItem.Text = "Continue"; stepIntoToolStripMenuItem.Enabled = true; stepOverToolStripMenuItem.Enabled = true; stopDebuggerToolStripMenuItem.Enabled = true; buildToolStripMenuItem.Enabled = false; codeBox.ReadOnly = true; MacroGUI main = null; foreach (MacroGUI mg in macros) { if (mg.ToString().StartsWith("main", StringComparison.InvariantCultureIgnoreCase)) { main = mg; break; } } if (main != null) { ConsoleMessage(""); ConsoleMessage("Starting debugger"); //Setup main debugLine = main.opIndexes.Length > 0 ? main.opIndexes[0] : -1; callStackListBox.Items.Insert(0, main); if (debugLine != -1) { //Make sure we are at the first line main.lastLine = 0; HighlighLine(debugLine, Color.Red); } } else { stopDebuggerToolStripMenuItem_Click(sender, e); } } else { //TODO: Continue } } }
//This is really just a glorified, and manual version of Macro.Run private void debugStepping(object sender, EventArgs e, bool stepInto) { //Create the variable list List <Variable> opVars = new List <Variable>(); foreach (VariableGUI vg in variableListBox.Items) { opVars.Add(vg.var); } if (debugLine == -1) { MacroGUI omac = callStackListBox.Items[0] as MacroGUI; callStackListBox.Items.RemoveAt(0); if (callStackListBox.Items.Count == 0) { //No more code stopDebuggerToolStripMenuItem_Click(sender, e); } else { //Unwrap variables omac.macro.Cleanup(opVars); ReloadVars(opVars); //Go to parent macro MacroGUI mac = callStackListBox.Items[0] as MacroGUI; if (mac.lastLine + 1 >= mac.opIndexes.Length) { //Just go to the next line debugLine = mac.opIndexes[mac.lastLine++] + 1; } else { //We have another line we can go to debugLine = mac.opIndexes[++mac.lastLine]; } HighlighLine(debugLine, Color.Red); if (mac.lastLine >= mac.opIndexes.Length) { debugLine = -1; } } } else { MacroGUI mac = callStackListBox.Items[0] as MacroGUI; Instruction[] ops = mac.macro.GetInstructions(); //We always want to be on the current debug line when we run HighlighLine(debugLine, Color.Red); //Invoke if (ops[mac.lastLine] is Macro && stepInto) { //We want to cut off execution right away so we can jump to the macro Macro macro = ops[mac.lastLine] as Macro; //Find the MacroGUI int debugMacro = -1; for (int i = 0; i < macros.Count; i++) { if (macros[i].macro.Equals(macro)) { debugMacro = i; break; } } if (debugMacro == -1) { throw new InvalidOperationException("Macro not found"); } //Get the macro, push it onto the call stack, reset it's position, then go to the line mac = macros[debugMacro]; callStackListBox.Items.Insert(0, mac); mac.lastLine = 0; HighlighLine(debugLine = mac.opIndexes[mac.lastLine], Color.Red); //Wrap variables mac.macro.WrapVars(opVars); } else { string gotoLabel = null; bool isGoto, increment = true; int prevSize = 0; if (isGoto = ops[mac.lastLine] is Instruction.GotoInstruction) { prevSize = opVars.Count; } //Invoke the instruction ops[mac.lastLine].Run(opVars); //TODO: Figure out how to handle break points within a macro //Handle any gotos if (isGoto && prevSize != opVars.Count) { gotoLabel = opVars[opVars.Count - 1].Name; int jump = mac.macro.JumpIndex(gotoLabel); increment = false; if (jump == -1) { //We know how to cleanup a goto, we can ignore it opVars.Remove(Variable.FindVar(gotoLabel, opVars)); debugLine = -1; stepOverToolStripMenuItem_Click(sender, e); //It does exactly what we want, so why copy and paste? } else { prevSize = mac.lastLine; mac.lastLine = jump; HighlighLine(debugLine = mac.opIndexes[mac.lastLine], Color.Red); } } else { prevSize = mac.lastLine; } if (increment) { //We need to manually go to the next line mac.lastLine++; if (mac.lastLine >= mac.opIndexes.Length) { debugLine = -1; HighlighLine(mac.opIndexes[mac.opIndexes.Length - 1] + 1, Color.Red); //Jump to the end of the macro } else { HighlighLine(debugLine = mac.opIndexes[mac.lastLine], Color.Red); } } ops[prevSize].Cleanup(opVars); } ReloadVars(opVars); } }
private void macroListBox_DoubleClick(object sender, EventArgs e) { MacroGUI mac = macroListBox.SelectedItem as MacroGUI; GotoLine(mac.macroLine); }
private void callStackListBox_DoubleClick(object sender, EventArgs e) { MacroGUI mac = callStackListBox.SelectedItem as MacroGUI; GotoLine(mac.opIndexes[mac.lastLine]); }