Ejemplo n.º 1
0
        public override DbgCodeBreakpointCheckResult ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, DbgCodeBreakpointFilter filter)
        {
            if (!dbgFilterExpressionEvaluatorService.HasExpressionEvaluator)
            {
                // There's no need to localize it, the FEE is exported by the Roslyn code
                return(new DbgCodeBreakpointCheckResult("There's no filter expression evaluator"));
            }

            var expr = filter.Filter;

            Debug.Assert(expr != null);
            if (expr == null)
            {
                return(new DbgCodeBreakpointCheckResult("Missing expression"));
            }

            try {
                dbgFilterEEVariableProvider.Initialize(boundBreakpoint.Process, thread);
                var res = dbgFilterExpressionEvaluatorService.Evaluate(expr, dbgFilterEEVariableProvider);
                if (res.HasError)
                {
                    return(new DbgCodeBreakpointCheckResult(res.Error));
                }
                return(new DbgCodeBreakpointCheckResult(res.Result));
            }
            finally {
                dbgFilterEEVariableProvider.Clear();
            }
        }
Ejemplo n.º 2
0
        public override bool ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, DbgCodeBreakpointFilter filter)
        {
            // If there's no FEE, assume expression matches everything
            if (!dbgFilterExpressionEvaluatorService.HasExpressionEvaluator)
            {
                return(true);
            }

            var expr = filter.Filter;

            Debug.Assert(expr != null);
            if (expr == null)
            {
                return(false);
            }

            try {
                dbgFilterEEVariableProvider.Initialize(boundBreakpoint.Process, thread);
                var res = dbgFilterExpressionEvaluatorService.Evaluate(expr, dbgFilterEEVariableProvider);
                if (res.HasError)
                {
                    return(false);                   //TODO: Notify user too, but only at most once per breakpoint
                }
                return(res.Result);
            }
            finally {
                dbgFilterEEVariableProvider.Clear();
            }
        }
Ejemplo n.º 3
0
		bool ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread? thread) {
			if (thread is null)
				return false;
			var bp = (DbgCodeBreakpointImpl)boundBreakpoint.Breakpoint;
			if (bp.IsClosed || boundBreakpoint.IsClosed)
				return false;

			var settings = bp.Settings;
			if (!settings.IsEnabled)
				return false;

			if (!bp.RaiseHitCheck(boundBreakpoint, thread))
				return false;

			DbgCodeBreakpointCheckResult checkRes;

			if (settings.Filter is DbgCodeBreakpointFilter filter) {
				checkRes = dbgCodeBreakpointFilterChecker.Value.ShouldBreak(boundBreakpoint, thread, filter);
				if (checkRes.ErrorMessage is not null) {
					boundBreakpoint.Process.DbgManager.ShowError(checkRes.ErrorMessage);
					return true;
				}
				if (!checkRes.ShouldBreak)
					return false;
			}

			if (settings.Condition is DbgCodeBreakpointCondition condition) {
				checkRes = dbgCodeBreakpointConditionChecker.Value.ShouldBreak(boundBreakpoint, thread, condition);
				if (checkRes.ErrorMessage is not null) {
					boundBreakpoint.Process.DbgManager.ShowError(checkRes.ErrorMessage);
					return true;
				}
				if (!checkRes.ShouldBreak)
					return false;
			}

			// This counts as a hit, even if there's no 'hit count' option
			int currentHitCount = dbgCodeBreakpointHitCountService.Value.Hit_DbgThread(boundBreakpoint.Breakpoint);
			if (settings.HitCount is DbgCodeBreakpointHitCount hitCount) {
				checkRes = dbgCodeBreakpointHitCountChecker.Value.ShouldBreak(boundBreakpoint, thread, hitCount, currentHitCount);
				if (checkRes.ErrorMessage is not null) {
					boundBreakpoint.Process.DbgManager.ShowError(checkRes.ErrorMessage);
					return true;
				}
				if (!checkRes.ShouldBreak)
					return false;
			}

			bool shouldBreak;
			if (settings.Trace is DbgCodeBreakpointTrace trace) {
				dbgCodeBreakpointTraceMessagePrinter.Value.Print(boundBreakpoint, thread, trace);
				shouldBreak = !trace.Continue;
			}
			else
				shouldBreak = true;
			if (shouldBreak)
				bp.RaiseHit(boundBreakpoint, thread);
			return shouldBreak;
		}
