private unsafe void InitDebugAttributes() { MetaDataImport metadata = GetMetadataImport(); if (metadata == null) { _debugMode = DebuggableAttribute.DebuggingModes.None; return; } try { if (metadata.GetCustomAttributeByName(0x20000001, "System.Diagnostics.DebuggableAttribute", out IntPtr data, out uint cbData) && cbData >= 4) { byte * b = (byte *)data.ToPointer(); ushort opt = b[2]; ushort dbg = b[3]; _debugMode = (DebuggableAttribute.DebuggingModes)((dbg << 8) | opt); } else { _debugMode = DebuggableAttribute.DebuggingModes.None; } }
internal Module(AppDomain appDomain, ICorDebugModule corModule) { this.appDomain = appDomain; this.process = appDomain.Process; this.corModule = corModule; unresolvedAssembly = TypeSystemExtensions.LoadModuleAsync(this, corModule); metaData = new MetaDataImport(corModule); if (IsDynamic || IsInMemory) { name = corModule.GetName(); } else { fullPath = corModule.GetName(); name = System.IO.Path.GetFileName(FullPath); } SetJITCompilerFlags(); LoadSymbolsFromDisk(process.Options.SymbolsSearchPaths); ResetJustMyCode(); LoadSymbolsDynamic(); }
static public DebugType Create(Process process, ICorDebugClass corClass, params ICorDebugType[] typeArguments) { MetaDataImport metaData = process.GetModule(corClass.Module).MetaData; bool isValueType = false; uint superClassToken = metaData.GetTypeDefProps(corClass.Token).SuperClassToken; if ((superClassToken & 0xFF000000) == 0x02000000) // TypeDef { if (metaData.GetTypeDefProps(superClassToken).Name == "System.ValueType") { isValueType = true; } } if ((superClassToken & 0xFF000000) == 0x01000000) // TypeRef { if (metaData.GetTypeRefProps(superClassToken).Name == "System.ValueType") { isValueType = true; } } int getArgsCount = metaData.GetGenericParamCount(corClass.Token); Array.Resize(ref typeArguments, getArgsCount); ICorDebugType corType = corClass.CastTo <ICorDebugClass2>().GetParameterizedType( isValueType ? (uint)CorElementType.VALUETYPE : (uint)CorElementType.CLASS, typeArguments ); return(Create(process, corType)); }
internal StackFrame(Thread thread, ICorDebugILFrame corILFrame, uint chainIndex, uint frameIndex) { this.process = thread.Process; this.thread = thread; this.appDomain = process.AppDomains[corILFrame.GetFunction().GetClass().GetModule().GetAssembly().GetAppDomain()]; this.corILFrame = corILFrame; this.corILFramePauseSession = process.PauseSession; this.corFunction = corILFrame.GetFunction(); this.chainIndex = chainIndex; this.frameIndex = frameIndex; MetaDataImport metaData = thread.Process.Modules[corFunction.GetClass().GetModule()].MetaData; int methodGenArgs = metaData.EnumGenericParams(corFunction.GetToken()).Length; // Class parameters are first, then the method ones List <ICorDebugType> corGenArgs = ((ICorDebugILFrame2)corILFrame).EnumerateTypeParameters().ToList(); // Remove method parametrs at the end corGenArgs.RemoveRange(corGenArgs.Count - methodGenArgs, methodGenArgs); List <DebugType> genArgs = new List <DebugType>(corGenArgs.Count); foreach (ICorDebugType corGenArg in corGenArgs) { genArgs.Add(DebugType.CreateFromCorType(this.AppDomain, corGenArg)); } DebugType debugType = DebugType.CreateFromCorClass( this.AppDomain, null, corFunction.GetClass(), genArgs.ToArray() ); this.methodInfo = (DebugMethodInfo)debugType.GetMember(corFunction.GetToken()); }
private IList <DebugType> FindTypesInModules(String name) { List <DebugType> result = new List <DebugType>(); List <Module> modules = new List <Module>(process.Modules); foreach (Module module in modules) { MetaDataImport metaData = module.MetaData; foreach (TypeDefProps typeDef in module.MetaData.EnumTypeDefProps()) { uint token = typeDef.Token; if (metaData.GetGenericParamCount(token) == 0) { if (name.Equals(typeDef.Name)) { try { result.Add(DebugType.Create(module, token)); } catch { } } } } } return(result); }
internal override MetaDataImport GetMetadataImport() { RevisionValidator.Validate(Revision, _runtime.Revision); if (_metadata != null) { return(_metadata); } _metadata = _runtime.GetMetadataImport(_address); return(_metadata); }
private void InitEnumData() { if (!IsEnum) { throw new InvalidOperationException("Type is not an Enum."); } _enumData = new EnumData(); MetaDataImport import = DesktopModule?.GetMetadataImport(); if (import == null) { return; } IntPtr hnd = IntPtr.Zero; List <string> names = new List <string>(); foreach (int token in import.EnumerateFields((int)_token)) { if (import.GetFieldProps(token, out string name, out FieldAttributes attr, out IntPtr ppvSigBlob, out int pcbSigBlob, out int pdwCPlusTypeFlag, out IntPtr ppValue)) { if ((int)attr == 0x606 && name == "value__") { SigParser parser = new SigParser(ppvSigBlob, pcbSigBlob); if (parser.GetCallingConvInfo(out int sigType) && parser.GetElemType(out int elemType)) { _enumData.ElementType = (ClrElementType)elemType; } } // public, static, literal, has default int intAttr = (int)attr; if ((int)attr == 0x8056) { names.Add(name); SigParser parser = new SigParser(ppvSigBlob, pcbSigBlob); parser.GetCallingConvInfo(out int ccinfo); parser.GetElemType(out int elemType); Type type = ClrRuntime.GetTypeForElementType((ClrElementType)pdwCPlusTypeFlag); if (type != null) { object o = System.Runtime.InteropServices.Marshal.PtrToStructure(ppValue, type); _enumData.NameToValue[name] = o; _enumData.ValueToName[o] = name; } } } } }
public bool TryGetMetadataImport(out MetaDataImport metadata) { if (GetMetaDataInterface(CorGuids.IMetadataImport, out Unknown unknown) != HResult.S_OK) { unknown?.Dispose(); metadata = null; return(false); } bool result = unknown.TryGetInterface(CorGuids.IMetadataImport, out metadata); unknown?.Dispose(); return(result); }
internal Module(Process process, ICorDebugModule pModule) { this.process = process; corModule = pModule; metaData = new MetaDataImport(pModule); fullPath = pModule.Name; LoadSymbols(process.Options.SymbolsSearchPaths); ResetJustMyCodeStatus(); }
internal override MetaDataImport GetMetadataImport() { if (Revision != _runtime.Revision) { ClrDiagnosticsException.ThrowRevisionError(Revision, _runtime.Revision); } if (_metadata != null) { return(_metadata); } _metadata = _runtime.GetMetadataImport(_address); return(_metadata); }
internal static DesktopMethod Create(DesktopRuntimeBase runtime, MetaDataImport metadata, IMethodDescData mdData) { if (mdData == null) { return(null); } MethodAttributes attrs = new MethodAttributes(); if (metadata != null) { attrs = metadata.GetMethodAttributes((int)mdData.MDToken); } return(new DesktopMethod(runtime, mdData.MethodDesc, mdData, attrs)); }
public List <ClrInterface> InitInterfaces() { if (DesktopModule == null) { _interfaces = DesktopHeap.EmptyInterfaceList; return(null); } BaseDesktopHeapType baseType = BaseType as BaseDesktopHeapType; List <ClrInterface> interfaces = baseType != null ? new List <ClrInterface>(baseType.Interfaces) : null; MetaDataImport import = DesktopModule.GetMetadataImport(); if (import == null) { _interfaces = DesktopHeap.EmptyInterfaceList; return(null); } foreach (int token in import.EnumerateInterfaceImpls((int)_token)) { if (import.GetInterfaceImplProps(token, out int mdClass, out int mdIFace)) { if (interfaces == null) { interfaces = new List <ClrInterface>(); } var result = GetInterface(import, mdIFace); if (result != null && !interfaces.Contains(result)) { interfaces.Add(result); } } } if (interfaces == null) { _interfaces = DesktopHeap.EmptyInterfaceList; } else { _interfaces = interfaces.ToArray(); } return(interfaces); }
private void InitFlags() { if (_attributes != 0 || DesktopModule == null) { return; } MetaDataImport import = DesktopModule.GetMetadataImport(); if (import == null) { _attributes = (TypeAttributes)0x70000000; return; } if (!import.GetTypeDefAttributes((int)_token, out _attributes) || _attributes == 0) { _attributes = (TypeAttributes)0x70000000; } }
internal Module(AppDomain appDomain, ICorDebugModule corModule) { this.appDomain = appDomain; this.process = appDomain.Process; this.corModule = corModule; metaData = new MetaDataImport(corModule); if (IsDynamic || IsInMemory) { name = corModule.GetName(); } else { fullPath = corModule.GetName(); name = System.IO.Path.GetFileName(FullPath); } asmFilename = corModule.GetAssembly().GetName(); SetJITCompilerFlags(); LoadSymbolsFromDisk(process.Options.SymbolsSearchPaths); ResetJustMyCodeStatus(); }
internal Module(AppDomain appDomain, ICorDebugModule corModule) { this.appDomain = appDomain; this.process = appDomain.Process; this.corModule = corModule; metaData = new MetaDataImport(corModule); if (IsDynamic || IsInMemory) { name = corModule.GetName(); } else { fullPath = corModule.GetName(); name = System.IO.Path.GetFileName(FullPath); } LoadSymbolsFromDisk(process.Options.SymbolsSearchPaths); ResetJustMyCodeStatus(); }
private void InitILInfo() { ClrModule module = Type?.Module; MetaDataImport mdImport = module.MetadataImport; uint rva = 0; if (mdImport != null) { rva = mdImport.GetRva((int)_token); } ulong il = _runtime.GetILForModule(module, rva); if (il != 0) { _il = new ILInfo(); if (_runtime.ReadByte(il, out byte b)) { bool isTinyHeader = (b & (IMAGE_COR_ILMETHOD.FormatMask >> 1)) == IMAGE_COR_ILMETHOD.TinyFormat; if (isTinyHeader) { _il.Address = il + 1; _il.Length = b >> (int)(IMAGE_COR_ILMETHOD.FormatShift - 1); _il.LocalVarSignatureToken = IMAGE_COR_ILMETHOD.mdSignatureNil; } else if (_runtime.ReadDword(il, out uint tmp)) { _il.Flags = tmp; _runtime.ReadDword(il + 4, out tmp); _il.Length = (int)tmp; _runtime.ReadDword(il + 8, out tmp); _il.LocalVarSignatureToken = tmp; _il.Address = il + 12; } } } }
public DesktopModule(DesktopRuntimeBase runtime, ulong address, IModuleData data, string name, string assemblyName) : base(runtime) { _address = address; Revision = runtime.Revision; _imageBase = data.ImageBase; _assemblyName = assemblyName; _isPE = data.IsPEFile; _reflection = data.IsReflection || string.IsNullOrEmpty(name); _name = name; ModuleId = data.ModuleId; ModuleIndex = data.ModuleIndex; _metadataStart = data.MetdataStart; _metadataLength = data.MetadataLength; _assemblyAddress = data.Assembly; _size = new Lazy <ulong>(() => runtime.GetModuleSize(address)); // This is very expensive in the minidump case, as we may be heading out to the symbol server or // reading multiple files from disk. Only optimistically fetch this data if we have full memory. if (!runtime.DataReader.IsMinidump && data.LegacyMetaDataImport != IntPtr.Zero) { _metadata = new MetaDataImport(runtime.DacLibrary, data.LegacyMetaDataImport); } }
private ClrInterface GetInterface(MetaDataImport import, int mdIFace) { ClrInterface result = null; if (!import.GetTypeDefProperties(mdIFace, out string name, out TypeAttributes attrs, out int extends)) { name = import.GetTypeRefName(mdIFace); } // TODO: Handle typespec case. if (name != null && !DesktopHeap.Interfaces.TryGetValue(name, out result)) { ClrInterface type = null; if (extends != 0 && extends != 0x01000000) { type = GetInterface(import, extends); } result = new DesktopHeapInterface(name, type); DesktopHeap.Interfaces[name] = result; } return(result); }
private void InitFields() { if (_fields != null) { return; } if (IsFree) { _fields = new List <ClrInstanceField>(); return; } DesktopRuntimeBase runtime = DesktopHeap.DesktopRuntime; IFieldInfo fieldInfo = runtime.GetFieldInfo(_constructedMT); if (fieldInfo == null) { // Fill fields so we don't repeatedly try to init these fields on error. _fields = new List <ClrInstanceField>(); return; } _fields = new List <ClrInstanceField>((int)fieldInfo.InstanceFields); // Add base type's fields. if (BaseType != null) { foreach (var field in BaseType.Fields) { _fields.Add(field); } } int count = (int)(fieldInfo.InstanceFields + fieldInfo.StaticFields) - _fields.Count; ulong nextField = fieldInfo.FirstField; int i = 0; MetaDataImport import = null; if (nextField != 0 && DesktopModule != null) { import = DesktopModule.GetMetadataImport(); } while (i < count && nextField != 0) { IFieldData field = runtime.GetFieldData(nextField); if (field == null) { break; } // We don't handle context statics. if (field.IsContextLocal) { nextField = field.NextField; continue; } // Get the name of the field. string name = null; FieldAttributes attr = FieldAttributes.PrivateScope; int sigLen = 0; IntPtr ppValue = IntPtr.Zero; IntPtr fieldSig = IntPtr.Zero; if (import != null) { import.GetFieldProps((int)field.FieldToken, out name, out attr, out fieldSig, out sigLen, out int pdwCPlusTypeFlab, out ppValue); } // If we couldn't figure out the name, at least give the token. if (import == null || name == null) { name = string.Format("<ERROR:{0:X}>", field.FieldToken); } // construct the appropriate type of field. if (field.IsThreadLocal) { if (_threadStatics == null) { _threadStatics = new List <ClrThreadStaticField>((int)fieldInfo.ThreadStaticFields); } // TODO: Renable when thread statics are fixed. //m_threadStatics.Add(new RealTimeMemThreadStaticField(m_heap, field, name)); } else if (field.IsStatic) { if (_statics == null) { _statics = new List <ClrStaticField>(); } // TODO: Enable default values. /* * object defaultValue = null; * * * FieldAttributes sdl = FieldAttributes.Static | FieldAttributes.HasDefault | FieldAttributes.Literal; * if ((attr & sdl) == sdl) * Debugger.Break(); */ _statics.Add(new DesktopStaticField(DesktopHeap, field, this, name, attr, null, fieldSig, sigLen)); } else // instance variable { _fields.Add(new DesktopInstanceField(DesktopHeap, field, name, attr, fieldSig, sigLen)); } i++; nextField = field.NextField; } _fields.Sort((a, b) => a.Offset.CompareTo(b.Offset)); }
internal Module(Process process, ICorDebugModule pModule) { this.process = process; corModule = pModule; metaData = new MetaDataImport(pModule); fullPath = pModule.Name; LoadSymbols(process.Options.SymbolsSearchPaths); ResetJustMyCodeStatus(); }
internal Module(AppDomain appDomain, ICorDebugModule corModule) { this.appDomain = appDomain; this.process = appDomain.Process; this.corModule = corModule; unresolvedAssembly = TypeSystemExtensions.LoadModuleAsync(this, corModule); metaData = new MetaDataImport(corModule); if (IsDynamic || IsInMemory) { name = corModule.GetName(); } else { fullPath = corModule.GetName(); name = System.IO.Path.GetFileName(FullPath); } SetJITCompilerFlags(); LoadSymbolsFromDisk(process.Options.SymbolsSearchPaths); ResetJustMyCode(); LoadSymbolsDynamic(); }