Beispiel #1
0
        private void InitDebugAttributes()
        {
            ICorDebug.IMetadataImport metadata = GetMetadataImport();
            if (metadata == null)
            {
                _debugMode = DebuggableAttribute.DebuggingModes.None;
                return;
            }

            try
            {
                IntPtr data;
                uint   cbData;
                int    hr = metadata.GetCustomAttributeByName(0x20000001, "System.Diagnostics.DebuggableAttribute", out data, out cbData);
                if (hr != 0 || cbData <= 4)
                {
                    _debugMode = DebuggableAttribute.DebuggingModes.None;
                    return;
                }

                unsafe
                {
                    byte * b   = (byte *)data.ToPointer();
                    UInt16 opt = b[2];
                    UInt16 dbg = b[3];

                    _debugMode = (System.Diagnostics.DebuggableAttribute.DebuggingModes)((dbg << 8) | opt);
                }
            }
            catch (SEHException)
            {
                _debugMode = DebuggableAttribute.DebuggingModes.None;
            }
        }
Beispiel #2
0
        public DesktopModule(DesktopRuntimeBase runtime, IModuleData data, string name, string assemblyName, ulong size)
            : base(runtime)
        {
            Revision      = runtime.Revision;
            _imageBase    = data.ImageBase;
            _assemblyName = assemblyName;
            _isPE         = data.IsPEFile;
            _reflection   = data.IsReflection || string.IsNullOrEmpty(name) || !name.Contains("\\");
            _name         = name;
            ModuleId      = data.ModuleId;
            _size         = size;

            _metadata = data.LegacyMetaDataImport as ICorDebug.IMetadataImport;
        }
Beispiel #3
0
        internal override ICorDebug.IMetadataImport GetMetadataImport()
        {
            if (Revision != _runtime.Revision)
            {
                ClrDiagnosticsException.ThrowRevisionError(Revision, _runtime.Revision);
            }

            if (_metadata != null)
            {
                return(_metadata);
            }

            _metadata = _runtime.GetMetadataImport(_address);
            return(_metadata);
        }
Beispiel #4
0
        internal static DesktopMethod Create(DesktopRuntimeBase runtime, ICorDebug.IMetadataImport metadata, IMethodDescData mdData)
        {
            if (mdData == null)
            {
                return(null);
            }

            MethodAttributes attrs = 0;

            if (metadata?.GetMethodProps(mdData.MDToken, out int pClass, null, 0, out int methodLength, out attrs, out IntPtr blob, out uint blobLen, out uint codeRva, out uint implFlags) < 0)
            {
                attrs = 0;
            }

            return(new DesktopMethod(runtime, mdData.MethodDesc, mdData, attrs));
        }
Beispiel #5
0
        internal static DesktopMethod Create(DesktopRuntimeBase runtime, ICorDebug.IMetadataImport metadata, IMethodDescData mdData)
        {
            if (mdData == null)
                return null;

            MethodAttributes attrs = (MethodAttributes)0;
            if (metadata != null)
            {
                int pClass, methodLength;
                uint blobLen, codeRva, implFlags;
                IntPtr blob;
                if (metadata.GetMethodProps(mdData.MDToken, out pClass, null, 0, out methodLength, out attrs, out blob, out blobLen, out codeRva, out implFlags) < 0)
                    attrs = (MethodAttributes)0;
            }

            return new DesktopMethod(runtime, mdData.MethodDesc, mdData, attrs);
        }
Beispiel #6
0
        public DesktopModule(DesktopRuntimeBase runtime, ulong address, IModuleData data, string name, string assemblyName, ulong size)
            : base(runtime)
        {
            _address         = address;
            Revision         = runtime.Revision;
            _imageBase       = data.ImageBase;
            _assemblyName    = assemblyName;
            _isPE            = data.IsPEFile;
            _reflection      = data.IsReflection || string.IsNullOrEmpty(name) || !name.Contains("\\");
            _name            = name;
            ModuleId         = data.ModuleId;
            ModuleIndex      = data.ModuleIndex;
            _metadataStart   = data.MetdataStart;
            _metadataLength  = data.MetadataLength;
            _assemblyAddress = data.Assembly;
            _size            = size;

            if (!runtime.DataReader.IsMinidump)
            {
                // 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.
                _metadata = data.LegacyMetaDataImport as ICorDebug.IMetadataImport;
            }
            else
            {
                // If we are a minidump and metadata isn't mapped in, attempt to fetch this module from the symbol server
                // on a background thread.
#if !V2_SUPPORT
                if (_isPE && _metadataStart != 0 && _metadataLength > 0)
                {
                    int    read;
                    byte[] tmp = new byte[1];
                    if (!_runtime.DataReader.ReadMemory(_metadataStart, tmp, 1, out read) || read == 0)
                    {
                        int filesize, imagesize;
                        if (PEFile.TryGetIndexProperties(new ReadVirtualStream(_runtime.DataReader, (long)data.ImageBase, (long)size), true, out imagesize, out filesize))
                        {
                            _runtime.DataTarget.SymbolLocator.PrefetchBinary(Path.GetFileName(assemblyName), imagesize, filesize);
                        }
                    }
                }
#endif
            }
        }
