Exemplo n.º 1
0
 public void Break(BreakReason reason, object obj = null)
 {
     Debug.LogWarning("Chan broken: " + reason.ToString());
     if (errorHandler != null)
     {
         errorHandler(reason, obj);
     }
 }
Exemplo n.º 2
0
        /**
         * Sends the pause notification.
         * bpAddress is a long address.
         */
        protected static void SendPauseNotification(BreakReason reason, int bpAddress, string reasonString)
        {
            //Log.WriteLine("SendPauseNotification: reason={0}, bpAddress=0x{1:X6}, reasonString='{2}'", reason, bpAddress, reasonString);
            // Convert string to byte array
            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
            byte[] reasonBytes            = enc.GetBytes(reasonString + "\0");
            int    stringLen = reasonBytes.Length;

            // Prepare data
            int length = 6 + stringLen;

            byte[] dataWoString =
            {
                // Length
                (byte)(length & 0xFF),
                (byte)((length >> 8) & 0xFF),
                (byte)((length >> 16) & 0xFF),
                (byte)(length >> 24),
                // SeqNo = 0
                0,
                // PAUSE
                (byte)DZRP_NTF.NTF_PAUSE,
                // Reason
                (byte)reason,
                // Breakpoint address (long address)
                (byte)(bpAddress & 0xFF),
                (byte)((bpAddress >> 8) & 0xFF),
                (byte)((bpAddress >> 16) & 0xFF),
            };
            int firstLen = dataWoString.Length;

            byte[] data = new byte[firstLen + stringLen];
            dataWoString.CopyTo(data, 0);
            reasonBytes.CopyTo(data, firstLen);

            // Respond
            CSpectSocket.Send(data);
        }
Exemplo n.º 3
0
        /**
         * Called when the debugger stopped.
         * E.g. because a breakpoint was hit.
         * @param sendNtfIfNoReason If no reason is found a notification (with "manual break") is sent
         * if true.
         * The notification is not sent if false. In that case a notification is only sent if a reason
         * is found.
         */
        protected static void CheckIfBreakpointHit(bool sendNtfIfNoReason = true)
        {
            // Get PC
            var  cspect = Main.CSpect;
            var  regs   = cspect.GetRegs();
            var  pc     = regs.PC;
            byte slot   = (byte)(pc >> 13);
            int  bank   = cspect.GetNextRegister((byte)(0x50 + slot));
            //Log.WriteLine("Debugger stopped: bank {0}, slot {1}", bank, slot);
            int pcLong = ((bank + 1) << 16) + pc;

            if (Log.Enabled)
            {
                Log.WriteLine("Debugger stopped at 0x{0:X4} (long address=0x{1:X6})", pc, pcLong);
            }

            // Disable temporary breakpoints (64k addresses)
            if (TmpBreakpoint1 >= 0)
            {
                if (!BreakpointMap.ContainsValue((ushort)TmpBreakpoint1))
                {
                    cspect.Debugger(Plugin.eDebugCommand.ClearBreakpoint, TmpBreakpoint1);
                }
            }
            if (TmpBreakpoint2 >= 0)
            {
                if (!BreakpointMap.ContainsValue((ushort)TmpBreakpoint2))
                {
                    cspect.Debugger(Plugin.eDebugCommand.ClearBreakpoint, TmpBreakpoint2);
                }
            }

            // Guess break reason
            BreakReason reason       = BreakReason.MANUAL_BREAK;
            string      reasonString = "";
            int         bpAddress    = 0;

            //  Check for temporary breakpoints
            if (pc == TmpBreakpoint1 || pc == TmpBreakpoint2)
            {
                reason    = BreakReason.NO_REASON;
                bpAddress = pcLong;
            }
            // Check for breakpoints
            else if (BreakpointMap.ContainsValue(pcLong) || BreakpointMap.ContainsValue(pc))
            {
                // Breakpoint hit
                reason    = BreakReason.BREAKPOINT_HIT;
                bpAddress = pcLong;
            }

            // Note: Watchpoint reasons cannot be safely recognized.
            // Use a few heuristics to determine if a watchpoint is hit.
            if (reason == BreakReason.MANUAL_BREAK)
            {
                if (!ManualBreak)
                {
                    // No pause command has been sent.
                    // Check if there is any watchpoint set. If yes
                    // assume it was a watchpoint.
                    // Note: It could also be a user stopping the CSpect by F1.
                    for (int i = 0; i < 0x10000; i++)
                    {
                        if (cspect.Debugger(Plugin.eDebugCommand.GetReadBreakpoint, i) != 0 ||
                            cspect.Debugger(Plugin.eDebugCommand.GetWriteBreakpoint, i) != 0)
                        {
                            reason       = BreakReason.OTHER;
                            reasonString = "Watchpoint hit or manual break.";
                            break;
                        }
                    }
                }
            }

            // Send break notification
            if (sendNtfIfNoReason || reason != BreakReason.MANUAL_BREAK)
            {
                SendPauseNotification(reason, bpAddress, reasonString);
            }

            // "Undefine" temporary breakpoints
            TmpBreakpoint1 = -1;
            TmpBreakpoint2 = -1;
            // Reset Pause
            ManualBreak = false;
        }