Exemple #1
0
        public override DbgEngineBoundCodeBreakpoint[] Create <T>(DbgBoundCodeBreakpointInfo <T>[] infos)
        {
            if (infos == null)
            {
                throw new ArgumentNullException(nameof(infos));
            }
            if (infos.Length == 0)
            {
                return(Array.Empty <DbgEngineBoundCodeBreakpoint>());
            }
            var bps     = new List <DbgEngineBoundCodeBreakpoint>(infos.Length);
            var bpImpls = new List <DbgEngineBoundCodeBreakpointImpl>(infos.Length);
            List <IDisposable> dataToDispose = null;

            var allBreakpoints = boundCodeBreakpointsService.Value.Breakpoints;
            var dict           = new Dictionary <DbgCodeLocation, DbgCodeBreakpoint>(allBreakpoints.Length);

            foreach (var bp in allBreakpoints)
            {
                Debug.Assert(!dict.ContainsKey(bp.Location));
                dict[bp.Location] = bp;
            }

            for (int i = 0; i < infos.Length; i++)
            {
                var info = infos[i];
                if (!dict.TryGetValue(info.Location, out var breakpoint))
                {
                    if (info.Data is IDisposable id)
                    {
                        if (dataToDispose == null)
                        {
                            dataToDispose = new List <IDisposable>();
                        }
                        dataToDispose.Add(id);
                    }
                }
                else
                {
                    var bp   = new DbgBoundCodeBreakpointImpl(runtime, breakpoint, info.Module, info.Address, info.Message.ToDbgBoundCodeBreakpointMessage());
                    var data = info.Data;
                    if (data != null)
                    {
                        bp.GetOrCreateData(() => data);
                    }
                    var ebp = new DbgEngineBoundCodeBreakpointImpl(bp);
                    bps.Add(ebp);
                    bpImpls.Add(ebp);
                }
            }
            if (bpImpls.Count > 0 || dataToDispose != null)
            {
                owner.Dispatcher.BeginInvoke(() => {
                    if (dataToDispose != null)
                    {
                        foreach (var id in dataToDispose)
                        {
                            id.Dispose();
                        }
                    }
                    if (bpImpls.Count > 0)
                    {
                        owner.AddBoundCodeBreakpoints_DbgThread(runtime, bpImpls.ToArray());
                    }
                });
            }
            return(bps.ToArray());
        }
Exemple #2
0
 public DbgEngineBoundCodeBreakpointImpl(DbgBoundCodeBreakpointImpl boundCodeBreakpoint) =>
 this.boundCodeBreakpoint = boundCodeBreakpoint ?? throw new ArgumentNullException(nameof(boundCodeBreakpoint));