Пример #1
0
        private static void UpdateAssertBreakpoints()
        {
            List <Breakpoint> asserts = new List <Breakpoint>();

            foreach (CodeLabel label in LabelManager.GetLabels())
            {
                foreach (string commentLine in label.Comment.Split('\n'))
                {
                    Match m = LabelManager.AssertRegex.Match(commentLine);
                    if (m.Success)
                    {
                        asserts.Add(new Breakpoint()
                        {
                            BreakOnExec = true,
                            MemoryType  = label.AddressType.ToMemoryType(),
                            Address     = label.Address,
                            Condition   = "!(" + m.Groups[1].Value + ")"
                        });
                    }
                }
            }

            BreakpointManager.Asserts = asserts;
            BreakpointManager.SetBreakpoints();
        }
Пример #2
0
        private void OnNotificationReceived(NotificationEventArgs e)
        {
            switch (e.NotificationType)
            {
            case ConsoleNotificationType.GameLoaded: {
                if (ConfigManager.Config.Debug.Debugger.BreakOnPowerCycleReset)
                {
                    DebugApi.Step(1, StepType.PpuStep);
                }

                DebugState state = DebugApi.GetState();
                this.BeginInvoke((MethodInvoker)(() => {
                        DebugWorkspaceManager.ImportDbgFile();
                        DebugApi.RefreshDisassembly(_cpuType);
                        UpdateDebugger(state, null);
                        BreakpointManager.SetBreakpoints();
                    }));
                break;
            }

            case ConsoleNotificationType.GameReset:
                if (ConfigManager.Config.Debug.Debugger.BreakOnPowerCycleReset)
                {
                    DebugApi.Step(1, StepType.PpuStep);
                }
                break;

            case ConsoleNotificationType.PpuFrameDone:
                this.BeginInvoke((MethodInvoker)(() => {
                    UpdateContinueAction();
                }));
                break;

            case ConsoleNotificationType.CodeBreak: {
                BreakEvent evt           = (BreakEvent)Marshal.PtrToStructure(e.Parameter, typeof(BreakEvent));
                DebugState state         = DebugApi.GetState();
                int        activeAddress = _cpuType == CpuType.Cpu ? (int)((state.Cpu.K << 16) | state.Cpu.PC) : (int)state.Spc.PC;

                this.BeginInvoke((MethodInvoker)(() => {
                        ProcessBreakEvent(evt, state, activeAddress);

                        if (_firstBreak && !ConfigManager.Config.Debug.Debugger.BreakOnOpen)
                        {
                            DebugApi.ResumeExecution();
                        }
                        _firstBreak = false;
                    }));
                break;
            }
            }
        }
Пример #3
0
        private void OnNotificationReceived(NotificationEventArgs e)
        {
            switch (e.NotificationType)
            {
            case ConsoleNotificationType.GameLoaded: {
                if (ConfigManager.Config.Debug.Debugger.BreakOnPowerCycleReset)
                {
                    DebugApi.Step(_cpuType, 1, StepType.Step);
                }

                BreakpointManager.SetBreakpoints();

                DebugState state = DebugApi.GetState();
                this.BeginInvoke((MethodInvoker)(() => {
                        //Refresh workspace here as well as frmMain to ensure workspace
                        //is up-to-date no matter which form is notified first.
                        DebugWorkspaceManager.GetWorkspace();

                        bool isPowerCycle = e.Parameter.ToInt32() != 0;
                        if (!isPowerCycle)
                        {
                            DebugWorkspaceManager.AutoImportSymbols();
                        }
                        LabelManager.RefreshLabels();
                        DebugApi.RefreshDisassembly(_cpuType);
                        UpdateDebugger(state, null);
                    }));
                break;
            }

            case ConsoleNotificationType.GameReset:
                if (ConfigManager.Config.Debug.Debugger.BreakOnPowerCycleReset)
                {
                    DebugApi.Step(_cpuType, 1, StepType.PpuStep);
                }
                break;

            case ConsoleNotificationType.PpuFrameDone:
                this.BeginInvoke((MethodInvoker)(() => {
                    UpdateContinueAction();
                }));
                break;

            case ConsoleNotificationType.CodeBreak: {
                BreakEvent evt = (BreakEvent)Marshal.PtrToStructure(e.Parameter, typeof(BreakEvent));
                RefreshDebugger(evt);
                break;
            }
            }
        }
