internal bool StartProcess(ToolInfo toolRun, DocumentInfo Document) { bool error = false; RunProcess = new System.Diagnostics.Process(); RunProcess.StartInfo.FileName = toolRun.Filename; RunProcess.StartInfo.WorkingDirectory = Core.MainForm.FillParameters(toolRun.WorkPath, Document, true, out error); RunProcess.EnableRaisingEvents = true; return(!error); }
public void SetupDebugger(ToolInfo RunTool) { if (RunTool == null) { return; } if (RunTool.Filename.ToUpper().Contains("XMEGA65")) { Debugger = new XMEGA65RemoteDebugger(Core); } else if (RunTool.DebugArguments.ToUpper().Contains("-BINARYMONITOR")) { Debugger = new VICERemoteDebuggerBinaryInterface(Core); var viceDebugger = Debugger as VICERemoteDebuggerBinaryInterface; viceDebugger.DocumentEvent += new BaseDocument.DocumentEventHandler(Core.MainForm.Document_DocumentEvent); } else { Debugger = new VICERemoteDebugger(Core); var viceDebugger = Debugger as VICERemoteDebugger; viceDebugger.DocumentEvent += new BaseDocument.DocumentEventHandler(Core.MainForm.Document_DocumentEvent); } // default to currently visible memory view Debugger.SetAutoRefreshMemory(Core.MainForm.m_DebugMemory.MemoryStart, Core.MainForm.m_DebugMemory.MemorySize, Core.MainForm.m_DebugMemory.MemoryAsCPU ? MemorySource.AS_CPU : MemorySource.RAM); // pass on remembered wathes foreach (var watch in Core.MainForm.m_DebugWatch.m_WatchEntries) { Debugger.AddWatchEntry(watch); } Debugger.DebugEvent += Core.MainForm.Debugger_DebugEvent; }
public bool ReadFromBuffer(GR.Memory.ByteBuffer SettingsData) { IgnoredWarnings.Clear(); GR.IO.BinaryReader binReader = new GR.IO.BinaryReader(SettingsData.MemoryStream()); GR.IO.FileChunk chunkData = new GR.IO.FileChunk(); while (chunkData.ReadFromStream(binReader)) { switch (chunkData.Type) { case Types.FileChunk.SETTINGS_TOOL: { ToolInfo tool = new ToolInfo(); tool.FromChunk(chunkData); // sanitize args tool.CartArguments = tool.CartArguments.Replace("$(BuildTargetFilename)", "$(RunFilename)"); tool.PRGArguments = tool.PRGArguments.Replace("$(BuildTargetFilename)", "$(RunFilename)"); tool.WorkPath = tool.WorkPath.Replace("$(FilePath)", "$(RunPath)"); if (string.IsNullOrEmpty(tool.TrueDriveOnArguments)) { tool.TrueDriveOnArguments = "-truedrive +virtualdev"; tool.TrueDriveOffArguments = "+truedrive -virtualdev"; } if (tool.PRGArguments.Contains("-truedrive ")) { tool.PRGArguments = tool.PRGArguments.Replace("-truedrive ", ""); } if (tool.PRGArguments.Contains(" -truedrive")) { tool.PRGArguments = tool.PRGArguments.Replace(" -truedrive", ""); } ToolInfos.AddLast(tool); } break; case Types.FileChunk.SETTINGS_ACCELERATOR: { AcceleratorKey key = new AcceleratorKey(); key.FromChunk(chunkData); Accelerators.Add(key.Key, key); } break; case Types.FileChunk.SETTINGS_DPS_LAYOUT: { GR.IO.IReader binIn = chunkData.MemoryReader(); uint size = binIn.ReadUInt32(); GR.Memory.ByteBuffer tempData = new GR.Memory.ByteBuffer(); binIn.ReadBlock(tempData, size); SetLayoutFromData(tempData); } break; case Types.FileChunk.SETTINGS_SOUND: { GR.IO.IReader binIn = chunkData.MemoryReader(); PlaySoundOnSuccessfulBuild = (binIn.ReadUInt8() != 0); PlaySoundOnBuildFailure = (binIn.ReadUInt8() != 0); PlaySoundOnSearchFoundNoItem = (binIn.ReadUInt8() != 0); } break; case Types.FileChunk.SETTINGS_WINDOW: { GR.IO.IReader binIn = chunkData.MemoryReader(); MainWindowPlacement = binIn.ReadString(); } break; case Types.FileChunk.SETTINGS_TABS: { GR.IO.IReader binIn = chunkData.MemoryReader(); TabSize = binIn.ReadInt32(); if ((TabSize <= 0) || (TabSize >= 100)) { TabSize = 2; } AllowTabs = (binIn.ReadUInt8() != 0); TabConvertToSpaces = (binIn.ReadUInt8() != 0); } break; case Types.FileChunk.SETTINGS_FONT: { GR.IO.IReader binIn = chunkData.MemoryReader(); SourceFontFamily = binIn.ReadString(); SourceFontSize = (float)binIn.ReadInt32(); BASICUseNonC64Font = (binIn.ReadUInt8() != 0); BASICSourceFontFamily = binIn.ReadString(); BASICSourceFontSize = (float)binIn.ReadInt32(); if (BASICSourceFontSize <= 0) { BASICSourceFontSize = 9.0f; } } break; case Types.FileChunk.SETTINGS_SYNTAX_COLORING: { GR.IO.IReader binIn = chunkData.MemoryReader(); Types.SyntaxElement element = (C64Studio.Types.SyntaxElement)binIn.ReadUInt32(); Types.SyntaxColor color = new C64Studio.Types.SyntaxColor(GR.EnumHelper.GetDescription(element)); color.FGColor = binIn.ReadUInt32(); color.BGColor = binIn.ReadUInt32(); color.BGColorAuto = (binIn.ReadUInt32() != 0); SyntaxColoring.Add(element, color); } break; case Types.FileChunk.SETTINGS_UI: { GR.IO.IReader binIn = chunkData.MemoryReader(); ToolbarActiveMain = (binIn.ReadUInt8() == 1); ToolbarActiveDebugger = (binIn.ReadUInt8() == 1); } break; case Types.FileChunk.SETTINGS_RUN_EMULATOR: { GR.IO.IReader binIn = chunkData.MemoryReader(); TrueDriveEnabled = (binIn.ReadUInt8() != 0); } break; case Types.FileChunk.SETTINGS_DEFAULTS: { GR.IO.IReader binIn = chunkData.MemoryReader(); DefaultProjectBasePath = binIn.ReadString(); } break; case Types.FileChunk.SETTINGS_FIND_REPLACE: { GR.IO.IReader binIn = chunkData.MemoryReader(); LastFindIgnoreCase = (binIn.ReadUInt8() == 1); LastFindWholeWord = (binIn.ReadUInt8() == 1); LastFindRegexp = (binIn.ReadUInt8() == 1); LastFindWrap = (binIn.ReadUInt8() == 1); LastFindTarget = binIn.ReadUInt8(); int numFindArguments = binIn.ReadInt32(); for (int i = 0; i < numFindArguments; ++i) { FindArguments.Add(binIn.ReadString()); } int numReplaceArguments = binIn.ReadInt32(); for (int i = 0; i < numReplaceArguments; ++i) { ReplaceArguments.Add(binIn.ReadString()); } } break; case Types.FileChunk.SETTINGS_IGNORED_WARNINGS: { GR.IO.IReader binIn = chunkData.MemoryReader(); int numIgnoredWarnings = binIn.ReadInt32(); for (int i = 0; i < numIgnoredWarnings; ++i) { IgnoredWarnings.Add((C64Studio.Types.ErrorCode)binIn.ReadInt32()); } } break; case Types.FileChunk.SETTINGS_PANEL_DISPLAY_DETAILS: { GR.IO.IReader binIn = chunkData.MemoryReader(); string toolName = binIn.ReadString(); if (GenericTools.ContainsKey(toolName)) { uint length = binIn.ReadUInt32(); GR.Memory.ByteBuffer data = new GR.Memory.ByteBuffer(); binIn.ReadBlock(data, length); GenericTools[toolName].ApplyDisplayDetails(data); } } break; case Types.FileChunk.SETTINGS_BASIC_KEYMAP: { GR.IO.IReader binIn = chunkData.MemoryReader(); int numEntries = binIn.ReadInt32(); uint neutralLang = (uint)(System.Globalization.CultureInfo.CurrentCulture.KeyboardLayoutId & 0xff); if ((neutralLang != 7) && (neutralLang != 9)) { neutralLang = 9; } for (int i = 0; i < numEntries; ++i) { Keys key = (Keys)binIn.ReadUInt32(); Types.KeyboardKey cmdKey = (C64Studio.Types.KeyboardKey)binIn.ReadInt32(); var keyMapEntry = new KeymapEntry(); foreach (var entry in BASICKeyMap.DefaultKeymaps[neutralLang]) { if (entry.Value.KeyboardKey == cmdKey) { BASICKeyMap.Keymap[key] = entry.Value; break; } } } } break; case Types.FileChunk.SETTINGS_ASSEMBLER_EDITOR: { GR.IO.IReader binIn = chunkData.MemoryReader(); ASMHideLineNumbers = (binIn.ReadUInt8() != 0); } break; case Types.FileChunk.SETTINGS_BASIC_PARSER: { GR.IO.IReader binIn = chunkData.MemoryReader(); BASICStripSpaces = (binIn.ReadUInt8() != 0); } break; case Types.FileChunk.SETTINGS_ENVIRONMENT: { GR.IO.IReader binIn = chunkData.MemoryReader(); AutoOpenLastSolution = (binIn.ReadUInt8() != 0); } break; } } return(true); }
public bool DebugCompiledFile(DocumentInfo DocumentToDebug, DocumentInfo DocumentToRun) { if (DocumentToDebug == null) { Core.AddToOutput("Debug document not found, this is an internal error!"); return(false); } if (DocumentToDebug.Element == null) { Core.AddToOutput("Debugging " + DocumentToDebug.DocumentFilename + System.Environment.NewLine); } else { Core.AddToOutput("Debugging " + DocumentToDebug.Element.Name + System.Environment.NewLine); } ToolInfo toolRun = Core.DetermineTool(DocumentToRun, true); if (toolRun == null) { System.Windows.Forms.MessageBox.Show("No emulator tool has been configured yet!", "Missing emulator tool"); Core.AddToOutput("There is no emulator tool configured!"); return(false); } SetupDebugger(toolRun); if (!Debugger.CheckEmulatorVersion(toolRun)) { return(false); } DebuggedASMBase = DocumentToDebug; DebugBaseDocumentRun = DocumentToRun; Core.MainForm.m_DebugWatch.ReseatWatches(DocumentToDebug.ASMFileInfo); Debugger.ClearCaches(); MemoryViews.ForEach(mv => mv.MarkAllMemoryAsUnknown()); ReseatBreakpoints(DocumentToDebug.ASMFileInfo); AddVirtualBreakpoints(DocumentToDebug.ASMFileInfo); Debugger.ClearAllBreakpoints(); MarkedDocument = null; MarkedDocumentLine = -1; if (!Core.Executing.StartProcess(toolRun, DocumentToRun)) { return(false); } if (!System.IO.Directory.Exists(Core.Executing.RunProcess.StartInfo.WorkingDirectory.Trim(new char[] { '"' }))) { Core.AddToOutput("The determined working directory " + Core.Executing.RunProcess.StartInfo.WorkingDirectory + " does not exist" + System.Environment.NewLine); return(false); } // determine debug target type Types.CompileTargetType targetType = C64Studio.Types.CompileTargetType.NONE; if (DocumentToRun.Element != null) { targetType = DocumentToRun.Element.TargetType; } string fileToRun = ""; if (DocumentToRun.Element != null) { fileToRun = DocumentToRun.Element.TargetFilename; ProjectElement.PerConfigSettings configSetting = DocumentToRun.Element.Settings[DocumentToRun.Project.Settings.CurrentConfig.Name]; if (!string.IsNullOrEmpty(configSetting.DebugFile)) { targetType = configSetting.DebugFileType; } } if (targetType == C64Studio.Types.CompileTargetType.NONE) { targetType = Core.Compiling.m_LastBuildInfo.TargetType; } DebugType = targetType; string breakPointFile = PrepareAfterStartBreakPoints(); string command = toolRun.DebugArguments; if (Parser.ASMFileParser.IsCartridge(targetType)) { command = command.Replace("-initbreak 0x$(DebugStartAddressHex) ", ""); } if ((toolRun.PassLabelsToEmulator) && (DebuggedASMBase.ASMFileInfo != null)) { breakPointFile += DebuggedASMBase.ASMFileInfo.LabelsAsFile(EmulatorInfo.LabelFormat(toolRun)); } if (breakPointFile.Length > 0) { try { TempDebuggerStartupFilename = System.IO.Path.GetTempFileName(); System.IO.File.WriteAllText(TempDebuggerStartupFilename, breakPointFile); command += " -moncommands \"" + TempDebuggerStartupFilename + "\""; } catch (System.IO.IOException ioe) { System.Windows.Forms.MessageBox.Show(ioe.Message, "Error writing temporary file"); Core.AddToOutput("Error writing temporary file"); TempDebuggerStartupFilename = ""; return(false); } } //ParserASM.CompileTarget != Types.CompileTargetType.NONE ) ? ParserASM.CompileTarget : DocumentToRun.Element.TargetType; // need to adjust initial breakpoint address for late added store/load breakpoints? InitialBreakpointIsTemporary = true; //if ( BreakpointsToAddAfterStartup.Count > 0 ) { // yes LateBreakpointOverrideDebugStart = OverrideDebugStart; // special start addresses for different run types if (Parser.ASMFileParser.IsCartridge(targetType)) { OverrideDebugStart = Debugger.ConnectedMachine.InitialBreakpointAddressCartridge; } else { // directly after calling load from ram (as VICE does when autostarting a .prg file) // TODO - check with .t64, .tap, .d64 OverrideDebugStart = Debugger.ConnectedMachine.InitialBreakpointAddress; } } if ((DocumentToDebug.Project != null) && (LateBreakpointOverrideDebugStart == -1) && (!string.IsNullOrEmpty(DocumentToDebug.Project.Settings.CurrentConfig.DebugStartAddressLabel))) { int debugStartAddress = -1; if (!Core.MainForm.DetermineDebugStartAddress(DocumentToDebug, DocumentToDebug.Project.Settings.CurrentConfig.DebugStartAddressLabel, out debugStartAddress)) { Core.AddToOutput("Cannot determine value for debug start address from '" + DocumentToDebug.Project.Settings.CurrentConfig.DebugStartAddressLabel + "'" + System.Environment.NewLine); return(false); } if (debugStartAddress != 0) { InitialBreakpointIsTemporary = false; OverrideDebugStart = debugStartAddress; LateBreakpointOverrideDebugStart = debugStartAddress; } } if (Core.Settings.TrueDriveEnabled) { command = toolRun.TrueDriveOnArguments + " " + command; } else { command = toolRun.TrueDriveOffArguments + " " + command; } bool error = false; Core.Executing.RunProcess.StartInfo.Arguments = Core.MainForm.FillParameters(command, DocumentToRun, true, out error); if (error) { return(false); } if (Parser.ASMFileParser.IsCartridge(targetType)) { Core.Executing.RunProcess.StartInfo.Arguments += " " + Core.MainForm.FillParameters(toolRun.CartArguments, DocumentToRun, true, out error); } else { Core.Executing.RunProcess.StartInfo.Arguments += " " + Core.MainForm.FillParameters(toolRun.PRGArguments, DocumentToRun, true, out error); } if (error) { return(false); } Core.AddToOutput("Calling " + Core.Executing.RunProcess.StartInfo.FileName + " with " + Core.Executing.RunProcess.StartInfo.Arguments + System.Environment.NewLine); Core.Executing.RunProcess.Exited += new EventHandler(Core.MainForm.runProcess_Exited); Core.SetStatus("Running..."); Core.MainForm.SetGUIForWaitOnExternalTool(true); if (Core.Executing.RunProcess.Start()) { DateTime current = DateTime.Now; // new GTK VICE opens up with console window (yuck) which nicely interferes with WaitForInputIdle -> give it 5 seconds to open main window bool waitForInputIdleFailed = false; try { Core.Executing.RunProcess.WaitForInputIdle(5000); } catch (Exception ex) { Debug.Log("WaitForInputIdle failed: " + ex.ToString()); waitForInputIdleFailed = true; } // only connect with debugger if VICE int numConnectionAttempts = 1; if ((string.IsNullOrEmpty(Core.Executing.RunProcess.MainWindowTitle)) && (waitForInputIdleFailed)) { // assume GTK VICE numConnectionAttempts = 10; } if (EmulatorInfo.SupportsDebugging(toolRun)) { //Debug.Log( "Have " + numConnectionAttempts + " attempts" ); Core.AddToOutput("Connection attempt "); for (int i = 0; i < numConnectionAttempts; ++i) { //Debug.Log( "attempt" + i ); Core.AddToOutput((i + 1).ToString()); if (Debugger.ConnectToEmulator(Parser.ASMFileParser.IsCartridge(targetType))) { //Debug.Log( "-succeeded" ); Core.AddToOutput(" succeeded" + System.Environment.NewLine); Core.MainForm.m_CurrentActiveTool = toolRun; DebuggedProject = DocumentToRun.Project; Core.MainForm.AppState = Types.StudioState.DEBUGGING_RUN; Core.MainForm.SetGUIForDebugging(true); break; } // wait a second for (int j = 0; j < 20; ++j) { System.Threading.Thread.Sleep(50); System.Windows.Forms.Application.DoEvents(); } } if (Core.MainForm.AppState != Types.StudioState.DEBUGGING_RUN) { Core.AddToOutput("failed " + numConnectionAttempts + " times, giving up" + System.Environment.NewLine); return(false); } } else { Core.MainForm.m_CurrentActiveTool = toolRun; DebuggedProject = DocumentToRun.Project; Core.MainForm.AppState = Types.StudioState.DEBUGGING_RUN; Core.MainForm.SetGUIForDebugging(true); } } return(true); }