Beispiel #7
0
        private unsafe void InitILInfo()
        {
            ClrModule module = Type?.Module;

            ICorDebug.IMetadataImport metadataImport = module?.MetadataImport as ICorDebug.IMetadataImport;

            if (metadataImport != null)
            {
                uint rva;
                uint flags;
                if (metadataImport.GetRVA(_token, out rva, out flags) == 0)
                {
                    ulong il = _runtime.GetILForModule(module, rva);
                    if (il != 0)
                    {
                        _il = new ILInfo();

                        uint tmp;
                        byte b;
                        if (_runtime.ReadByte(il, out 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 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;
                            }
                        }
                    }
                }
            }
        }
Beispiel #8
0
        public DesktopModule(DesktopRuntimeBase runtime, ulong address, IModuleData data, string name, string assemblyName, ulong size)
            : base(runtime)
        {
            Revision = runtime.Revision;
            _imageBase = data.ImageBase;
            _assemblyName = assemblyName;
            _isPE = data.IsPEFile;
            _reflection = data.IsReflection || string.IsNullOrEmpty(name) || !name.Contains("\\");
            _name = name;
            ModuleId = data.ModuleId;
            ModuleIndex = data.ModuleIndex;
            _metadataStart = data.MetdataStart;
            _metadataLength = data.MetadataLength;
            _assemblyAddress = data.Assembly;
            _size = size;

            if (!runtime.DataReader.IsMinidump)
            {
                // 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.
                _metadata = data.LegacyMetaDataImport as ICorDebug.IMetadataImport;
            }
            else
            {
                // If we are a minidump and metadata isn't mapped in, attempt to fetch this module from the symbol server
                // on a background thread.
#if !V2_SUPPORT
                if (_isPE && _metadataStart != 0 && _metadataLength > 0)
                {
                    int read;
                    byte[] tmp = new byte[1];
                    if (!_runtime.DataReader.ReadMemory(_metadataStart, tmp, 1, out read) || read == 0)
                    {
                        int filesize, imagesize;
                        if (PEFile.TryGetIndexProperties(new ReadVirtualStream(_runtime.DataReader, (long)data.ImageBase, (long)size), true, out imagesize, out filesize))
                            _runtime.DataTarget.SymbolLocator.PrefetchBinary(Path.GetFileName(assemblyName), imagesize, filesize);
                    }
                }
#endif
            }
        }
Beispiel #9
0
        internal override ICorDebug.IMetadataImport GetMetadataImport()
        {
            if (Revision != _runtime.Revision)
            {
                ClrDiagnosticsException.ThrowRevisionError(Revision, _runtime.Revision);
            }

            if (_metadata != null)
            {
                return(_metadata);
            }

            ulong module = GetDomainModule(null);

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

            _metadata = _runtime.GetMetadataImport(module);
            return(_metadata);
        }
Beispiel #10
0
        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));

            if (!runtime.DataReader.IsMinidump)
            {
                // 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.
                _metadata = data.LegacyMetaDataImport as ICorDebug.IMetadataImport;
            }
        }
Beispiel #11
0
        internal override ICorDebug.IMetadataImport GetMetadataImport()
        {
            if (Revision != _runtime.Revision)
                ClrDiagnosticsException.ThrowRevisionError(Revision, _runtime.Revision);

            if (_metadata != null)
                return _metadata;

            ulong module = GetDomainModule(null);
            if (module == 0)
                return null;

            _metadata = _runtime.GetMetadataImport(module);
            return _metadata;
        }