Пример #4
0
        private void _notifListener_OnNotification(InteropEmu.NotificationEventArgs e)
        {
            switch (e.NotificationType)
            {
            case InteropEmu.ConsoleNotificationType.CodeBreak:
                this.BeginInvoke((MethodInvoker)(() => UpdateDebugger()));
                BreakpointManager.SetBreakpoints();
                InteropEmu.DebugSetFlags(mnuPpuPartialDraw.Checked ? DebuggerFlags.PpuPartialDraw : DebuggerFlags.None);
                break;

            case InteropEmu.ConsoleNotificationType.GameReset:
            case InteropEmu.ConsoleNotificationType.GameLoaded:
                BreakpointManager.SetBreakpoints();
                InteropEmu.DebugStep(1);
                break;
            }
        }
Пример #5
0
 public static void ResetWorkspace()
 {
     if (_workspace != null)
     {
         lock (_lock) {
             if (_workspace != null)
             {
                 _workspace.Breakpoints = new List <Breakpoint>();
                 _workspace.Labels      = new List <CodeLabel>();
                 _workspace.WatchValues = new List <string>();
                 LabelManager.ResetLabels();
                 WatchManager.WatchEntries = _workspace.WatchValues;
                 BreakpointManager.SetBreakpoints(_workspace.Breakpoints);
                 _workspace.Save();
                 Clear();
             }
         }
     }
 }
Пример #6
0
        public static DebugWorkspace GetWorkspace()
        {
            string romName = InteropEmu.GetRomInfo().GetRomName();

            if (_workspace == null || _romName != romName)
            {
                SymbolProvider = null;
                lock (_lock) {
                    if (_workspace == null || _romName != romName)
                    {
                        if (_workspace != null)
                        {
                            SaveWorkspace();
                        }
                        _romName   = InteropEmu.GetRomInfo().GetRomName();
                        _workspace = DebugWorkspace.GetWorkspace();

                        //Setup labels
                        if (_workspace.Labels.Count == 0)
                        {
                            LabelManager.ResetLabels();
                            if (!ConfigManager.Config.DebugInfo.DisableDefaultLabels)
                            {
                                LabelManager.SetDefaultLabels(InteropEmu.GetRomInfo().MapperId);
                            }
                        }
                        else
                        {
                            LabelManager.ResetLabels();
                            LabelManager.SetLabels(_workspace.Labels, true);
                        }

                        //Load watch entries
                        WatchManager.WatchEntries = _workspace.WatchValues;

                        //Load breakpoints
                        BreakpointManager.SetBreakpoints(_workspace.Breakpoints);
                    }
                }
            }
            return(_workspace);
        }
Пример #7
0
        private void _notifListener_OnNotification(InteropEmu.NotificationEventArgs e)
        {
            switch (e.NotificationType)
            {
            case InteropEmu.ConsoleNotificationType.PpuFrameDone:
                if (ConfigManager.Config.DebugInfo.RefreshWatchWhileRunning)
                {
                    this.BeginInvoke((MethodInvoker)(() => ctrlWatch.UpdateWatch()));
                }
                break;

            case InteropEmu.ConsoleNotificationType.CodeBreak:
                this.BeginInvoke((MethodInvoker)(() => {
                    UpdateDebugger();
                    mnuContinue.Enabled = true;
                    mnuBreak.Enabled = false;
                }));
                BreakpointManager.SetBreakpoints();
                break;

            case InteropEmu.ConsoleNotificationType.GameReset:
            case InteropEmu.ConsoleNotificationType.GameLoaded:
                this.BeginInvoke((MethodInvoker)(() => {
                    this.UpdateWorkspace();
                    this.AutoLoadCdlFiles();
                    this.AutoLoadDbgFiles(true);
                    UpdateDebugger(true, false);
                    BreakpointManager.SetBreakpoints();

                    if (!ConfigManager.Config.DebugInfo.BreakOnReset)
                    {
                        ClearActiveStatement();
                    }
                }));

                if (ConfigManager.Config.DebugInfo.BreakOnReset)
                {
                    InteropEmu.DebugStep(1);
                }
                break;
            }
        }
