Esempio n. 1
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);
        }
Esempio 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 override sealed 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;
        }
Esempio n. 3
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 override sealed bool BindToModule(MDbgModule managedModule)
        {
            MDbgFunction func;
            int ILoffset;

            // Note that in some cases (eg. source/line breakpoints) we may actually
            // want to bind to multiple locations in this module instead of just one.
            if (!m_location.ResolveLocation(this, managedModule, out func, out ILoffset))
                return false;

            if (m_breakpoints != null)
            {
                // Assume all breakpoints are CorFunctionBreakpoints.
                // If this ever becomes invalid, we'll need a new check here to avoid
                // duplicating that type of breakpoint.
                foreach (CorFunctionBreakpoint cb in m_breakpoints)
                {
                    // If we find a CorBreakpoint that already matches this location
                    // don't add a new one, or the debugger will stop twice when it's hit.
                    // Note that CorFunction instances are 1:1 with a specific function in a
                    // specific module and AppDomain (but represents all generic instantiations).
                    if (cb.Function == func.CorFunction && cb.Offset == ILoffset)
                        return false;
                }
            }

            // Use the resolved information to get a raw CorBreakpoint object.
            CorBreakpoint 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 (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 ArrayList();
            }
            m_breakpoints.Add(breakpoint);

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

            return true;
        }
Esempio n. 4
0
 /// <summary>
 /// Register a handler to be invoked when a Custom Breakpoint is hit.
 /// </summary>
 /// <param name="breakpoint">The CorBreakpoint to register.</param>
 /// <param name="handler">The CustomBreakpointEventHandler to run when the Breakpoint is hit.
 /// 	If this is null, this breakpoints callback is explicitly deregistered.
 /// </param>
 /// <remarks>
 /// 	Only one handler can be specified per breakpoint. The handler could be a 
 /// 	multicast delegate. To change a breakpoints handler, first deregister it and then set
 /// 	a new one.
 /// 	The handler has the same lifespan semantics as the underlying CorBreakpoint object.
 /// 	That means it is alive and the same handler will be invoked every time the breakpoint is hit
 /// 	until the handler is explicitly deregistered. 
 ///
 /// 	A handler can stop the shell at the breakpoint by calling Controller.Stop on the
 ///		CustomBreakpointEventArgs parameter passed into the delegate.
 ///</remarks>
 public void RegisterCustomBreakpoint(CorBreakpoint breakpoint, CustomBreakpointEventHandler handler)
 {
     Debug.Assert(breakpoint != null);
     if (breakpoint == null)
         throw new ArgumentException("cannot be null", "breakpoint");
     if (handler == null)
     {
         // explicit deregistration
         if (customBreakpoints != null)
         {
             customBreakpoints.Remove(breakpoint);
         }
     }
     else
     {
         // adding registration
         if (customBreakpoints == null)
         {
             customBreakpoints = new ListDictionary();
         }
         else
         {
             if (customBreakpoints.Contains(breakpoint))
             {
                 throw new InvalidOperationException("Handler alrady registered for the custom breakpoint");
             }
         }
         customBreakpoints.Add(breakpoint, handler);
     }
 }
Esempio n. 5
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);
        }
Esempio n. 6
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;

            // Note that in some cases (eg. source/line breakpoints) we may actually
            // want to bind to multiple locations in this module instead of just one.
            if (!m_location.ResolveLocation(this, managedModule, out func, out ILoffset))
            {
                return(false);
            }

            if (m_breakpoints != null)
            {
                // Assume all breakpoints are CorFunctionBreakpoints.
                // If this ever becomes invalid, we'll need a new check here to avoid
                // duplicating that type of breakpoint.
                foreach (CorFunctionBreakpoint cb in m_breakpoints)
                {
                    // If we find a CorBreakpoint that already matches this location
                    // don't add a new one, or the debugger will stop twice when it's hit.
                    // Note that CorFunction instances are 1:1 with a specific function in a
                    // specific module and AppDomain (but represents all generic instantiations).
                    if (cb.Function == func.CorFunction && cb.Offset == ILoffset)
                    {
                        return(false);
                    }
                }
            }

            // Use the resolved information to get a raw CorBreakpoint object.
            CorBreakpoint 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 (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 ArrayList();
            }
            m_breakpoints.Add(breakpoint);

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

            p.RegisterCustomBreakpoint(breakpoint, handler);

            return(true);
        }