// Class for special breakpoint for user-entry.
        // This is set by the shell.

        private void UnloadModuleEventHandler(Object sender, CorModuleEventArgs e)
        {
            OriginalMDbgMessages.WriteLine("ManagedCallback::UnloadModule");

            bool handled = HandleCustomPostCallback(ManagedCallbackType.OnModuleUnload, e);

            m_moduleMgr.Unregister(e.Module);

            if (handled)
                return;

            if (InternalHandleRawMode(ManagedCallbackType.OnModuleUnload, e))
                return;
        }
        private void LoadModuleEventHandler(Object sender, CorModuleEventArgs e)
        {
            MDbgModule m = m_moduleMgr.Register(e.Module);
            OriginalMDbgMessages.WriteLine("ManagedCallback::LoadModule(" + m.CorModule.Name + ")");

            if (!m_processAttaching
                && (m_debugMode != DebugModeFlag.Default))
            {
                // translate DebugModeFlags to JITCompilerFlags
                CorDebugJITCompilerFlags jcf = MapDebugModeToJITCompilerFlags(m_debugMode);

                OriginalMDbgMessages.WriteLine("Setting module jit compiler flags:" + jcf);

                try
                {
                    e.Module.JITCompilerFlags = jcf;

                    // Flags may succeed but not set all bits, so requery.
                    CorDebugJITCompilerFlags jcfActual = e.Module.JITCompilerFlags;
                    if (jcf != jcfActual)
                    {
                        OriginalMDbgMessages.WriteLine("Couldn't set all flags. Actual flags:" + jcfActual);
                    }
                }
                catch (COMException ex)
                {
                    // we'll ignore the error if we cannot set the jit flags
                    OriginalMDbgMessages.WriteLine(string.Format("Failed to set flags with hr=0x{0:x}", ex.ErrorCode));
                }
            }

            m_breakpointMgr.BindBreakpoints(m);
            // let's try to bind all unboud breakpoints (maybe the types got loaded this time)

            if (InternalHandleRawMode(ManagedCallbackType.OnModuleLoad, e))
                return;


            // Symbols track a user entry method.
            // We set a breakpoint at the user entry method and then just run to that to skip any 
            // compiler-injected non-user code before main.
            if (!m_processAttaching
                && m_userEntryBreakpointEnabled
                && m_userEntryBreakpoint == null)
            {
                //now try to set user entry Breakpoint
                if (m.SymReader != null)
                {
                    int st = 0;
                    st = m.SymReader.UserEntryPoint.GetToken();
                    if (st != 0)
                    {
                        MDbgFunction mfunc = m.GetFunction(st);
                        m_userEntryBreakpoint = new UserEntryBreakpoint(this, mfunc);
                        bool ok = m_userEntryBreakpoint.BindToModule(m);
                        Debug.Assert(ok);
                        // now we cannot call BindBreakpoints again otherwise userEntrBreakpoint will be bound
                        // twice
                    }

                    // We explicitly don't set JMC. An extension can hook up to this module and set JMC policy if it wants.
                }
            }

            if (HandleCustomPostCallback(ManagedCallbackType.OnModuleLoad, e))
                return;

            if (m_engine.Options.StopOnModuleLoad)
            {
                e.Continue = false;
                InternalSignalRuntimeIsStopped(null, new ModuleLoadedStopReason(Modules.Lookup(e.Module)));
            }
        }