Пример #8
0
        public static void SetupWorkspace(bool saveCurrentWorkspace = true)
        {
            string romName = InteropEmu.GetRomInfo().GetRomName();

            lock (_lock) {
                if (_workspace != null && _romName == romName)
                {
                    if (saveCurrentWorkspace)
                    {
                        SaveWorkspace();
                    }

                    //Setup labels
                    if (_workspace.Labels.Count == 0)
                    {
                        LabelManager.ResetLabels();
                        if (!ConfigManager.Config.DebugInfo.DisableDefaultLabels)
                        {
                            LabelManager.SetDefaultLabels(InteropEmu.FdsGetSideCount() > 0);
                        }
                    }
                    else
                    {
                        LabelManager.ResetLabels();
                        LabelManager.SetLabels(_workspace.Labels, false);
                    }

                    //Load watch entries
                    WatchManager.WatchEntries = _workspace.WatchValues;

                    //Load breakpoints
                    BreakpointManager.SetBreakpoints(_workspace.Breakpoints);
                }
                else
                {
                    Clear();
                }
            }
        }
Пример #9
0
        public static DebugWorkspace GetWorkspace()
        {
            string romName = InteropEmu.GetRomInfo().GetRomName();

            if (_workspace != null)
            {
                SaveWorkspace();
            }

            if (_workspace == null || _romName != romName)
            {
                SymbolProvider = null;
                lock (_lock) {
                    if (_workspace == null || _romName != romName)
                    {
                        _romName   = InteropEmu.GetRomInfo().GetRomName();
                        _workspace = DebugWorkspace.GetWorkspace();

                        //Load watch entries
                        WatchManager.WatchEntries = _workspace.WatchValues;

                        //Setup labels
                        if (_workspace.Labels.Count == 0 && !ConfigManager.Config.DebugInfo.DisableDefaultLabels)
                        {
                            LabelManager.SetDefaultLabels(InteropEmu.GetRomInfo().MapperId);
                        }
                    }
                }
            }

            //Send breakpoints & labels to emulation core (even if the same game is running)
            BreakpointManager.SetBreakpoints(_workspace.Breakpoints);
            LabelManager.RefreshLabels();

            return(_workspace);
        }
