コード例 #1
0
ファイル: Searching.cs プロジェクト: jeason0813/C64Studio
        internal string GetDocumentInfoText(DocumentInfo DocInfo)
        {
            string elementPath = "";

            if (System.IO.Path.IsPathRooted(DocInfo.FullPath))
            {
                elementPath = DocInfo.FullPath;
            }
            else if (DocInfo.Project != null)
            {
                elementPath = GR.Path.Normalize(GR.Path.Append(DocInfo.Project.Settings.BasePath, DocInfo.FullPath), false);
            }
            else
            {
                elementPath = DocInfo.FullPath;
            }

            if (DocInfo.BaseDoc != null)
            {
                if (DocInfo.BaseDoc is SourceASMEx)
                {
                    DateTime lastModificationTimeStamp = ((SourceASMEx)DocInfo.BaseDoc).LastChange;

                    if ((GR.Path.IsPathEqual(PreviousSearchedFile, elementPath)) &&
                        (lastModificationTimeStamp <= PreviousSearchedFileTimeStamp))
                    {
                        return(Core.Searching.PreviousSearchedFileContent);
                    }
                    PreviousSearchedFile          = elementPath;
                    PreviousSearchedFileTimeStamp = lastModificationTimeStamp;
                    PreviousSearchedFileContent   = ((SourceASMEx)DocInfo.BaseDoc).editSource.Text;
                    return(PreviousSearchedFileContent);
                }
                else if (DocInfo.BaseDoc is SourceBasicEx)
                {
                    PreviousSearchedFile = elementPath;
                    return(((SourceBasicEx)DocInfo.BaseDoc).editSource.Text);
                }
                else if (DocInfo.BaseDoc is Disassembler)
                {
                    PreviousSearchedFile = elementPath;
                    return(((Disassembler)DocInfo.BaseDoc).editDisassembly.Text);
                }
                return("");
            }

            // can we use cached text?
            bool cacheIsUpToDate = false;

            DateTime lastAccessTimeStamp;

            try
            {
                lastAccessTimeStamp = System.IO.File.GetLastWriteTime(elementPath);

                cacheIsUpToDate = (lastAccessTimeStamp <= PreviousSearchedFileTimeStamp);

                PreviousSearchedFileTimeStamp = lastAccessTimeStamp;
            }
            catch (Exception)
            {
            }

            if ((GR.Path.IsPathEqual(PreviousSearchedFile, elementPath)) &&
                (cacheIsUpToDate) &&
                (PreviousSearchedFileContent != null))
            {
                return(PreviousSearchedFileContent);
            }

            PreviousSearchedFileContent = GR.IO.File.ReadAllText(elementPath);
            PreviousSearchedFile        = elementPath;
            return(PreviousSearchedFileContent);
        }
コード例 #2
0
ファイル: BaseDocument.cs プロジェクト: mattuna15/C64Studio
 public void SetProjectElement(ProjectElement Element)
 {
     DocumentInfo = Element.DocumentInfo;
 }
コード例 #3
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);
        }
コード例 #4
0
ファイル: Compiling.cs プロジェクト: jeason0813/C64Studio
        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);
        }
