Exemplo n.º 1
0
        protected override BreakEventInfo OnInsertBreakEvent(BreakEvent be)
        {
            BreakEventInfo binfo = new BreakEventInfo();

            lock (documents) {
                Breakpoint bp = be as Breakpoint;
                if (bp != null)
                {
                    DocInfo doc;
                    if (!documents.TryGetValue(System.IO.Path.GetFullPath(bp.FileName), out doc))
                    {
                        binfo.SetStatus(BreakEventStatus.NotBound, null);
                        return(binfo);
                    }

                    int line;
                    try {
                        line = doc.Document.FindClosestLine(bp.Line);
                    }
                    catch {
                        // Invalid line
                        binfo.SetStatus(BreakEventStatus.Invalid, null);
                        return(binfo);
                    }
                    ISymbolMethod met = doc.Reader.GetMethodFromDocumentPosition(doc.Document, line, 0);
                    if (met == null)
                    {
                        binfo.SetStatus(BreakEventStatus.Invalid, null);
                        return(binfo);
                    }

                    int offset = -1;
                    foreach (SequencePoint sp in met.GetSequencePoints())
                    {
                        if (sp.Line == line && sp.Document.URL == doc.Document.URL)
                        {
                            offset = sp.Offset;
                            break;
                        }
                    }
                    if (offset == -1)
                    {
                        binfo.SetStatus(BreakEventStatus.Invalid, null);
                        return(binfo);
                    }

                    CorFunction           func  = doc.Module.GetFunctionFromToken(met.Token.GetToken());
                    CorFunctionBreakpoint corBp = func.ILCode.CreateBreakpoint(offset);
                    corBp.Activate(bp.Enabled);
                    breakpoints[corBp] = binfo;

                    binfo.Handle = corBp;
                    binfo.SetStatus(BreakEventStatus.Bound, null);
                    return(binfo);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function tries to bind a breakpoint to the specified module.
        /// </summary>
        /// <param name="managedModule">A module the breakpoint should be bound to.</param>
        /// <returns>true if breakpoint was successfully bound or false if it failed or was already bound.</returns>
        /// <remarks>
        ///     This function is called by breakpoint manager for every brekapoint whenever a new module
        ///     gets loaded into the debugged process or whenever a dynamic module loads a new class
        ///     or new symbols. This adds any missing bindings, but will not duplicate any that already exist.
        /// </remarks>
        public sealed override bool BindToModule(MDbgModule managedModule)
        {
            List <MDbgFunction> funcs;
            int ILoffset;

            // If we already bound a breakpoint in this module then nothing to do
            if (m_breakpoints != null && m_breakpoints.ContainsKey(managedModule))
            {
                return(false);
            }

            // If we can't resolve the location in this module then there is nothing to do
            if (!m_location.ResolveLocation(this, managedModule, out funcs, out ILoffset))
            {
                return(false);
            }

            // Use the resolved information to get a raw CorBreakpoint object.
            CorFunctionBreakpoint breakpoint = null;

            try
            {
                if (ILoffset == 0)
                {
                    foreach (var func in funcs)
                    {
                        breakpoint = func.CorFunction.CreateBreakpoint();
                        SetupBreakpoint(breakpoint, managedModule);
                    }
                }
                else
                {
                    foreach (var func in funcs)
                    {
                        // we need to set a breakpoint on code rather than directly on function
                        CorCode code = func.CorFunction.ILCode;

                        if (code == null)
                        {
                            throw new MDbgException(String.Format(CultureInfo.InvariantCulture, "IL Code for function {0} is null", new Object[] { func.FullName }));
                        }
                        breakpoint = code.CreateBreakpoint(ILoffset);
                        SetupBreakpoint(breakpoint, managedModule);
                    }
                }
            }
            catch (NotImplementedException)
            {
                return(false);
            }
            catch (COMException)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        protected override void OnRemoveBreakEvent(object handle)
        {
            if (terminated)
            {
                return;
            }
            CorFunctionBreakpoint corBp = (CorFunctionBreakpoint)handle;

            corBp.Activate(false);
        }
Exemplo n.º 4
0
        protected override void OnRemoveBreakEvent(BreakEventInfo bi)
        {
            if (terminated)
            {
                return;
            }
            CorFunctionBreakpoint corBp = (CorFunctionBreakpoint)bi.Handle;

            corBp.Activate(false);
        }
Exemplo n.º 5
0
        protected override object OnInsertBreakEvent(BreakEvent be, bool activate)
        {
            lock (documents) {
                Breakpoint bp = be as Breakpoint;
                if (bp != null)
                {
                    DocInfo doc;
                    if (!documents.TryGetValue(System.IO.Path.GetFullPath(bp.FileName), out doc))
                    {
                        return(null);
                    }

                    int line;
                    try {
                        line = doc.Document.FindClosestLine(bp.Line);
                    }
                    catch {
                        // Invalid line
                        return(null);
                    }
                    ISymbolMethod met = doc.Reader.GetMethodFromDocumentPosition(doc.Document, line, 0);
                    if (met == null)
                    {
                        return(null);
                    }

                    int offset = -1;
                    foreach (SequencePoint sp in met.GetSequencePoints())
                    {
                        if (sp.Line == line && sp.Document.URL == doc.Document.URL)
                        {
                            offset = sp.Offset;
                            break;
                        }
                    }
                    if (offset == -1)
                    {
                        return(null);
                    }

                    CorFunction           func  = doc.Module.GetFunctionFromToken(met.Token.GetToken());
                    CorFunctionBreakpoint corBp = func.ILCode.CreateBreakpoint(offset);
                    corBp.Activate(activate);
                    return(corBp);
                }
            }
            return(null);
        }
        protected override void OnRemoveBreakEvent(BreakEventInfo bi)
        {
            if (terminated)
            {
                return;
            }

            if (bi.Status != BreakEventStatus.Bound || bi.Handle == null)
            {
                return;
            }

            CorFunctionBreakpoint corBp = (CorFunctionBreakpoint)bi.Handle;

            corBp.Activate(false);
        }
Exemplo n.º 7
0
        private void SetupBreakpoint(CorFunctionBreakpoint breakpoint, MDbgModule managedModule)
        {
            // Add the new CorBreakpoint object to our internal list and register a handler for it.
            Debug.Assert(breakpoint != null);
            breakpoint.Activate(true);
            if (m_breakpoints == null)
            {
                m_breakpoints = new Dictionary <MDbgModule, List <CorFunctionBreakpoint> >();
            }
            else if (m_breakpoints.ContainsKey(managedModule))
            {
                m_breakpoints[managedModule].Add(breakpoint);
            }
            else
            {
                m_breakpoints[managedModule] = new List <CorFunctionBreakpoint>();
                m_breakpoints[managedModule].Add(breakpoint);
            }

            MDbgProcess p = managedModule.Process;
            CustomBreakpointEventHandler handler = new CustomBreakpointEventHandler(this.InternalOnHitHandler);

            p.RegisterCustomBreakpoint(breakpoint, handler);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Function tries to bind a breakpoint to the specified module.
        /// </summary>
        /// <param name="managedModule">A module the breakpoint should be bound to.</param>
        /// <returns>true if breakpoint was successfully bound or false if it failed or was already bound.</returns>
        /// <remarks>
        ///     This function is called by breakpoint manager for every brekapoint whenever a new module
        ///     gets loaded into the debugged process or whenever a dynamic module loads a new class
        ///     or new symbols. This adds any missing bindings, but will not duplicate any that already exist.
        /// </remarks>
        public sealed override bool BindToModule(MDbgModule managedModule)
        {
            MDbgFunction func;
            int          ILoffset;

            // If we already bound a breakpoint in this module then nothing to do
            if (m_breakpoints != null && m_breakpoints.ContainsKey(managedModule))
            {
                return(false);
            }

            // If we can't resolve the location in this module then there is nothing to do
            if (!m_location.ResolveLocation(this, managedModule, out func, out ILoffset))
            {
                return(false);
            }

            // Use the resolved information to get a raw CorBreakpoint object.
            CorFunctionBreakpoint breakpoint = null;

            try
            {
                if (ILoffset == 0)
                {
                    breakpoint = func.CorFunction.CreateBreakpoint();
                }
                else
                {
                    // we need to set a breakpoint on code rather than directly on function
                    CorCode code = func.CorFunction.ILCode;

                    if (code == null)
                    {
                        throw new MDbgException(String.Format(CultureInfo.InvariantCulture, "IL Code for function {0} is null", new Object[] { func.FullName }));
                    }
                    breakpoint = code.CreateBreakpoint(ILoffset);
                }
            }
            catch (NotImplementedException)
            {
                return(false);
            }
            catch (COMException)
            {
                return(false);
            }

            // Add the new CorBreakpoint object to our internal list and register a handler for it.
            Debug.Assert(breakpoint != null);
            breakpoint.Activate(true);
            if (m_breakpoints == null)
            {
                m_breakpoints = new Dictionary <MDbgModule, CorFunctionBreakpoint>();
            }
            m_breakpoints.Add(managedModule, breakpoint);

            MDbgProcess p = managedModule.Process;
            CustomBreakpointEventHandler handler = new CustomBreakpointEventHandler(this.InternalOnHitHandler);

            p.RegisterCustomBreakpoint(breakpoint, handler);

            return(true);
        }
Exemplo n.º 9
0
		public ModuleILCodeBreakpoint(DnModule module, CorFunctionBreakpoint funcBp) {
			this.module = module;
			this.funcBp = funcBp;
		}
Exemplo n.º 10
0
		public ModuleCodeBreakpoint(DnModule module, CorFunctionBreakpoint funcBp) {
			Module = module;
			FunctionBreakpoint = funcBp;
		}