Exemple #1
0
        /// <summary>
        /// 派生クラスで実装された場合、実行中のプロセスにアタッチされたVisual Studioデバッガーの情報を返します。
        /// </summary>
        /// <returns>
        /// 実行中のプロセスにアタッチされたVisual Studioデバッガーの情報。
        /// 情報を取得できない場合は<c>null</c>。
        /// </returns>
        public override DebuggerInfo GetCurrentDebuggerInfo()
        {
            if (!Debugger.IsAttached)
            {
                return(null);
            }

            var p = Process.GetCurrentProcess();

            while (p != null)
            {
                if (p.ProcessName.Equals("devenv", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(new DebuggerInfo()
                    {
                        DebuggerType = GetType(),
                        ProcessId = p.Id
                    });
                }

                var pbi = new ProcessBasicInformation();
                int returnLength;
                var status = NativeMethods.NtQueryInformationProcess(
                    p.Handle,
                    0,
                    ref pbi,
                    Marshal.SizeOf(typeof(ProcessBasicInformation)),
                    out returnLength);
                if (status != 0)
                {
                    return(null);
                }

                p = Process.GetProcessById(pbi.InheritedFromUniqueProcessId.ToInt32());
            }
            return(null);
        }
Exemple #2
0
 internal static extern int NtQueryInformationProcess(IntPtr processHandle, int processInformationClass, ref ProcessBasicInformation processInformation, int processInformationLength, out int returnLength);