コード例 #5
0
ファイル: Compiling.cs プロジェクト: sajmosia/C64Studio
        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)
                {
                    var project = Core.MainForm.m_Solution.GetProjectByName(dependency.Project);
                    if (project == null)
                    {
                        Core.AddToOutput("Could not find dependency project " + dependency.Project + " for " + dependency + System.Environment.NewLine);
                        return(true);
                    }

                    ProjectElement elementDependency = project.GetElementByFilename(dependency.Filename);
                    if (elementDependency == null)
                    {
                        Core.AddToOutput("Could not find dependency " + dependency.Filename + " in project " + dependency.Project + " 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);
        }
コード例 #6
0
        private bool RunExternalCommand(string Command, DocumentInfo CommandDocument)
        {
            m_LastReceivedOutputTime = System.DateTime.Now;

            string fullCommand = Command;
            string args        = "";

            if (Command.StartsWith("\""))
            {
                int nextQuote = Command.IndexOf('"', 1);
                if (nextQuote == -1)
                {
                    // invalid file
                    Core.AddToOutput("Invalid command specified (" + Command + ")");
                    return(false);
                }
                fullCommand = Command.Substring(1, nextQuote - 1);
                args        = Command.Substring(nextQuote + 1).Trim();
            }
            else if (Command.IndexOf(' ') != -1)
            {
                int spacePos = Command.IndexOf(' ');
                fullCommand = Command.Substring(0, spacePos);
                args        = Command.Substring(spacePos + 1).Trim();
            }

            fullCommand = "cmd.exe";

            bool error       = false;
            bool errorAtArgs = false;

            string command = Core.MainForm.FillParameters(Command, CommandDocument, false, out error);

            if (error)
            {
                return(false);
            }
            args = "/C \"" + command + "\"";
            args = Core.MainForm.FillParameters(args, CommandDocument, false, out errorAtArgs);
            if ((error) ||
                (errorAtArgs))
            {
                return(false);
            }


            //Debug.Log( "Args:" + args );
            //string command = fullCommand + " " + args;

            Core.AddToOutput(command + System.Environment.NewLine);

            m_ExternalProcess = new System.Diagnostics.Process();
            m_ExternalProcess.StartInfo.FileName         = fullCommand;
            m_ExternalProcess.StartInfo.WorkingDirectory = Core.MainForm.FillParameters("$(BuildTargetPath)", CommandDocument, false, out error);

            if (error)
            {
                return(false);
            }
            if (!System.IO.Directory.Exists(m_ExternalProcess.StartInfo.WorkingDirectory + "/"))
            {
                Core.AddToOutput("The determined working directory \"" + m_ExternalProcess.StartInfo.WorkingDirectory + "\" does not exist" + System.Environment.NewLine);
                return(false);
            }

            m_ExternalProcess.StartInfo.CreateNoWindow  = true;
            m_ExternalProcess.EnableRaisingEvents       = true;
            m_ExternalProcess.StartInfo.Arguments       = args;
            m_ExternalProcess.StartInfo.UseShellExecute = false;
            //m_ExternalProcess.Exited += new EventHandler( Core.MainForm.m_ExternalProcess_Exited );

            m_ExternalProcess.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(ExternalProcessOutputReceived);
            m_ExternalProcess.ErrorDataReceived  += new System.Diagnostics.DataReceivedEventHandler(ExternalProcessOutputReceived);
            m_ExternalProcess.StartInfo.RedirectStandardError  = true;
            m_ExternalProcess.StartInfo.RedirectStandardOutput = true;

            try
            {
                if (!m_ExternalProcess.Start())
                {
                    m_ExternalProcess.Close();
                    return(false);
                }
                m_ExternalProcess.BeginOutputReadLine();
                m_ExternalProcess.BeginErrorReadLine();
            }
            catch (Win32Exception ex)
            {
                m_ExternalProcess.Close();
                Core.AddToOutput(ex.Message + System.Environment.NewLine);
                return(false);
            }

            //Debug.Log( "=============Start" );
            while (!m_ExternalProcess.WaitForExit(5))
            {
                Application.DoEvents();
            }
            // DO NOT REMOVE: final DoEvents to let the app clear its invoke queue to the output display
            Application.DoEvents();
            //Debug.Log( "=============Done" );

            /*
             * // working wait
             * while ( ( System.DateTime.Now - m_LastReceivedOutputTime ).TotalMilliseconds < 500  )
             * {
             * Application.DoEvents();
             * System.Threading.Thread.Sleep( 20 );
             * }
             */

            bool success = (m_ExternalProcess.ExitCode == 0);

            if (!success)
            {
                Core.AddToOutput("External Command " + command + " exited with result code " + m_ExternalProcess.ExitCode.ToString() + System.Environment.NewLine);
            }
            m_ExternalProcess.Close();
            return(success);
        }