Ejemplo n.º 4
0
 public override bool ShowNativeCode(DbgBoundCodeBreakpoint boundBreakpoint, string title)
 {
     if (!dbgNativeCodeProvider.Value.TryGetNativeCode(boundBreakpoint, GetNativeCodeOptions(), out var result))
     {
         return(false);
     }
     Show(result, title);
     return(true);
 }
Ejemplo n.º 5
0
 public override void Print(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, DbgCodeBreakpointTrace trace)
 {
     if (tracepointMessageListeners.Length != 0)
     {
         var message = tracepointMessageCreator.Create(boundBreakpoint, thread, trace);
         foreach (var lz in tracepointMessageListeners)
         {
             lz.Value.Message(message);
         }
     }
 }
Ejemplo n.º 6
0
        public override bool CanGetNativeCode(DbgBoundCodeBreakpoint boundBreakpoint)
        {
            if (boundBreakpoint == null)
            {
                throw new ArgumentNullException(nameof(boundBreakpoint));
            }

            foreach (var provider in GetProviders(boundBreakpoint.Runtime))
            {
                if (provider.CanGetNativeCode(boundBreakpoint))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 7
0
        public override bool TryGetNativeCode(DbgBoundCodeBreakpoint boundBreakpoint, DbgNativeCodeOptions options, out GetNativeCodeResult result)
        {
            if (boundBreakpoint == null)
            {
                throw new ArgumentNullException(nameof(boundBreakpoint));
            }

            foreach (var provider in GetProviders(boundBreakpoint.Runtime))
            {
                if (provider.TryGetNativeCode(boundBreakpoint, options, out result))
                {
                    return(true);
                }
            }

            result = default;
            return(false);
        }
        public override bool ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, DbgCodeBreakpointHitCount hitCount, int currentHitCount)
        {
            switch (hitCount.Kind)
            {
            case DbgCodeBreakpointHitCountKind.Equals:
                return(currentHitCount == hitCount.Count);

            case DbgCodeBreakpointHitCountKind.MultipleOf:
                if (hitCount.Count <= 0)
                {
                    return(false);
                }
                return((currentHitCount % hitCount.Count) == 0);

            case DbgCodeBreakpointHitCountKind.GreaterThanOrEquals:
                return(currentHitCount >= hitCount.Count);

            default:
                Debug.Fail($"Unknown hit count kind: {hitCount.Kind}");
                return(false);
            }
        }
Ejemplo n.º 9
0
        public override DbgCodeBreakpointCheckResult ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, DbgCodeBreakpointHitCount hitCount, int currentHitCount)
        {
            switch (hitCount.Kind)
            {
            case DbgCodeBreakpointHitCountKind.Equals:
                return(new DbgCodeBreakpointCheckResult(currentHitCount == hitCount.Count));

            case DbgCodeBreakpointHitCountKind.MultipleOf:
                if (hitCount.Count <= 0)
                {
                    return(new DbgCodeBreakpointCheckResult($"Invalid hit count value: {hitCount.Count}"));
                }
                return(new DbgCodeBreakpointCheckResult((currentHitCount % hitCount.Count) == 0));

            case DbgCodeBreakpointHitCountKind.GreaterThanOrEquals:
                return(new DbgCodeBreakpointCheckResult(currentHitCount >= hitCount.Count));

            default:
                Debug.Fail($"Unknown hit count kind: {hitCount.Kind}");
                return(new DbgCodeBreakpointCheckResult($"Unknown hit count kind: {hitCount.Kind}"));
            }
        }
Ejemplo n.º 10
0
 public abstract bool CanShowNativeCode(DbgBoundCodeBreakpoint boundBreakpoint);
 public override DbgCodeBreakpointCheckResult ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, in DbgCodeBreakpointHitCount hitCount, int currentHitCount)
Ejemplo n.º 12
0
 public abstract DbgCodeBreakpointCheckResult ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, DbgCodeBreakpointHitCount hitCount, int currentHitCount);
Ejemplo n.º 13
0
 public override DbgCodeBreakpointCheckResult ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, in DbgCodeBreakpointFilter filter)
