示例#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
        static DataTarget()
        {
#if !NET45
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                PlatformFunctions = new LinuxFunctions();
            }
            else
#endif
            PlatformFunctions = new WindowsFunctions();
        }
示例#3
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);
        }
示例#4
0
#pragma warning disable 0618
        private ClrInfo[] InitVersions()
        {
            List <ClrInfo> versions = new List <ClrInfo>();

            foreach (ModuleInfo module in EnumerateModules())
            {
                string clrName = Path.GetFileNameWithoutExtension(module.FileName).ToLower();

                if (clrName != "clr" && clrName != "mscorwks" && clrName != "coreclr" && clrName != "mrt100_app" && clrName != "libcoreclr")
                {
                    continue;
                }

                ClrFlavor flavor;
                switch (clrName)
                {
                case "mrt100_app":
                    _native = module;
                    continue;

                case "libcoreclr":
                case "coreclr":
                    flavor = ClrFlavor.Core;
                    break;

                default:
                    flavor = ClrFlavor.Desktop;
                    break;
                }

                bool isLinux = clrName == "libcoreclr";

                string dacLocation = Path.Combine(Path.GetDirectoryName(module.FileName), DacInfo.GetDacFileName(flavor, Architecture));

                if (isLinux)
                {
                    dacLocation = Path.ChangeExtension(dacLocation, ".so");
                }

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

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

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

                module.IsRuntime = true; //strange logic here (originally from the ClrInfo constructor)

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

            ClrInfo[] result = versions.ToArray();
            Array.Sort(result);
            return(result);
        }
示例#5
0
#pragma warning disable 0618
        private ClrInfo[] InitVersions()
        {
            List <ClrInfo> versions = new List <ClrInfo>();

            foreach (ModuleInfo module in EnumerateModules())
            {
                string clrName = Path.GetFileNameWithoutExtension(module.FileName).ToLower();

                if (clrName != "clr" && clrName != "mscorwks" && clrName != "coreclr" && clrName != "mrt100_app" && clrName != "libcoreclr")
                {
                    continue;
                }

                ClrFlavor flavor;
                switch (clrName)
                {
                case "mrt100_app":
                    _native = module;
                    continue;

                case "libcoreclr":
                case "coreclr":
                    flavor = ClrFlavor.Core;
                    break;

                default:
                    flavor = ClrFlavor.Desktop;
                    break;
                }

                bool isLinux = clrName == "libcoreclr";

                const string LinuxDacFileName = "libmscordaccore.so";

                string dacLocation = Path.Combine(Path.GetDirectoryName(module.FileName), isLinux ? LinuxDacFileName : DacInfo.GetDacFileName(flavor, Architecture));

                if (isLinux)
                {
                    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.ToString());
                        Directory.CreateDirectory(tempDirectory);

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

                VersionInfo version = module.Version;
                string      dacAgnosticName;
                string      dacFileName;
                if (isLinux)
                {
                    // Linux never has a "long" named DAC
                    dacAgnosticName = LinuxDacFileName;
                    dacFileName     = LinuxDacFileName;
                }
                else
                {
                    dacAgnosticName = DacInfo.GetDacRequestFileName(flavor, Architecture, Architecture, version);
                    dacFileName     = DacInfo.GetDacRequestFileName(flavor, IntPtr.Size == 4 ? Architecture.X86 : Architecture.Amd64, Architecture, version);
                }

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

                module.IsRuntime = true; //strange logic here (originally from the ClrInfo constructor)

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

            ClrInfo[] result = versions.ToArray();
            Array.Sort(result);
            return(result);
        }