Пример #1
0
        public Help(StudioCore Core)
        {
            this.Core   = Core;
            HideOnClose = true;

            InitializeComponent();

            webBrowser.ScriptErrorsSuppressed = true;

            try
            {
#if DEBUG
                string helpDocPath = @"..\..\..\Doc\main.html";
#else
                string helpDocPath = @"Doc\main.html";
#endif
                string fullPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), helpDocPath);

                Core.AddToOutput("Help Path: " + fullPath);
                webBrowser.Navigate(fullPath);
            }
            catch (Exception ex)
            {
                Debug.Log("Got exception: " + ex.ToString());
                Core.AddToOutput("Help exception: " + ex.ToString());
            }
            webBrowser.CanGoBackChanged    += new EventHandler(webBrowser_CanGoBackChanged);
            webBrowser.CanGoForwardChanged += new EventHandler(webBrowser_CanGoForwardChanged);
            toolStripBtnForward.Enabled     = webBrowser.CanGoForward;
            toolStripBtnBack.Enabled        = webBrowser.CanGoBack;
        }
Пример #2
0
        public void AddVirtualBreakpoints(Types.ASM.FileInfo ASMFileInfo)
        {
            if (ASMFileInfo == null)
            {
                return;
            }
            foreach (var virtualBP in ASMFileInfo.VirtualBreakpoints.Values)
            {
                virtualBP.IsVirtual = true;
                int globalLineIndex = -1;
                if (!ASMFileInfo.FindGlobalLineIndex(virtualBP.LineIndex, virtualBP.DocumentFilename, out globalLineIndex))
                {
                    Core.AddToOutput("Cannot assign breakpoint for line " + virtualBP.LineIndex + ", no address found" + System.Environment.NewLine);
                    continue;
                }
                int address = ASMFileInfo.FindLineAddress(globalLineIndex);
                if (address != -1)
                {
                    var existingBP = BreakpointAtAddress(address);

                    if (existingBP == null)
                    {
                        C64Studio.Types.Breakpoint bp = new C64Studio.Types.Breakpoint();

                        bp.LineIndex        = virtualBP.LineIndex;
                        bp.Address          = address;
                        bp.TriggerOnExec    = true;
                        bp.IsVirtual        = true;
                        bp.DocumentFilename = virtualBP.DocumentFilename;
                        bp.Virtual.Add(virtualBP);
                        virtualBP.Address = address;
                        // we just need any key (as null is not allowed)
                        if (!BreakPoints.ContainsKey("C64Studio.DebugBreakpoints"))
                        {
                            BreakPoints.Add("C64Studio.DebugBreakpoints", new List <C64Studio.Types.Breakpoint>());
                        }
                        BreakPoints["C64Studio.DebugBreakpoints"].Add(bp);
                        //AddBreakpoint( bp );
                        Debug.Log("Add virtual bp for $" + address.ToString("X4"));
                    }
                    else
                    {
                        // merge with existing
                        existingBP.TriggerOnExec = true;
                        existingBP.Virtual.Add(virtualBP);
                    }
                }
                else
                {
                    Core.AddToOutput("Cannot assign breakpoint for line " + virtualBP.LineIndex + ", no address found" + System.Environment.NewLine);
                }
            }
        }
Пример #3
0
        private bool InitDialects()
        {
            // hard code BASIC V2, this one simply MUST exist
            BASICDialects.Add("BASIC V2", Dialect.BASICV2);

            try
            {
                string basePath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;

                if (basePath.ToUpper().StartsWith("FILE:///"))
                {
                    basePath = basePath.Substring(8);
                }
                string dialectFilePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(basePath), "BASIC Dialects");

                var files = System.IO.Directory.GetFiles(dialectFilePath, "*.txt");

                foreach (var file in files)
                {
                    try
                    {
                        ReadBASICDialect(file);
                    }
                    catch (Exception ex)
                    {
                        Core.AddToOutput("Exception reading BASIC dialect file " + file + ": " + ex.Message + System.Environment.NewLine);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.AddToOutput("Exception reading BASIC dialect files: " + ex.Message + System.Environment.NewLine);
            }
            return(true);
        }
Пример #4
0
 public bool RunCommand(DocumentInfo Doc, string StepDesc, string Command)
 {
     if (!RunExternalCommand(Doc, Command))
     {
         Core.AddToOutput("-" + StepDesc + " step failed" + System.Environment.NewLine);
         return(false);
     }
     Core.AddToOutput("-" + StepDesc + " step successful" + System.Environment.NewLine);
     return(true);
 }
Пример #5
0
        public bool CheckEmulatorVersion(ToolInfo ToolRun)
        {
            if (ToolRun == null)
            {
                Core.AddToOutput("The emulator to run was not properly configured (ToolRun = null )");
                return(false);
            }

            return(true);
        }
Пример #6
0
        public bool NeedsRebuild(DocumentInfo DocInfo, string ConfigSetting)
        {
            if (DocInfo == null)
            {
                return(false);
            }
            // actual parsing and deducing dependencies if a rebuild is necessary!
            foreach (IDockContent dockContent in Core.MainForm.panelMain.Documents)
            {
                BaseDocument baseDoc = (BaseDocument)dockContent;

                if (baseDoc.Modified)
                {
                    return(true);
                }
            }

            if (DocInfo.Element != null)
            {
                foreach (var dependency in DocInfo.Element.ForcedDependency.DependentOnFile)
                {
                    ProjectElement elementDependency = DocInfo.Project.GetElementByFilename(dependency.Filename);
                    if (elementDependency == null)
                    {
                        Core.AddToOutput("Could not find dependency for " + dependency + System.Environment.NewLine);
                        return(true);
                    }
                    if (NeedsRebuild(elementDependency.DocumentInfo, ConfigSetting))
                    {
                        return(true);
                    }
                    foreach (var rebuildFile in m_RebuiltFiles)
                    {
                        if (GR.Path.IsPathEqual(elementDependency.DocumentInfo.DocumentFilename, rebuildFile))
                        {
                            Core.AddToOutput("Dependency " + elementDependency.DocumentInfo.DocumentFilename + " was rebuilt in this cycle, need to rebuild dependent element " + DocInfo.DocumentFilename + System.Environment.NewLine);
                            return(true);
                        }
                    }
                }
                if (DocInfo.DeducedDependency[ConfigSetting] != null)
                {
                    // custom build overrides output file -> always rebuild
                    if ((!string.IsNullOrEmpty(DocInfo.Element.Settings[ConfigSetting].CustomBuild)) &&
                        (!string.IsNullOrEmpty(DocInfo.Element.TargetFilename)))
                    {
                        Core.AddToOutput("Custom build always requires a rebuild" + System.Environment.NewLine);
                        return(true);
                    }

                    foreach (var dependency in DocInfo.Element.ExternalDependencies.DependentOnFile)
                    {
                        string fullPath = BuildFullPath(DocInfo.Project.Settings.BasePath, dependency.Filename);

                        DateTime fileTime = new DateTime();

                        try
                        {
                            if (System.IO.File.Exists(fullPath))
                            {
                                fileTime = System.IO.File.GetLastWriteTime(fullPath);
                            }
                        }
                        catch
                        {
                        }

                        if (fileTime != DocInfo.DeducedDependency[ConfigSetting].BuildState[fullPath])
                        {
                            Core.AddToOutput("External Dependency " + fullPath + " was modified, need to rebuild dependent element " + DocInfo.DocumentFilename + System.Environment.NewLine);

                            DocInfo.DeducedDependency[ConfigSetting].BuildState.Add(fullPath, fileTime);
                            return(true);
                        }
                    }
                }
                else
                {
                    // no build time stored yet, needs rebuild
                    DocInfo.DeducedDependency[ConfigSetting] = new DependencyBuildState();
                    return(true);
                }
            }
            if (DocInfo.Compilable)
            {
                if (!DocInfo.HasBeenSuccessfullyBuilt)
                {
                    return(true);
                }
            }
            if (DocInfo.Project == null)
            {
                return(true);
            }
            if (DocInfo.DeducedDependency[ConfigSetting] == null)
            {
                // no build time stored yet, needs rebuild
                DocInfo.DeducedDependency[ConfigSetting] = new DependencyBuildState();
                return(true);
            }
            foreach (KeyValuePair <string, DateTime> dependency in DocInfo.DeducedDependency[ConfigSetting].BuildState)
            {
                DateTime fileTime = new DateTime();

                try
                {
                    fileTime = System.IO.File.GetLastWriteTime(dependency.Key);
                }
                catch
                {
                }
                if (fileTime != dependency.Value)
                {
                    //Debug.Log( "File time differs for " + dependency.Key );
                    return(true);
                }
            }
            return(false);
        }
Пример #7
0
        public bool NeedsRebuild(DocumentInfo DocInfo, string ConfigSetting)
        {
            if (DocInfo == null)
            {
                return(false);
            }
            // actual parsing and deducing dependencies if a rebuild is necessary!
            foreach (IDockContent dockContent in Core.MainForm.panelMain.Documents)
            {
                BaseDocument baseDoc = (BaseDocument)dockContent;

                if (baseDoc.Modified)
                {
                    return(true);
                }
            }

            if (DocInfo.Element != null)
            {
                foreach (var dependency in DocInfo.Element.ForcedDependency.DependentOnFile)
                {
                    ProjectElement elementDependency = DocInfo.Project.GetElementByFilename(dependency.Filename);
                    if (elementDependency == null)
                    {
                        Core.AddToOutput("Could not find dependency for " + dependency + System.Environment.NewLine);
                        return(true);
                    }
                    if (NeedsRebuild(elementDependency.DocumentInfo, ConfigSetting))
                    {
                        return(true);
                    }
                    foreach (var rebuildFile in m_RebuiltFiles)
                    {
                        if (GR.Path.IsPathEqual(elementDependency.DocumentInfo.DocumentFilename, rebuildFile))
                        {
                            Core.AddToOutput("Dependency " + elementDependency.DocumentInfo.DocumentFilename + " was rebuilt in this cycle, need to rebuild dependent element " + DocInfo.DocumentFilename + System.Environment.NewLine);
                            return(true);
                        }
                    }
                }
            }
            if (DocInfo.Compilable)
            {
                if (!DocInfo.HasBeenSuccessfullyBuilt)
                {
                    return(true);
                }
            }
            if (DocInfo.Project == null)
            {
                return(true);
            }
            if (DocInfo.DeducedDependency[ConfigSetting] == null)
            {
                // no build time stored yet, needs rebuild
                DocInfo.DeducedDependency[ConfigSetting] = new DependencyBuildState();
                return(true);
            }
            foreach (KeyValuePair <string, DateTime> dependency in DocInfo.DeducedDependency[ConfigSetting].BuildState)
            {
                DateTime fileTime = new DateTime();

                try
                {
                    fileTime = System.IO.File.GetLastWriteTime(dependency.Key);
                }
                catch
                {
                }
                if (fileTime != dependency.Value)
                {
                    //Debug.Log( "File time differs for " + dependency.Key );
                    return(true);
                }
            }
            return(false);
        }
Пример #8
0
        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);
        }