Ejemplo n.º 14
0
 public abstract void Print(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, DbgCodeBreakpointTrace trace);
Ejemplo n.º 15
0
 /// <summary>
 /// Tries to get the native code
 /// </summary>
 /// <param name="boundBreakpoint">A bound breakpoint</param>
 /// <param name="options">Options</param>
 /// <param name="result">Native code if successful</param>
 /// <returns></returns>
 public abstract bool TryGetNativeCode(DbgBoundCodeBreakpoint boundBreakpoint, DbgNativeCodeOptions options, out GetNativeCodeResult result);
Ejemplo n.º 16
0
 public abstract DbgCodeBreakpointCheckResult ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, in DbgCodeBreakpointFilter filter);
Ejemplo n.º 17
0
 public abstract bool ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, DbgCodeBreakpointCondition condition);
Ejemplo n.º 18
0
 public override bool ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, DbgCodeBreakpointCondition condition)
 {
     //TODO:
     return(false);
 }
Ejemplo n.º 19
0
 public abstract DbgCodeBreakpointCheckResult ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, DbgCodeBreakpointCondition condition);
Ejemplo n.º 20
0
        bool ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread)
        {
            var bp = (DbgCodeBreakpointImpl)boundBreakpoint.Breakpoint;

            if (bp.IsClosed || boundBreakpoint.IsClosed)
            {
                return(false);
            }

            var settings = bp.Settings;

            if (!settings.IsEnabled)
            {
                return(false);
            }

            if (!bp.RaiseHitCheck(boundBreakpoint, thread))
            {
                return(false);
            }

            // Don't reorder these checks. This seems to be the order VS' debugger checks everything:
            //		condition && hitCount && filter

            if (settings.Condition is DbgCodeBreakpointCondition condition)
            {
                if (!dbgCodeBreakpointConditionChecker.Value.ShouldBreak(boundBreakpoint, thread, condition))
                {
                    return(false);
                }
            }

            // This counts as a hit, even if there's no 'hit count' option
            int currentHitCount = dbgCodeBreakpointHitCountService.Value.Hit_DbgThread(boundBreakpoint.Breakpoint);

            if (settings.HitCount is DbgCodeBreakpointHitCount hitCount)
            {
                if (!dbgCodeBreakpointHitCountChecker.Value.ShouldBreak(boundBreakpoint, thread, hitCount, currentHitCount))
                {
                    return(false);
                }
            }

            if (settings.Filter is DbgCodeBreakpointFilter filter)
            {
                if (!dbgCodeBreakpointFilterChecker.Value.ShouldBreak(boundBreakpoint, thread, filter))
                {
                    return(false);
                }
            }

            bool shouldBreak;

            if (settings.Trace is DbgCodeBreakpointTrace trace)
            {
                dbgCodeBreakpointTraceMessagePrinter.Value.Print(boundBreakpoint, thread, trace);
                shouldBreak = !trace.Continue;
            }
            else
            {
                shouldBreak = true;
            }
            if (shouldBreak)
            {
                bp.RaiseHit(boundBreakpoint, thread);
            }
            return(shouldBreak);
        }
 public override void Print(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, in DbgCodeBreakpointTrace trace)
Ejemplo n.º 22
0
 public abstract bool ShowNativeCode(DbgBoundCodeBreakpoint boundBreakpoint, string title = null);
Ejemplo n.º 23
0
 public override bool CanShowNativeCode(DbgBoundCodeBreakpoint boundBreakpoint) =>
 dbgNativeCodeProvider.Value.CanGetNativeCode(boundBreakpoint);
Ejemplo n.º 24
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="boundBreakpoint">Breakpoint</param>
 /// <param name="thread">Thread or null if it's not known</param>
 /// <param name="messageFlags">Message flags</param>
 public DbgMessageBreakpoint(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, DbgEngineMessageFlags messageFlags)
     : base(messageFlags)
 {
     BoundBreakpoint = boundBreakpoint ?? throw new ArgumentNullException(nameof(boundBreakpoint));
     Thread          = thread;
 }
Ejemplo n.º 25
0
 public abstract bool ShouldBreak(DbgBoundCodeBreakpoint boundBreakpoint, DbgThread thread, DbgCodeBreakpointFilter filter);