Пример #10
0
        private void OnNotificationReceived(NotificationEventArgs e)
        {
            switch (e.NotificationType)
            {
            case ConsoleNotificationType.GameLoaded: {
                if (_cpuType == CpuType.Sa1)
                {
                    CoprocessorType coprocessor = EmuApi.GetRomInfo().CoprocessorType;
                    if (coprocessor != CoprocessorType.SA1)
                    {
                        this.Invoke((MethodInvoker)(() => {
                                this.Close();
                            }));
                        return;
                    }
                }

                if (ConfigManager.Config.Debug.Debugger.BreakOnPowerCycleReset)
                {
                    DebugApi.Step(_cpuType, 1, StepType.PpuStep);
                }

                BreakpointManager.SetBreakpoints();

                DebugState state = DebugApi.GetState();
                this.BeginInvoke((MethodInvoker)(() => {
                        DebugWorkspaceManager.ImportDbgFile();
                        LabelManager.RefreshLabels();
                        DebugApi.RefreshDisassembly(_cpuType);
                        UpdateDebugger(state, null);
                    }));
                break;
            }

            case ConsoleNotificationType.GameReset:
                if (ConfigManager.Config.Debug.Debugger.BreakOnPowerCycleReset)
                {
                    DebugApi.Step(_cpuType, 1, StepType.PpuStep);
                }
                break;

            case ConsoleNotificationType.PpuFrameDone:
                this.BeginInvoke((MethodInvoker)(() => {
                    UpdateContinueAction();
                }));
                break;

            case ConsoleNotificationType.CodeBreak: {
                BreakEvent evt   = (BreakEvent)Marshal.PtrToStructure(e.Parameter, typeof(BreakEvent));
                DebugState state = DebugApi.GetState();
                int        activeAddress;
                switch (_cpuType)
                {
                case CpuType.Cpu: activeAddress = (int)((state.Cpu.K << 16) | state.Cpu.PC); break;

                case CpuType.Spc: activeAddress = (int)state.Spc.PC; break;

                case CpuType.Sa1: activeAddress = (int)((state.Sa1.K << 16) | state.Sa1.PC); break;

                case CpuType.Gsu: activeAddress = (int)((state.Gsu.ProgramBank << 16) | state.Gsu.R[15]); break;

                default: throw new Exception("Unsupported cpu type");
                }

                this.BeginInvoke((MethodInvoker)(() => {
                        ProcessBreakEvent(evt, state, activeAddress);

                        if (_firstBreak && !ConfigManager.Config.Debug.Debugger.BreakOnOpen)
                        {
                            DebugApi.ResumeExecution();
                        }
                        _firstBreak = false;
                    }));
                break;
            }
            }
        }
