Esempio n. 1
0
        protected override void OnEnableBreakEvent(BreakEventInfo binfo, bool enable)
        {
            CorBreakpoint bp = binfo.Handle as CorFunctionBreakpoint;

            if (bp != null)
            {
                bp.Activate(enable);
            }
        }
Esempio n. 2
0
        protected override void OnEnableBreakEvent(object handle, bool enable)
        {
            CorBreakpoint bp = handle as CorFunctionBreakpoint;

            if (bp != null)
            {
                bp.Activate(enable);
            }
        }
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 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);
        }