Exemple #1
0
        internal void DispatchEvent(CorModuleLoadEventArgs ev)
        {
            if (!options.IsAttaching)
            {
                var symreader = ev.Module.GetSymbolReader();
                if (symreader != null)
                {
                    // we will set breakpoint on the user entry code
                    // when debugger creates the debuggee process
                    Int32 token = symreader.UserEntryPoint.GetToken();
                    if (token != 0)
                    {
                        // FIXME should be better written (control over this breakpoint)
                        CorFunction   func       = ev.Module.GetFunctionFromToken(token);
                        CorBreakpoint breakpoint = func.CreateBreakpoint();
                        breakpoint.Activate(true);
                    }
                }
            }

            // we need to save the new module in the modules set
            modules.Add(ev.Module);

            ev.Continue = true;

            if (OnModuleLoad != null)
            {
                OnModuleLoad(ev);
            }
        }
Exemple #2
0
        /// <summary>
        /// Resolves function from its name.
        /// </summary>
        /// <param name="moduleName">module name</param>
        /// <param name="className">class name</param>
        /// <param name="functionName">wanted function name</param>
        /// <returns></returns>
        public CorFunction ResolveFunctionName(String moduleName, String className, String functionName)
        {
            // find module
            CorModule module = FindModuleByName(moduleName);

            if (module == null)
            {
                return(null);
            }

            Int32 typeToken = module.GetTypeTokenFromName(className);

            if (typeToken == CorConstants.TokenNotFound)
            {
                return(null);
            }

            Type        t    = new MetadataType(module.GetMetadataInterface <IMetadataImport>(), typeToken);
            CorFunction func = null;

            foreach (MethodInfo mi in t.GetMethods())
            {
                if (String.Equals(mi.Name, functionName, StringComparison.Ordinal))
                {
                    func = module.GetFunctionFromToken(mi.MetadataToken);
                    break;
                }
            }
            return(func);
        }
Exemple #3
0
 /// <summary>
 /// Resolves code location after the source file name and the code line number.
 /// </summary>
 /// <param name="fileName">source file name</param>
 /// <param name="lineNumber">line number in the source file</param>
 /// <param name="iloffset">returns the offset in the il code (based on the line number)</param>
 /// <returns></returns>
 public CorCode ResolveCodeLocation(String fileName, Int32 lineNumber, out Int32 iloffset)
 {
     // find module
     foreach (CorModule module in Modules)
     {
         ISymbolReader symreader = module.GetSymbolReader();
         if (symreader != null)
         {
             foreach (ISymbolDocument symdoc in symreader.GetDocuments())
             {
                 if (String.Compare(symdoc.URL, fileName, true, CultureInfo.InvariantCulture) == 0 ||
                     String.Compare(System.IO.Path.GetFileName(symdoc.URL), fileName, true, CultureInfo.InvariantCulture) == 0)
                 {
                     Int32 line = 0;
                     try
                     {
                         line = symdoc.FindClosestLine(lineNumber);
                     }
                     catch (System.Runtime.InteropServices.COMException ex)
                     {
                         if (ex.ErrorCode == (Int32)HResult.E_FAIL)
                         {
                             continue; // it's not this document
                         }
                     }
                     ISymbolMethod symmethod = symreader.GetMethodFromDocumentPosition(symdoc, line, 0);
                     CorFunction   func      = module.GetFunctionFromToken(symmethod.Token.GetToken());
                     // IL offset in function code
                     iloffset = func.GetIPFromPosition(symdoc, line);
                     if (iloffset == -1)
                     {
                         return(null);
                     }
                     // finally return the code
                     return(func.GetILCode());
                 }
             }
         }
     }
     iloffset = -1;
     return(null);
 }