Beispiel #1
0
        public override ModuleDef?GetDynamicMetadata(DbgModule module, out ModuleId moduleId)
        {
            var data = module.GetOrCreateData <DynamicModuleData>();

            if (!(data.Metadata is null))
            {
                moduleId = data.ModuleId;
                return(data.Metadata);
            }
            var info = Invoke(() => {
                if (!(data.Metadata is null))
                {
                    return(metadata: data.Metadata, moduleId: data.ModuleId);
                }
                var info2 = engine.GetDynamicMetadata_EngineThread(module);
                if (!(info2.metadata is null))
                {
                    // DsDotNetDocumentBase sets EnableTypeDefFindCache to true and that property accesses the
                    // Types property. It must be initialized in the correct thread.
                    _ = info2.metadata.Types;
                    info2.metadata.DisableMDAPICalls = true;
                }
                return(info2);
            });

            data.ModuleId = info.moduleId;
            data.Metadata = info.metadata;
            moduleId      = info.moduleId;
            return(data.Metadata);
        }
 public override ModuleId?GetModuleId(DbgModule module)
 {
     if (module == null)
     {
         throw new ArgumentNullException(nameof(module));
     }
     // Don't cache dynamic modules. The reason is that their ModuleIds could change,
     // see CorDebug's DbgEngineImpl.UpdateDynamicModuleIds()
     if (module.IsDynamic)
     {
         return(GetModuleIdCore(module));
     }
     return(module.GetOrCreateData(() => new CachedModuleId(GetModuleIdCore(module))).Id);
 }
Beispiel #3
0
 CorModuleDef?TryGetDynamicMetadata(DbgModule module) => module.GetOrCreateData <DynamicModuleData>().Metadata;
Beispiel #4
0
        public override IEnumerable <uint> GetModifiedTypes(DbgModule module)
        {
            engine.VerifyCorDebugThread();
            var data = module.GetOrCreateData <DynamicModuleData>();
            var cmod = TryGetDynamicMetadata(module);

            var hash = new HashSet <uint>();

            if (cmod is null)
            {
                return(hash);
            }

            var oldLastValid = UpdateLastValidRids(data, cmod);
            var lastValid    = data.LastValidRids;

            if (oldLastValid.Equals(lastValid))
            {
                return(hash);
            }

            const uint TYPEDEF_TOKEN = 0x02000000;

            // Optimization if we loaded a big file
            if (oldLastValid.TypeDefRid == 0)
            {
                for (uint rid = 1; rid <= lastValid.TypeDefRid; rid++)
                {
                    hash.Add(TYPEDEF_TOKEN + rid);
                }
                return(hash);
            }

            var methodRids = new HashSet <uint>();
            var gpRids     = new HashSet <uint>();

            for (uint rid = oldLastValid.TypeDefRid + 1; rid <= lastValid.TypeDefRid; rid++)
            {
                hash.Add(TYPEDEF_TOKEN + rid);
            }
            for (uint rid = oldLastValid.FieldRid + 1; rid <= lastValid.FieldRid; rid++)
            {
                var typeOwner = cmod.GetFieldOwnerToken(rid);
                if (typeOwner.Rid != 0)
                {
                    hash.Add(typeOwner.Raw);
                }
            }
            for (uint rid = oldLastValid.MethodRid + 1; rid <= lastValid.MethodRid; rid++)
            {
                methodRids.Add(rid);
                var typeOwner = cmod.GetMethodOwnerToken(rid);
                if (typeOwner.Rid != 0)
                {
                    hash.Add(typeOwner.Raw);
                }
            }
            for (uint rid = oldLastValid.ParamRid + 1; rid <= lastValid.ParamRid; rid++)
            {
                var methodOwner = cmod.GetParamOwnerToken(rid);
                if (methodRids.Contains(methodOwner.Rid))
                {
                    continue;
                }
                var typeOwner = cmod.GetMethodOwnerToken(methodOwner.Rid);
                if (typeOwner.Rid != 0)
                {
                    hash.Add(typeOwner.Raw);
                }
            }
            for (uint rid = oldLastValid.EventRid + 1; rid <= lastValid.EventRid; rid++)
            {
                var typeOwner = cmod.GetEventOwnerToken(rid);
                if (typeOwner.Rid != 0)
                {
                    hash.Add(typeOwner.Raw);
                }
            }
            for (uint rid = oldLastValid.PropertyRid + 1; rid <= lastValid.PropertyRid; rid++)
            {
                var typeOwner = cmod.GetPropertyOwnerToken(rid);
                if (typeOwner.Rid != 0)
                {
                    hash.Add(typeOwner.Raw);
                }
            }
            for (uint rid = oldLastValid.GenericParamRid + 1; rid <= lastValid.GenericParamRid; rid++)
            {
                gpRids.Add(rid);
                var     ownerToken = cmod.GetGenericParamOwnerToken(rid);
                MDToken typeOwner;
                if (ownerToken.Table == Table.TypeDef)
                {
                    typeOwner = ownerToken;
                }
                else if (ownerToken.Table == Table.Method)
                {
                    if (methodRids.Contains(ownerToken.Rid))
                    {
                        continue;
                    }
                    typeOwner = cmod.GetMethodOwnerToken(ownerToken.Rid);
                }
                else
                {
                    continue;
                }
                if (typeOwner.Rid != 0)
                {
                    hash.Add(typeOwner.Raw);
                }
            }
            for (uint rid = oldLastValid.GenericParamConstraintRid + 1; rid <= lastValid.GenericParamConstraintRid; rid++)
            {
                var gpOwner = cmod.GetGenericParamConstraintOwnerToken(rid);
                if (gpRids.Contains(gpOwner.Rid))
                {
                    continue;
                }
                var     ownerToken = cmod.GetGenericParamOwnerToken(gpOwner.Rid);
                MDToken typeOwner;
                if (ownerToken.Table == Table.TypeDef)
                {
                    typeOwner = ownerToken;
                }
                else if (ownerToken.Table == Table.Method)
                {
                    if (methodRids.Contains(ownerToken.Rid))
                    {
                        continue;
                    }
                    typeOwner = cmod.GetMethodOwnerToken(ownerToken.Rid);
                }
                else
                {
                    continue;
                }
                if (typeOwner.Rid != 0)
                {
                    hash.Add(typeOwner.Raw);
                }
            }

            return(hash);
        }