Пример #11
0
        public static void Import(string path, bool silent = false)
        {
            List <CodeLabel>  labels      = new List <CodeLabel>(1000);
            List <Breakpoint> breakpoints = new List <Breakpoint>(1000);

            int errorCount = 0;

            foreach (string row in File.ReadAllLines(path, Encoding.UTF8))
            {
                string lineData = row.Trim();
                if (lineData.StartsWith("<"))
                {
                    continue;                                           //this is a <command line>: operation and we don't want it
                }
                if (lineData.Contains(":="))
                {
                    continue;                                          //this is a "variable" we dont' want it
                }
                int splitIndex = lineData.IndexOf(' ');

                string[] parts = lineData.Substring(splitIndex + 1).Split('=');

                UInt32       address;
                string       value = parts[1].Trim();
                NumberStyles type  = NumberStyles.Integer;
                if (value.StartsWith("$"))
                {
                    type  = NumberStyles.HexNumber;
                    value = value.Substring(1);                     //remove the $
                }
                else if (value.StartsWith("%"))
                {
                    continue;                     // Binary values are not labels 99.99999999999999% of the time
                }

                if (!UInt32.TryParse(value, type, null, out address))
                {
                    errorCount++;
                    continue;
                }

                AddressInfo absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo()
                {
                    Address = (int)address, Type = SnesMemoryType.CpuMemory
                });

                if (absAddress.Address >= 0)
                {
                    if (parts[0].Contains("BREAK"))
                    {
                        //we have a break point
                        Breakpoint breakpoint = new Breakpoint();
                        breakpoint.Address     = address;
                        breakpoint.AddressType = BreakpointAddressType.SingleAddress;
                        breakpoint.BreakOnExec = true;
                        breakpoint.CpuType     = CpuType.Cpu;
                        breakpoints.Add(breakpoint);
                    }
                    else if (parts[0].Contains("ASSERT_"))
                    {
                        string assert_field = parts[0].Trim().ToLower().Substring(parts[0].IndexOf("ASSERT_") + 7);
                        string cond         = string.Empty;
                        if (assert_field == "a8")
                        {
                            cond = "(PS & 32) == 32";
                        }
                        else if (assert_field == "a16")
                        {
                            cond = "(PS & 32) == 0";
                        }
                        else if (assert_field == "xy8")
                        {
                            cond = "(PS & 16) == 16";
                        }
                        else if (assert_field == "xy16")
                        {
                            cond = "(PS & 16) == 0";
                        }
                        else if (assert_field == "axy8")
                        {
                            cond = "(PS & 48) == 48";
                        }
                        else if (assert_field == "axy16")
                        {
                            cond = "(PS & 48) == 32";
                        }
                        else if (assert_field == "jsl")
                        {
                            cond = "jslf == 1";
                        }
                        else if (assert_field == "jsr")
                        {
                            cond = "jslf == 0";
                        }
                        else
                        {
                            cond = assert_field.Replace("_0x", "_$");
                            cond = cond.Replace("_eq_", "==");
                            cond = cond.Replace("_lt_", "<");
                            cond = cond.Replace("_lte_", "<=");
                            cond = cond.Replace("_gt_", ">");
                            cond = cond.Replace("_gte_", ">=");
                            cond = cond.Replace("_ne_", "!=");
                            cond = cond.Replace("_and_", "&&");
                            cond = cond.Replace("_or_", "||");
                            cond = cond.Replace("_not_", "!");
                            cond = cond.Replace("_lbrac_", "(");
                            cond = cond.Replace("_rbrac_", ")");
                            cond = cond.Replace("_", " ");
                        }

                        Breakpoint breakpoint = new Breakpoint();
                        breakpoint.Address     = address;
                        breakpoint.AddressType = BreakpointAddressType.SingleAddress;
                        breakpoint.BreakOnExec = true;
                        breakpoint.CpuType     = CpuType.Cpu;
                        breakpoint.IsAssert    = true;
                        breakpoint.Condition   = "!(" + cond + ")";
                        breakpoints.Add(breakpoint);
                    }
                    else if (parts[0].Contains("WATCH_"))
                    {
                        string[]   watchParts = parts[0].Trim().ToLower().Split('_');
                        Breakpoint breakpoint = new Breakpoint();
                        breakpoint.CpuType     = CpuType.Cpu;
                        breakpoint.IsAssert    = false;
                        breakpoint.Condition   = String.Empty;
                        breakpoint.BreakOnExec = false;
                        int range = 1;
                        for (int i = 1; i < watchParts.Length; ++i)
                        {
                            switch (watchParts[i])
                            {
                            case "load":
                            case "read":
                                breakpoint.BreakOnRead = true;
                                break;

                            case "store":
                            case "write":
                                breakpoint.BreakOnWrite = true;
                                break;

                            case "readwrite":
                            case "writeread":
                            case "loadstore":
                            case "storeload":
                                breakpoint.BreakOnRead  = true;
                                breakpoint.BreakOnWrite = true;
                                break;

                            case "word":
                                range = 2;
                                break;

                            case "long":
                                range = 3;
                                break;
                            }
                        }
                        breakpoint.EndAddress = address - 1;
                        switch (range)
                        {
                        case 1:
                            breakpoint.StartAddress = address - 1;
                            breakpoint.AddressType  = BreakpointAddressType.SingleAddress;
                            break;

                        case 2:
                            breakpoint.StartAddress = address - 2;
                            breakpoint.AddressType  = BreakpointAddressType.AddressRange;
                            break;

                        case 3:
                            breakpoint.StartAddress = address - 3;
                            breakpoint.AddressType  = BreakpointAddressType.AddressRange;
                            break;
                        }
                        breakpoint.Address = breakpoint.StartAddress;
                        breakpoints.Add(breakpoint);
                    }
                    else
                    {
                        CodeLabel label = new CodeLabel();
                        label.Address    = (UInt32)absAddress.Address;
                        label.MemoryType = absAddress.Type;
                        label.Comment    = "";
                        string labelName = parts[0].Trim();
                        if (string.IsNullOrEmpty(labelName) || !LabelManager.LabelRegex.IsMatch(labelName))
                        {
                            errorCount++;
                        }
                        else
                        {
                            label.Label = labelName;
                            labels.Add(label);
                        }
                    }
                }
            }

            LabelManager.SetLabels(labels);
            BreakpointManager.SetBreakpoints(breakpoints);

            if (!silent)
            {
                string message = $"Import completed with {labels.Count} labels imported";
                if (errorCount > 0)
                {
                    message += $" and {errorCount} error(s)";
                }
                MessageBox.Show(message, "Mesen-S", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }