Пример #1
0
        /// <summary>
        /// Searches for CoreCLR runtimes in a process
        /// </summary>
        /// <param name="pid">Process ID</param>
        /// <param name="runtimePath">Path of CoreCLR.dll or path of the CoreCLR runtime. This is
        /// used to find <c>dbgshim.dll</c> if <paramref name="dbgshimPath"/> is null</param>
        /// <param name="dbgshimPath">Filename of dbgshim.dll or null if we should look in
        /// <paramref name="runtimePath"/></param>
        /// <returns></returns>
        public unsafe static CoreCLRInfo[] GetCoreCLRInfos(int pid, string?runtimePath, string?dbgshimPath)
        {
            var dbgShimState = GetOrCreateDbgShimState(runtimePath, dbgshimPath);

            if (dbgShimState is null)
            {
                return(Array.Empty <CoreCLRInfo>());
            }
            int hr = dbgShimState.EnumerateCLRs !((uint)pid, out var pHandleArray, out var pStringArray, out uint dwArrayLength);

            if (hr < 0 || dwArrayLength == 0)
            {
                return(Array.Empty <CoreCLRInfo>());
            }
            try {
                var ary = new CoreCLRInfo[dwArrayLength];
                var psa = (IntPtr *)pStringArray;
                for (int i = 0; i < ary.Length; i++)
                {
                    var version = GetVersionStringFromModule(dbgShimState, (uint)pid, psa[i], out string coreclrFilename);
                    ary[i] = new CoreCLRInfo(pid, coreclrFilename, version, dbgShimState.Filename !);
                }

                return(ary);
            }
            finally {
                hr = dbgShimState.CloseCLREnumeration !(pHandleArray, pStringArray, dwArrayLength);
                Debug.Assert(hr >= 0);
            }
        }
Пример #2
0
        /// <summary>
        /// Searches for CoreCLR runtimes in a process
        /// </summary>
        /// <param name="pid">Process ID</param>
        /// <param name="runtimePath">Path of CoreCLR.dll or path of the CoreCLR runtime. This is
        /// used to find <c>dbgshim.dll</c> if <paramref name="dbgshimPath"/> is null</param>
        /// <param name="dbgshimPath">Filename of dbgshim.dll or null if we should look in
        /// <paramref name="runtimePath"/></param>
        /// <returns></returns>
        public unsafe static CoreCLRInfo[] GetCoreCLRInfos(int pid, string runtimePath, string dbgshimPath)
        {
            var dbgShimState = GetOrCreateDbgShimState(runtimePath, dbgshimPath);

            if (dbgShimState == null)
            {
                return(new CoreCLRInfo[0]);
            }

            IntPtr pHandleArray, pStringArray;
            uint   dwArrayLength;
            int    hr = dbgShimState.EnumerateCLRs((uint)pid, out pHandleArray, out pStringArray, out dwArrayLength);

            if (hr < 0 || dwArrayLength == 0)
            {
                return(new CoreCLRInfo[0]);
            }
            try {
                var ary = new CoreCLRInfo[dwArrayLength];
                var psa = (IntPtr *)pStringArray;
                for (int i = 0; i < ary.Length; i++)
                {
                    string moduleFilename;
                    var    version = GetVersionStringFromModule(dbgShimState, (uint)pid, psa[i], out moduleFilename);
                    ary[i] = new CoreCLRInfo(pid, moduleFilename, version, dbgShimState.Filename);
                }

                return(ary);
            }
            finally {
                hr = dbgShimState.CloseCLREnumeration(pHandleArray, pStringArray, dwArrayLength);
                Debug.Assert(hr >= 0);
            }
        }