Beispiel #5
0
        void EnableBreakpoints(ModuleMirror monoModule, DbgModule module, List <DbgDotNetCodeLocation> moduleLocations)
        {
            debuggerThread.VerifyAccess();
            if (moduleLocations.Count == 0)
            {
                return;
            }

            var createdBreakpoints = new DbgBoundCodeBreakpointInfo <BoundBreakpointData> [moduleLocations.Count];
            var reflectionModule   = module.GetReflectionModule();
            var state = module.GetOrCreateData <TypeLoadBreakpointState>();

            for (int i = 0; i < createdBreakpoints.Length; i++)
            {
                var         location = moduleLocations[i];
                const ulong address  = DbgObjectFactory.BoundBreakpointNoAddress;

                DbgEngineBoundCodeBreakpointMessage msg;
                var method = reflectionModule.ResolveMethod((int)location.Token, DmdResolveOptions.None);
                if ((object)method == null)
                {
                    msg = DbgEngineBoundCodeBreakpointMessage.CreateFunctionNotFound(GetFunctionName(location.Module, location.Token));
                }
                else
                {
                    msg = state.IsTypeLoaded(method.DeclaringType.MetadataToken) ?
                          DbgEngineBoundCodeBreakpointMessage.CreateCustomWarning(dnSpy_Debugger_DotNet_Mono_Resources.CanNotSetABreakpointWhenProcessIsPaused) :
                          DbgEngineBoundCodeBreakpointMessage.CreateNoError();
                }
                var bpData = new BoundBreakpointData(this, location.Module);
                createdBreakpoints[i] = new DbgBoundCodeBreakpointInfo <BoundBreakpointData>(location, module, address, msg, bpData);
            }

            var boundBreakpoints = objectFactory.Create(createdBreakpoints.ToArray());

            foreach (var ebp in boundBreakpoints)
            {
                if (!ebp.BoundCodeBreakpoint.TryGetData(out BoundBreakpointData bpData))
                {
                    Debug.Assert(ebp.BoundCodeBreakpoint.IsClosed);
                    continue;
                }
                bpData.EngineBoundCodeBreakpoint = ebp;
                if (bpData.Breakpoint != null)
                {
                    bpData.Breakpoint.Tag = bpData;
                }
            }

            for (int i = 0; i < boundBreakpoints.Length; i++)
            {
                var boundBp  = boundBreakpoints[i];
                var location = (DbgDotNetCodeLocation)boundBp.BoundCodeBreakpoint.Breakpoint.Location;
                var method   = reflectionModule.ResolveMethod((int)location.Token, DmdResolveOptions.None);
                if ((object)method == null)
                {
                    continue;
                }

                state.AddBreakpoint(method.DeclaringType.MetadataToken, boundBp, () => EnableBreakpointCore(module, method, boundBp, location));
            }
        }