internal void DebugBreak()
        {
            if (Debugger == null)
            {
                Core.AddToOutput("No debugger attached");
                return;
            }

            if ((Core.MainForm.m_CurrentActiveTool != null) &&
                (!EmulatorInfo.SupportsDebugging(Core.MainForm.m_CurrentActiveTool)))
            {
                return;
            }

            if (Core.MainForm.AppState == Types.StudioState.DEBUGGING_RUN)
            {
                // send any command to break into the monitor again
                try
                {
                    Debugger.Break();

                    Core.Executing.BringStudioToForeground();
                }
                catch (Exception ex)
                {
                    Core.AddToOutput("Exception while debug break:" + ex.ToString());
                }

                Core.MainForm.AppState = Types.StudioState.DEBUGGING_BROKEN;
                FirstActionAfterBreak  = true;
                Core.MainForm.SetGUIForDebugging(true);
            }
        }
        public void StepOver()
        {
            if (Debugger == null)
            {
                Core.AddToOutput("No debugger attached");
                return;
            }

            if ((Core.MainForm.m_CurrentActiveTool != null) &&
                (!EmulatorInfo.SupportsDebugging(Core.MainForm.m_CurrentActiveTool)))
            {
                return;
            }
            if ((Core.MainForm.AppState == Types.StudioState.DEBUGGING_BROKEN) ||
                (Core.MainForm.AppState == Types.StudioState.DEBUGGING_RUN))
            {
                Core.MainForm.m_DebugMemory.InvalidateAllMemory();
                Debugger.StepOver();
                Debugger.RefreshRegistersAndWatches();
                Debugger.SetAutoRefreshMemory(Core.MainForm.m_DebugMemory.MemoryStart,
                                              Core.MainForm.m_DebugMemory.MemorySize,
                                              Core.MainForm.m_DebugMemory.MemoryAsCPU ? MemorySource.AS_CPU : MemorySource.RAM);
                Debugger.RefreshMemory(Core.MainForm.m_DebugMemory.MemoryStart,
                                       Core.MainForm.m_DebugMemory.MemorySize,
                                       Core.MainForm.m_DebugMemory.MemoryAsCPU ? MemorySource.AS_CPU : MemorySource.RAM);

                if (Core.MainForm.AppState == Types.StudioState.DEBUGGING_RUN)
                {
                    FirstActionAfterBreak = true;
                }
                Core.Executing.BringStudioToForeground();
                Core.MainForm.AppState = Types.StudioState.DEBUGGING_BROKEN;
                Core.MainForm.SetGUIForDebugging(true);
            }
        }
Example #3
0
        /// <summary>
        /// Updates Client Update Notes
        /// </summary>
        /// <param name="emuInfo"></param>
        public void SetPatchNotes(EmulatorInfo emuInfo)
        {
            emuInfo.Patches.Reverse();        // Up to date at the top

            string patchNotes = string.Empty; // Clear the Patch Notes area

            foreach (var patch in emuInfo.Patches)
            {
                patchNotes += $"\t\tVersion {patch.Version}:{Environment.NewLine + Environment.NewLine}";

                foreach (var change in patch.Changes)
                {
                    patchNotes += $"{change.Date.ToShortDateString()}:{Environment.NewLine} - {change.Value}{Environment.NewLine + Environment.NewLine}";
                }

                patchNotes += Environment.NewLine;
            }

            PatchNotes = patchNotes;

            emuInfo.Patches.Reverse();      // Revert in case this is needed elsewhere in future.
        }
        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.PrepareStartProcess(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 = RetroDevStudio.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 == RetroDevStudio.Types.CompileTargetType.NONE)
            {
                var lastBuildInfoOfThisFile = Core.Compiling.m_LastBuildInfo[DocumentToRun.FullPath];

                targetType = lastBuildInfoOfThisFile.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);
        }