void OnModuleUnload (object sender, CorModuleEventArgs e) { lock (documents) { ModuleInfo moi; modules.TryGetValue (e.Module.Name, out moi); if (moi == null || --moi.References > 0) return; modules.Remove (e.Module.Name); List<string> toRemove = new List<string> (); foreach (KeyValuePair<string, DocInfo> di in documents) { if (di.Value.Module.Name == e.Module.Name) toRemove.Add (di.Key); } foreach (string file in toRemove) { documents.Remove (file); NotifySourceFileUnloaded (file); } } }
void CreateModuleEventHandler(object sender, CorModuleEventArgs e) { //Console.WriteLine("OnCreateModule" + e.Module.Name); e.Continue = true; }
void OnModuleLoad (object sender, CorModuleEventArgs e) { CorMetadataImport mi = new CorMetadataImport (e.Module); try { // Required to avoid the jit to get rid of variables too early e.Module.JITCompilerFlags = CorDebugJITCompilerFlags.CORDEBUG_JIT_DISABLE_OPTIMIZATION; } catch { // Some kind of modules don't allow JIT flags to be changed. } string file = e.Module.Assembly.Name; lock (documents) { ISymbolReader reader = null; if (file.IndexOfAny (System.IO.Path.InvalidPathChars) == -1 && System.IO.File.Exists (System.IO.Path.ChangeExtension (file, ".pdb"))) { try { reader = symbolBinder.GetReaderForFile (mi.RawCOMObject, file, "."); foreach (ISymbolDocument doc in reader.GetDocuments ()) { if (string.IsNullOrEmpty (doc.URL)) continue; string docFile = System.IO.Path.GetFullPath (doc.URL); DocInfo di = new DocInfo (); di.Document = doc; di.Reader = reader; di.Module = e.Module; documents[docFile] = di; NotifySourceFileLoaded (docFile); } } catch (Exception ex) { OnDebuggerOutput (true, string.Format ("Debugger Error: {0}\n", ex.Message)); } e.Module.SetJmcStatus (true, null); } else { // Flag modules without debug info as not JMC. In this way // the debugger won't try to step into them e.Module.SetJmcStatus (false, null); } ModuleInfo moi; if (modules.TryGetValue (e.Module.Name, out moi)) { moi.References++; } else { moi = new ModuleInfo (); moi.Module = e.Module; moi.Reader = reader; moi.Importer = mi; moi.References = 1; modules[e.Module.Name] = moi; } } e.Continue = true; }
void _process_OnModuleLoad(object sender, CorModuleEventArgs e) { var module = e.Module; var reader = loadSymbolReader(module); if (module.Name.Equals(_breakpoint.Assembly)) setBreakpoint(module, reader); }
private void OnModuleLoad(object sender, CorModuleEventArgs e) { subscriber.Published(string.Format("Loading module: {0}", e.Module.Name)); modules.Add(e.Module); Assembly assembly = Assembly.LoadFile(e.Module.Name); object[] attributes = assembly.GetCustomAttributes(true); try { var revisionAttribute = (AssemblyInformationalVersionAttribute) attributes.First(o => o is AssemblyInformationalVersionAttribute); string revision = revisionAttribute.InformationalVersion; sourceRepository.Verify(revision, subscriber); } catch (InvalidOperationException ioex) { subscriber.Published( string.Format( "No source revision found for module {0}, will not use this module for tracking source.", e.Module.Name)); } subscriber.Published(string.Format("Module loaded: {0}", e.Module.Name)); NumberOfModulesLoaded++; }
private void UnloadModuleEventHandler(Object sender, CorModuleEventArgs e) { Trace.WriteLine("ManagedCallback::UnloadModule"); BeginManagedDebugEvent(); try { bool handled = HandleCustomPostCallback(ManagedCallbackType.OnModuleUnload, e); MDbgModule module = m_moduleMgr.Lookup(e.Module); m_moduleMgr.Unregister(e.Module); // unbind breakpoints that were in the module which just got unloaded if (module != null) { m_breakpointMgr.OnModuleUnloaded(module); } if (handled) return; if (InternalHandleRawMode(ManagedCallbackType.OnModuleUnload, e)) return; } finally { EndManagedDebugEvent(e); } }
private void LoadModuleEventHandler(Object sender, CorModuleEventArgs e) { Trace.WriteLine("ManagedCallback::LoadModule(" + e.Module.Name + ")"); BeginManagedDebugEvent(); try { MDbgModule m = m_moduleMgr.Register(e.Module); if (!m_processAttaching && (m_debugMode != DebugModeFlag.Default)) { // translate DebugModeFlags to JITCompilerFlags CorDebugJITCompilerFlags jcf = MapDebugModeToJITCompilerFlags(m_debugMode); Trace.WriteLine("Setting module jit compiler flags:" + jcf.ToString()); try { e.Module.JITCompilerFlags = jcf; // Flags may succeed but not set all bits, so requery. CorDebugJITCompilerFlags jcfActual = e.Module.JITCompilerFlags; if (jcf != jcfActual) { Trace.WriteLine("Couldn't set all flags. Actual flags:" + jcfActual.ToString()); } } catch (COMException ex) { // we'll ignore the error if we cannot set the jit flags Trace.WriteLine(string.Format("Failed to set flags with hr=0x{0:x}", ex.ErrorCode)); } } // let's try to bind all unboud breakpoints (maybe the types got loaded this time) // Note that for dynamic and in-memory modules we won't have symbols until the // first UpdateModuleSymbols or LoadClass callback, so this can't bind any source-level // breakpoints. In fact, this is probably useless for dynamic modules since they don't have // any code in them until the first LoadClass event. m_breakpointMgr.BindBreakpoints(m); 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) SetUserEntryBreakpointInModule(m); if (HandleCustomPostCallback(ManagedCallbackType.OnModuleLoad, e)) return; if (m_engine.Options.StopOnModuleLoad) { e.Continue = false; InternalSignalRuntimeIsStopped(null, new ModuleLoadedStopReason(Modules.Lookup(e.Module))); } } finally { EndManagedDebugEvent(e); } }