Exemple #1
0
        private bool IsBreakPointTriggered()
        {
            //This prevents the Run Command from getting stuck after reaching a breakpoint
            if (_breakpointTriggered)
            {
                _breakpointTriggered = false;
                return(false);
            }

            foreach (var breakpoint in Breakpoints.Where(x => x.IsEnabled))
            {
                int value;

                if (!int.TryParse(breakpoint.Value, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out value))
                {
                    continue;
                }

                if (breakpoint.Type == BreakpointType.NumberOfCycleType && value == NumberOfCycles)
                {
                    _breakpointTriggered = true;
                    RunPause();
                    return(true);
                }

                if (breakpoint.Type == BreakpointType.ProgramCounterType && value == Proc.ProgramCounter)
                {
                    _breakpointTriggered = true;
                    RunPause();
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
		public static Breakpoint GetMatchingBreakpoint(UInt32 startAddress, UInt32 endAddress, SnesMemoryType memoryType)
		{
			bool isAddressRange = startAddress != endAddress;
			return Breakpoints.Where((bp) =>
					bp.MemoryType == memoryType &&
					((!isAddressRange && bp.Address == startAddress) || (isAddressRange && bp.StartAddress == startAddress && bp.EndAddress == endAddress))
				).FirstOrDefault();
		}
        /// <summary>
        /// Us this method to prepare the breakpoints when running the
        /// virtual machine in debug mode
        /// </summary>
        public void PrepareBreakpoints()
        {
            // --- Keep CPU breakpoints set through the Disassembler tool
            var cpuBreakPoints = Breakpoints.Where(bp => bp.Value.IsCpuBreakpoint).ToList();

            Breakpoints.Clear();
            foreach (var bpItem in cpuBreakPoints)
            {
                Breakpoints.Add(bpItem.Key, bpItem.Value);
            }

            // --- Merge breakpoints set in Visual Studio
            if (CompiledOutput == null)
            {
                return;
            }
            foreach (Breakpoint breakpoint in Package.ApplicationObject.Debugger.Breakpoints)
            {
                // --- Check for the file
                int fileIndex = -1;
                for (var i = 0; i < CompiledOutput.SourceFileList.Count; i++)
                {
                    if (string.Compare(breakpoint.File, CompiledOutput.SourceFileList[i].Filename,
                                       StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        fileIndex = i;
                        break;
                    }
                }
                if (fileIndex < 0)
                {
                    continue;
                }

                // --- Check the breakpoint address
                if (CompiledOutput.AddressMap.TryGetValue((fileIndex, breakpoint.FileLine), out var address))
                {
                    Breakpoints.Add(address, new BreakpointInfo
                    {
                        File     = CompiledOutput.SourceFileList[fileIndex].Filename,
                        FileLine = breakpoint.FileLine,
                        Type     = BreakpointType.NoCondition
                    });
                }
            }
        }
Exemple #4
0
		public static Breakpoint GetMatchingBreakpoint(AddressInfo info, CpuType cpuType)
		{
			return Breakpoints.Where((bp) => bp.Matches((UInt32)info.Address, info.Type, cpuType)).FirstOrDefault();
		}
        /// <summary>
        /// Us this method to prepare the breakpoints when running the
        /// virtual machine in debug mode
        /// </summary>
        public void PrepareBreakpoints()
        {
            // --- No compiled code, no VS breakpoints to merge
            if (CompiledOutput == null)
            {
                return;
            }

            var currentVsBreakpoints = new HashSet <Breakpoint>();
            var newVsBreakpoints     = new HashSet <Breakpoint>();

            // --- Identify new breakpoints
            foreach (Breakpoint bp in Package.ApplicationObject.Debugger.Breakpoints)
            {
                if (!_previousVsBreakpoints.ContainsKey(bp))
                {
                    newVsBreakpoints.Add(bp);
                }
                currentVsBreakpoints.Add(bp);
            }

            var oldBreakpoints = new HashSet <Breakpoint>();

            // --- Identify breakpoints to remove
            foreach (var bp in _previousVsBreakpoints.Keys)
            {
                if (!currentVsBreakpoints.Contains(bp))
                {
                    oldBreakpoints.Add(bp);
                }
            }

            // --- In there any change?
            if (newVsBreakpoints.Count == 0 && oldBreakpoints.Count == 0)
            {
                // --- No change, use existing breakpoints
                return;
            }

            // --- Remove old breakpoints
            foreach (var oldBp in oldBreakpoints)
            {
                _previousVsBreakpoints.Remove(oldBp);
            }

            // --- Start assembling the new breakpoint collection
            var newBreakpointCollection = new BreakpointCollection();

            // --- Keep CPU breakpoints set through the Disassembler tool
            foreach (var pair in Breakpoints.Where(bp => bp.Value.IsCpuBreakpoint))
            {
                newBreakpointCollection.Add(pair.Key, pair.Value);
            }

            // --- Add existing VS breakpoints
            foreach (var existingBp in _previousVsBreakpoints.Values)
            {
                foreach (var bp in existingBp)
                {
                    newBreakpointCollection.Add(bp.Key, bp.Value);
                }
            }

            // --- Create new breakpoints
            foreach (var newBp in newVsBreakpoints)
            {
                // --- Check for the file
                var fileIndex = -1;
                for (var i = 0; i < CompiledOutput.SourceFileList.Count; i++)
                {
                    if (string.Compare(newBp.File, CompiledOutput.SourceFileList[i].Filename,
                                       StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        fileIndex = i;
                        break;
                    }
                }
                if (fileIndex < 0)
                {
                    continue;
                }

                var newVsBreakpoint = new BreakpointInfo
                {
                    File     = CompiledOutput.SourceFileList[fileIndex].Filename,
                    FileLine = newBp.FileLine,
                    HitType  = BreakpointHitType.None
                };

                // --- Set hit condition
                if (newBp.HitCountType != dbgHitCountType.dbgHitCountTypeNone)
                {
                    if (newBp.HitCountType == dbgHitCountType.dbgHitCountTypeEqual)
                    {
                        newVsBreakpoint.HitType = BreakpointHitType.Equal;
                    }
                    else if (newBp.HitCountType == dbgHitCountType.dbgHitCountTypeGreaterOrEqual)
                    {
                        newVsBreakpoint.HitType = BreakpointHitType.GreaterOrEqual;
                    }
                    else if (newBp.HitCountType == dbgHitCountType.dbgHitCountTypeMultiple)
                    {
                        newVsBreakpoint.HitType = BreakpointHitType.Multiple;
                    }
                    newVsBreakpoint.HitConditionValue = (ushort)(newBp.HitCountTarget >= 0 ? newBp.HitCountTarget : 0);
                }

                // --- Set filter condition
                if (!string.IsNullOrWhiteSpace(newBp.Condition))
                {
                    var inputStream = new AntlrInputStream(newBp.Condition);
                    var lexer       = new Z80EvalLexer(inputStream);
                    var tokenStream = new CommonTokenStream(lexer);
                    var evalParser  = new Z80EvalParser(tokenStream);
                    var context     = evalParser.compileUnit();
                    var visitor     = new Z80EvalVisitor();
                    var z80Expr     = (Z80ExpressionNode)visitor.Visit(context);
                    if (evalParser.SyntaxErrors.Count == 0)
                    {
                        newVsBreakpoint.FilterExpression = z80Expr.Expression;
                    }
                }

                // --- Check the breakpoint address
                if (CompiledOutput.AddressMap.TryGetValue((fileIndex, newBp.FileLine), out var addresses))
                {
                    foreach (var addr in addresses)
                    {
                        // --- Set up breakpoints

                        newBreakpointCollection.Add(addr, newVsBreakpoint);
                    }
                }
            }

            // --- Set the new collection of breakpoints
            Breakpoints = newBreakpointCollection;
        }
Exemple #6
0
 public static Breakpoint GetMatchingBreakpoint(int relativeAddress, AddressTypeInfo info)
 {
     return(Breakpoints.Where((bp) => bp.Matches(relativeAddress, info)).FirstOrDefault());
 }