Example #1
0
 public static void ToggleBreakpoint(int address, bool toggleEnabled)
 {
     if (address >= 0)
     {
         Breakpoint breakpoint = BreakpointManager.GetMatchingBreakpoint(address);
         if (breakpoint != null)
         {
             if (toggleEnabled)
             {
                 breakpoint.SetEnabled(!breakpoint.Enabled);
             }
             else
             {
                 BreakpointManager.RemoveBreakpoint(breakpoint);
             }
         }
         else
         {
             breakpoint = new Breakpoint()
             {
                 BreakOnExec       = true,
                 Address           = (UInt32)address,
                 IsAbsoluteAddress = false,
                 Enabled           = true
             };
             BreakpointManager.AddBreakpoint(breakpoint);
         }
     }
 }
Example #2
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();
        }
Example #3
0
        public static void ToggleBreakpoint(AddressInfo info)
        {
            if (info.Address < 0)
            {
                return;
            }

            Breakpoint breakpoint = BreakpointManager.GetMatchingBreakpoint(info);

            if (breakpoint != null)
            {
                BreakpointManager.RemoveBreakpoint(breakpoint);
            }
            else
            {
                breakpoint = new Breakpoint()
                {
                    Enabled     = true,
                    BreakOnExec = true,
                    Address     = (UInt32)info.Address
                };

                if (info.Type != SnesMemoryType.PrgRom)
                {
                    breakpoint.BreakOnRead  = true;
                    breakpoint.BreakOnWrite = true;
                }

                breakpoint.MemoryType = info.Type;
                BreakpointManager.AddBreakpoint(breakpoint);
            }
        }
Example #4
0
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            DebuggerInfo cfg = ConfigManager.Config.Debug.Debugger;

            cfg.WindowSize       = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Size : this.Size;
            cfg.WindowLocation   = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Location : this.Location;
            cfg.SplitterDistance = ctrlSplitContainer.SplitterDistance;

            _entityBinder.UpdateObject();
            ConfigManager.ApplyChanges();

            switch (_cpuType)
            {
            case CpuType.Cpu: ConfigApi.SetDebuggerFlag(DebuggerFlags.CpuDebuggerEnabled, false); break;

            case CpuType.Spc: ConfigApi.SetDebuggerFlag(DebuggerFlags.SpcDebuggerEnabled, false); break;

            case CpuType.Sa1: ConfigApi.SetDebuggerFlag(DebuggerFlags.Sa1DebuggerEnabled, false); break;

            case CpuType.Gsu: ConfigApi.SetDebuggerFlag(DebuggerFlags.GsuDebuggerEnabled, false); break;
            }

            BreakpointManager.RemoveCpuType(_cpuType);

            if (this._notifListener != null)
            {
                this._notifListener.Dispose();
                this._notifListener = null;
            }
        }
Example #5
0
        void ProcessBreakEvent(BreakEvent evt, DebugState state, int activeAddress)
        {
            if (ConfigManager.Config.Debug.Debugger.BringToFrontOnBreak)
            {
                Breakpoint bp = BreakpointManager.GetBreakpointById(evt.BreakpointId);
                if (bp?.CpuType == _cpuType || evt.Source > BreakSource.PpuStep)
                {
                    DebugWindowManager.BringToFront(this);
                }
            }

            UpdateContinueAction();
            UpdateDebugger(state, activeAddress);

            if (evt.Source == BreakSource.Breakpoint || evt.Source > BreakSource.PpuStep)
            {
                string message = ResourceHelper.GetEnumText(evt.Source);
                if (evt.Source == BreakSource.Breakpoint)
                {
                    message += ": " + ResourceHelper.GetEnumText(evt.Operation.Type) + " ($" + evt.Operation.Address.ToString("X4") + ":$" + evt.Operation.Value.ToString("X2") + ")";
                }
                ctrlDisassemblyView.SetMessage(new TextboxMessageInfo()
                {
                    Message = message
                });
            }
        }
Example #6
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.Text      = _cpuType == CpuType.Cpu ? "CPU Debugger" : "SPC Debugger";
            _notifListener = new NotificationListener();
            _notifListener.OnNotification += OnNotificationReceived;

            switch (_cpuType)
            {
            case CpuType.Cpu: ctrlDisassemblyView.Initialize(new CpuDisassemblyManager(), new CpuLineStyleProvider()); break;

            case CpuType.Spc: ctrlDisassemblyView.Initialize(new SpcDisassemblyManager(), new SpcLineStyleProvider()); break;
            }

            ctrlBreakpoints.CpuType = _cpuType;
            ctrlWatch.CpuType       = _cpuType;

            InitShortcuts();
            InitToolbar();
            LoadConfig();

            toolTip.SetToolTip(picWatchHelp, ctrlWatch.GetTooltipText());

            ConfigApi.SetDebuggerFlag(_cpuType == CpuType.Cpu ? DebuggerFlags.CpuDebuggerEnabled : DebuggerFlags.SpcDebuggerEnabled, true);
            BreakpointManager.AddCpuType(_cpuType);
            DebugApi.Step(10000, StepType.CpuStep);
        }
Example #7
0
        public static void EnableDisableBreakpoint(AddressInfo info)
        {
            Breakpoint breakpoint = BreakpointManager.GetMatchingBreakpoint(info);

            if (breakpoint != null)
            {
                breakpoint.SetEnabled(!breakpoint.Enabled);
            }
        }
Example #8
0
		public static bool EnableDisableBreakpoint(AddressInfo info, CpuType cpuType)
		{
			Breakpoint breakpoint = BreakpointManager.GetMatchingBreakpoint(info, cpuType);
			if(breakpoint != null) {
				breakpoint.SetEnabled(!breakpoint.Enabled);
				return true;
			}
			return false;
		}
Example #9
0
        public static bool EnableDisableBreakpoint(AddressInfo info)
        {
            Breakpoint breakpoint = BreakpointManager.GetMatchingBreakpoint(info);

            if (breakpoint != null)
            {
                breakpoint.SetEnabled(!breakpoint.Enabled);
                return(true);
            }
            return(false);
        }
Example #10
0
        private Breakpoint GetCurrentLineBreakpoint()
        {
            AddressTypeInfo addressInfo = GetAddressInfo(ctrlCodeViewer.SelectedLine);

            if (addressInfo.Address >= 0)
            {
                int relativeAddress = InteropEmu.DebugGetRelativeAddress((uint)addressInfo.Address, addressInfo.Type);
                return(BreakpointManager.GetMatchingBreakpoint(relativeAddress, addressInfo));
            }
            return(null);
        }
Example #11
0
        private void ctrlCodeViewer_MouseDown(object sender, MouseEventArgs e)
        {
            _tooltipManager.Close();

            if (e.Button == MouseButtons.Left && e.Location.X < this.ctrlCodeViewer.CodeMargin / 4)
            {
                int             relativeAddress = ctrlCodeViewer.GetLineNumberAtPosition(e.Y);
                AddressTypeInfo info            = GetAddressInfo(ctrlCodeViewer.GetLineIndexAtPosition(e.Y));
                BreakpointManager.ToggleBreakpoint(relativeAddress, info, false);
            }
        }
Example #12
0
        protected override void OnLoad(EventArgs e)
        {
            _notifListener = new NotificationListener();
            _notifListener.OnNotification += OnNotificationReceived;

            switch (_cpuType)
            {
            case CpuType.Cpu:
                ctrlDisassemblyView.Initialize(new CpuDisassemblyManager(), new CpuLineStyleProvider());
                ConfigApi.SetDebuggerFlag(DebuggerFlags.CpuDebuggerEnabled, true);
                this.Text = "CPU Debugger";
                break;

            case CpuType.Spc:
                ctrlDisassemblyView.Initialize(new SpcDisassemblyManager(), new SpcLineStyleProvider());
                ConfigApi.SetDebuggerFlag(DebuggerFlags.SpcDebuggerEnabled, true);
                this.Text = "SPC Debugger";
                break;

            case CpuType.Sa1:
                ctrlDisassemblyView.Initialize(new Sa1DisassemblyManager(), new Sa1LineStyleProvider());
                ConfigApi.SetDebuggerFlag(DebuggerFlags.Sa1DebuggerEnabled, true);
                this.Text = "SA-1 Debugger";
                break;

            case CpuType.Gsu:
                ctrlDisassemblyView.Initialize(new GsuDisassemblyManager(), new GsuLineStyleProvider());
                ConfigApi.SetDebuggerFlag(DebuggerFlags.GsuDebuggerEnabled, true);
                this.Text                  = "GSU Debugger";
                ctrlCallstack.Visible      = false;
                ctrlLabelList.Visible      = false;
                mnuStepOver.Visible        = false;
                mnuStepOut.Visible         = false;
                mnuStepInto.Text           = "Step";
                tlpBottomPanel.ColumnCount = 2;
                break;
            }

            ctrlBreakpoints.CpuType = _cpuType;
            ctrlWatch.CpuType       = _cpuType;

            InitShortcuts();
            InitToolbar();
            LoadConfig();

            toolTip.SetToolTip(picWatchHelp, ctrlWatch.GetTooltipText());

            BreakpointManager.AddCpuType(_cpuType);
            DebugApi.Step(_cpuType, 10000, StepType.Step);

            base.OnLoad(e);
        }
Example #13
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;
            }
            }
        }
Example #14
0
        public static void ToggleBreakpoint(int relativeAddress, AddressTypeInfo info, bool toggleEnabled)
        {
            if (relativeAddress >= 0 || info.Address >= 0)
            {
                Breakpoint breakpoint = BreakpointManager.GetMatchingBreakpoint(relativeAddress, info);
                if (breakpoint != null)
                {
                    if (toggleEnabled)
                    {
                        breakpoint.SetEnabled(!breakpoint.Enabled);
                    }
                    else
                    {
                        BreakpointManager.RemoveBreakpoint(breakpoint);
                    }
                }
                else
                {
                    if (info.Address < 0 || info.Type == AddressType.InternalRam)
                    {
                        breakpoint = new Breakpoint()
                        {
                            MemoryType   = DebugMemoryType.CpuMemory,
                            BreakOnExec  = true,
                            BreakOnRead  = true,
                            BreakOnWrite = true,
                            Address      = (UInt32)relativeAddress,
                            Enabled      = true
                        };
                    }
                    else
                    {
                        breakpoint = new Breakpoint()
                        {
                            Enabled     = true,
                            BreakOnExec = true,
                            Address     = (UInt32)info.Address
                        };

                        if (info.Type != AddressType.PrgRom)
                        {
                            breakpoint.BreakOnRead  = true;
                            breakpoint.BreakOnWrite = true;
                        }

                        breakpoint.MemoryType = info.Type.ToMemoryType();
                    }
                    BreakpointManager.AddBreakpoint(breakpoint);
                }
            }
        }
Example #15
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;
            }
            }
        }
Example #16
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;
            }
        }
Example #17
0
        private void ctrlCodeViewer_MouseDown(object sender, MouseEventArgs e)
        {
            if (_codeTooltip != null)
            {
                _codeTooltip.Close();
                _codeTooltip = null;
            }

            int address = ctrlCodeViewer.GetLineNumberAtPosition(e.Y);

            _lineBreakpoint = BreakpointManager.GetMatchingBreakpoint(address);

            if (e.Button == MouseButtons.Left && e.Location.X < this.ctrlCodeViewer.CodeMargin / 4)
            {
                BreakpointManager.ToggleBreakpoint(address, false);
            }
        }
Example #18
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();
             }
         }
     }
 }
Example #19
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;
            }
        }
Example #20
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);
        }
Example #21
0
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);


            DebuggerInfo cfg = ConfigManager.Config.Debug.Debugger;

            cfg.WindowSize     = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Size : this.Size;
            cfg.WindowLocation = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Location : this.Location;
            _entityBinder.UpdateObject();
            ConfigManager.ApplyChanges();

            ConfigApi.SetDebuggerFlag(_cpuType == CpuType.Cpu ? DebuggerFlags.CpuDebuggerEnabled : DebuggerFlags.SpcDebuggerEnabled, false);
            BreakpointManager.RemoveCpuType(_cpuType);

            if (this._notifListener != null)
            {
                this._notifListener.Dispose();
                this._notifListener = null;
            }
        }
Example #22
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();
                }
            }
        }
Example #23
0
        private void ctrlCodeViewer_MouseDown(object sender, MouseEventArgs e)
        {
            int address = ctrlCodeViewer.GetLineNumberAtPosition(e.Y);

            _lineBreakpoint = BreakpointManager.GetMatchingBreakpoint(address);

            if (e.Location.X < this.ctrlCodeViewer.CodeMargin / 5)
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    if (_lineBreakpoint == null)
                    {
                        Breakpoint bp = new Breakpoint();
                        bp.Address     = (UInt32)address;
                        bp.BreakOnExec = true;
                        BreakpointManager.AddBreakpoint(bp);
                    }
                    else
                    {
                        BreakpointManager.RemoveBreakpoint(_lineBreakpoint);
                    }
                }
            }
        }
Example #24
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);
        }
Example #25
0
 private void mnuEditBreakpoint_Click(object sender, EventArgs e)
 {
     BreakpointManager.EditBreakpoint(GetCurrentLineBreakpoint());
 }
Example #26
0
        private void ctrlHexViewer_InitializeContextMenu(object sender, EventArgs evt)
        {
            HexBox hexBox = (HexBox)sender;

            var mnuEditLabel = new ToolStripMenuItem();

            mnuEditLabel.Click += (s, e) => {
                UInt32 address = (UInt32)hexBox.SelectionStart;
                if (this._memoryType == DebugMemoryType.CpuMemory)
                {
                    AddressTypeInfo info = new AddressTypeInfo();
                    InteropEmu.DebugGetAbsoluteAddressAndType(address, ref info);
                    ctrlLabelList.EditLabel((UInt32)info.Address, info.Type);
                }
                else
                {
                    ctrlLabelList.EditLabel(address, GetAddressType().Value);
                }
            };

            var mnuEditBreakpoint = new ToolStripMenuItem();

            mnuEditBreakpoint.Click += (s, e) => {
                UInt32 startAddress = (UInt32)hexBox.SelectionStart;
                UInt32 endAddress   = (UInt32)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1)));
                BreakpointAddressType addressType = startAddress == endAddress ? BreakpointAddressType.SingleAddress : BreakpointAddressType.AddressRange;

                Breakpoint bp = BreakpointManager.GetMatchingBreakpoint(startAddress, endAddress, this._memoryType == DebugMemoryType.PpuMemory);
                if (bp == null)
                {
                    bp = new Breakpoint()
                    {
                        Address = startAddress, StartAddress = startAddress, EndAddress = endAddress, AddressType = addressType, IsAbsoluteAddress = false
                    };
                    if (this._memoryType == DebugMemoryType.CpuMemory)
                    {
                        bp.BreakOnWrite = bp.BreakOnRead = true;
                    }
                    else
                    {
                        bp.BreakOnWriteVram = bp.BreakOnReadVram = true;
                    }
                }
                BreakpointManager.EditBreakpoint(bp);
            };

            var mnuAddWatch = new ToolStripMenuItem();

            mnuAddWatch.Click += (s, e) => {
                UInt32   startAddress = (UInt32)hexBox.SelectionStart;
                UInt32   endAddress   = (UInt32)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1)));
                string[] toAdd        = Enumerable.Range((int)startAddress, (int)(endAddress - startAddress + 1)).Select((num) => $"[${num.ToString("X4")}]").ToArray();
                WatchManager.AddWatch(toAdd);
            };

            var mnuMarkSelectionAs = new ToolStripMenuItem();
            var mnuMarkAsCode      = new ToolStripMenuItem();

            mnuMarkAsCode.Text   = "Verified Code";
            mnuMarkAsCode.Click += (s, e) => {
                int startAddress = (int)hexBox.SelectionStart;
                int endAddress   = (int)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1)));
                this.MarkSelectionAs(startAddress, endAddress, CdlPrgFlags.Code);
            };
            var mnuMarkAsData = new ToolStripMenuItem();

            mnuMarkAsData.Text   = "Verified Data";
            mnuMarkAsData.Click += (s, e) => {
                int startAddress = (int)hexBox.SelectionStart;
                int endAddress   = (int)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1)));
                this.MarkSelectionAs(startAddress, endAddress, CdlPrgFlags.Data);
            };
            var mnuMarkAsUnidentifiedData = new ToolStripMenuItem();

            mnuMarkAsUnidentifiedData.Text   = "Unidentified Code/Data";
            mnuMarkAsUnidentifiedData.Click += (s, e) => {
                int startAddress = (int)hexBox.SelectionStart;
                int endAddress   = (int)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1)));
                this.MarkSelectionAs(startAddress, endAddress, CdlPrgFlags.None);
            };

            mnuMarkSelectionAs.DropDownItems.Add(mnuMarkAsCode);
            mnuMarkSelectionAs.DropDownItems.Add(mnuMarkAsData);
            mnuMarkSelectionAs.DropDownItems.Add(mnuMarkAsUnidentifiedData);

            var mnuFreeze = new ToolStripMenuItem();

            mnuFreeze.Click += (s, e) => {
                UInt32 startAddress = (UInt32)hexBox.SelectionStart;
                UInt32 endAddress   = (UInt32)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1)));

                for (UInt32 i = startAddress; i <= endAddress; i++)
                {
                    InteropEmu.DebugSetFreezeState((UInt16)i, (bool)mnuFreeze.Tag);
                }
            };

            hexBox.ContextMenuStrip.Opening += (s, e) => {
                UInt32 startAddress = (UInt32)hexBox.SelectionStart;
                UInt32 endAddress   = (UInt32)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1)));

                string address = "$" + startAddress.ToString("X4");
                string addressRange;
                if (startAddress != endAddress)
                {
                    addressRange = "$" + startAddress.ToString("X4") + "-$" + endAddress.ToString("X4");
                }
                else
                {
                    addressRange = address;
                }

                mnuEditLabel.Text      = $"Edit Label ({address})";
                mnuEditBreakpoint.Text = $"Edit Breakpoint ({addressRange})";
                mnuAddWatch.Text       = $"Add to Watch ({addressRange})";

                if (this._memoryType == DebugMemoryType.CpuMemory)
                {
                    bool[] freezeState = InteropEmu.DebugGetFreezeState((UInt16)startAddress, (UInt16)(endAddress - startAddress + 1));
                    if (freezeState.All((frozen) => frozen))
                    {
                        mnuFreeze.Text = $"Unfreeze ({addressRange})";
                        mnuFreeze.Tag  = false;
                    }
                    else
                    {
                        mnuFreeze.Text = $"Freeze ({addressRange})";
                        mnuFreeze.Tag  = true;
                    }
                }
                else
                {
                    mnuFreeze.Text = $"Freeze";
                    mnuFreeze.Tag  = false;
                }

                if (this._memoryType == DebugMemoryType.CpuMemory)
                {
                    int absStart = InteropEmu.DebugGetAbsoluteAddress(startAddress);
                    int absEnd   = InteropEmu.DebugGetAbsoluteAddress(endAddress);

                    if (absStart >= 0 && absEnd >= 0 && absStart <= absEnd)
                    {
                        mnuMarkSelectionAs.Text    = "Mark selection as... (" + addressRange + ")";
                        mnuMarkSelectionAs.Enabled = true;
                    }
                    else
                    {
                        mnuMarkSelectionAs.Text    = "Mark selection as...";
                        mnuMarkSelectionAs.Enabled = false;
                    }
                }
                else if (this._memoryType == DebugMemoryType.PrgRom)
                {
                    mnuMarkSelectionAs.Text    = "Mark selection as... (" + addressRange + ")";
                    mnuMarkSelectionAs.Enabled = true;
                }
                else
                {
                    mnuMarkSelectionAs.Text    = "Mark selection as...";
                    mnuMarkSelectionAs.Enabled = false;
                }

                bool disableEditLabel = false;
                if (this._memoryType == DebugMemoryType.CpuMemory)
                {
                    AddressTypeInfo info = new AddressTypeInfo();
                    InteropEmu.DebugGetAbsoluteAddressAndType(startAddress, ref info);
                    disableEditLabel = info.Address == -1;
                }

                mnuEditLabel.Enabled      = !disableEditLabel && (this._memoryType == DebugMemoryType.CpuMemory || this.GetAddressType().HasValue);
                mnuEditBreakpoint.Enabled = (this._memoryType == DebugMemoryType.CpuMemory || this._memoryType == DebugMemoryType.PpuMemory) && DebugWindowManager.GetDebugger() != null;
                mnuAddWatch.Enabled       = this._memoryType == DebugMemoryType.CpuMemory;
                mnuFreeze.Enabled         = this._memoryType == DebugMemoryType.CpuMemory;
            };

            hexBox.ContextMenuStrip.Items.Insert(0, new ToolStripSeparator());
            hexBox.ContextMenuStrip.Items.Insert(0, mnuFreeze);
            hexBox.ContextMenuStrip.Items.Insert(0, mnuEditLabel);
            hexBox.ContextMenuStrip.Items.Insert(0, mnuEditBreakpoint);
            hexBox.ContextMenuStrip.Items.Insert(0, mnuAddWatch);
            hexBox.ContextMenuStrip.Items.Insert(0, new ToolStripSeparator());
            hexBox.ContextMenuStrip.Items.Insert(0, mnuMarkSelectionAs);
        }
Example #27
0
 public void SetEnabled(bool enabled)
 {
     Enabled = enabled;
     BreakpointManager.RefreshBreakpoints(this);
 }
Example #28
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;
            }
            }
        }
Example #29
0
 public void SetMarked(bool marked)
 {
     MarkEvent = marked;
     BreakpointManager.RefreshBreakpoints(this);
 }
Example #30
0
 private void ToggleBreakpoint(bool toggleEnabled)
 {
     BreakpointManager.ToggleBreakpoint(_lastCodeWindow.GetCurrentLine(), toggleEnabled);
 }