Пример #1
0
        private ClrInfo[] InitVersions()
        {
            List <ClrInfo> versions = new List <ClrInfo>();

            foreach (ModuleInfo module in EnumerateModules())
            {
                if (!ClrInfoProvider.IsSupportedRuntime(module, out var flavor, out var platform))
                {
                    continue;
                }

                string dacFileName = ClrInfoProvider.GetDacFileName(flavor, platform);
                string dacLocation = Path.Combine(Path.GetDirectoryName(module.FileName), dacFileName);

                if (platform == Platform.Linux)
                {
                    if (File.Exists(dacLocation))
                    {
                        // Works around issue https://github.com/dotnet/coreclr/issues/20205
                        int    processId     = Process.GetCurrentProcess().Id;
                        string tempDirectory = Path.Combine(Path.GetTempPath(), "clrmd" + processId);
                        Directory.CreateDirectory(tempDirectory);

                        string symlink = Path.Combine(tempDirectory, dacFileName);
                        if (LinuxFunctions.symlink(dacLocation, symlink) == 0)
                        {
                            dacLocation = symlink;
                        }
                    }
                    else
                    {
                        dacLocation = dacFileName;
                    }
                }
                else if (!File.Exists(dacLocation) || !PlatformFunctions.IsEqualFileVersion(dacLocation, module.Version))
                {
                    dacLocation = null;
                }

                VersionInfo version         = module.Version;
                string      dacAgnosticName = ClrInfoProvider.GetDacRequestFileName(flavor, Architecture, Architecture, version, platform);
                string      dacRegularName  = ClrInfoProvider.GetDacRequestFileName(flavor, IntPtr.Size == 4 ? Architecture.X86 : Architecture.Amd64, Architecture, version, platform);

                DacInfo dacInfo = new DacInfo(_dataReader, dacAgnosticName, Architecture)
                {
                    FileSize  = module.FileSize,
                    TimeStamp = module.TimeStamp,
                    FileName  = dacRegularName,
                    Version   = module.Version
                };

                versions.Add(new ClrInfo(this, flavor, module, dacInfo, dacLocation));
            }

            ClrInfo[] result = versions.ToArray();
            Array.Sort(result);
            return(result);
        }
Пример #2
0
        private ClrInfo[] GetOrCreateClrVersions()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(DataTarget));
            }

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

            var arch     = DataReader.Architecture;
            var versions = new List <ClrInfo>(2);

            foreach (var module in EnumerateModules())
            {
                byte[] runtimeBuildId   = Array.Empty <byte>();
                int    runtimeTimeStamp = 0;
                int    runtimeFileSize  = 0;

                if (ClrInfoProvider.IsSupportedRuntime(module, out var flavor))
                {
                    runtimeTimeStamp = module.IndexTimeStamp;
                    runtimeFileSize  = module.IndexFileSize;
                    runtimeBuildId   = module.BuildId;
                }
                else
                {
                    continue;
                }

                string dacFileName = ClrInfoProvider.GetDacFileName(flavor);
                string?dacLocation = Path.Combine(Path.GetDirectoryName(module.FileName) !, dacFileName);

                if (!File.Exists(dacLocation) || !PlatformFunctions.IsEqualFileVersion(dacLocation, module.Version))
                {
                    dacLocation = null;
                }

                var    version         = module.Version;
                string dacAgnosticName = ClrInfoProvider.GetDacRequestFileName(flavor, arch, arch, version);
                string dacRegularName  = ClrInfoProvider.GetDacRequestFileName(flavor, IntPtr.Size == 4 ? Architecture.X86 : Architecture.Amd64, arch, version);

                var dacInfo = new DacInfo(dacLocation, dacRegularName, dacAgnosticName, arch, runtimeFileSize, runtimeTimeStamp, version, runtimeBuildId);
                versions.Add(new ClrInfo(this, flavor, module, dacInfo));
            }

            _clrs = versions.ToArray();
            return(_clrs);
        }
Пример #3
0
 public static string GetDacRequestFileName(ClrFlavor flavor, Architecture currentArchitecture, Architecture targetArchitecture, VersionInfo clrVersion)
 {
     //method is kept for backward compatibility //TODO: remove
     return(ClrInfoProvider.GetDacRequestFileName(flavor, currentArchitecture, targetArchitecture, clrVersion, Platform.Windows));
 }