Beispiel #1
0
        public void StartProcess()
        {
            Debugger.Options.StopOnLogMessage = false;
            if (options.PID != 0)
            {
                string clrVersion = string.IsNullOrEmpty(options.CLRVersion) ? MdbgVersionPolicy.GetDefaultAttachVersion(options.PID) : options.CLRVersion;
                Process = Debugger.Attach(options.PID, null, clrVersion);
                WriteLine("Attached to " + options.PID);
                Process.Go().WaitOne();
            }
            else if (!string.IsNullOrEmpty(options.Executable))
            {
                var clrVersion = MdbgVersionPolicy.GetDefaultLaunchVersion(options.Executable);
                Process = Debugger.Processes.CreateLocalProcess(new CorDebugger(clrVersion));
                if (Process == null)
                {
                    throw new Exception("Could not create debugging interface for runtime version " + clrVersion);
                }
                Process.DebugMode = DebugModeFlag.Debug;
                Process.CreateProcess(options.Executable, configuration.arguments != null ? configuration.arguments : "");
                Process.Go().WaitOne();
            }
            else
            {
                WriteLine(options.GetUsage());
                return;
            }

            Console.CancelKeyPress += OnAbort;
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            int pid;

            if (args.Length == 1 && int.TryParse(args[0], out pid))
            {
                try
                {
                    var process = Process.GetProcessById(int.Parse(args[0]));

                    var mh = new CLRMetaHost();
                    mh.EnumerateLoadedRuntimes(process.Id);
                    var version     = MdbgVersionPolicy.GetDefaultAttachVersion(process.Id);
                    var debugger    = new CorDebugger(version);
                    var processInfo = new ProcessInfo(process, debugger);
                    foreach (var line in processInfo.GetDisplayStackTrace())
                    {
                        Console.WriteLine(line);
                    }
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("Error getting process thread dump: " + e);
                }
            }
            else
            {
                Console.Error.WriteLine("Simple utility to generate .NET managed process thread dump (similar to Java jstack)");
                Console.Error.WriteLine("Usage: " + AppDomain.CurrentDomain.FriendlyName + " <PID>");
            }
        }
Beispiel #3
0
        public ActionResult MDbgAdd()
        {
            string deeVersion = MdbgVersionPolicy.GetDefaultAttachVersion(Process.GetCurrentProcess().Id);

            if (Request.IsPostBack())
            {
                string message = commentService.MDbgAdd();
                return(Content("调用栈------:mdbg:" + message));
            }
            return(View());
        }
Beispiel #4
0
 private void ProcessArgs()
 {
     if (options.EnumProcesses)
     {
         EnumProcesses();
     }
     else if (!string.IsNullOrEmpty(options.PrintDebuggerVersionForAssembly))
     {
         Console.WriteLine(MdbgVersionPolicy.GetDefaultLaunchVersion(options.PrintDebuggerVersionForAssembly));
     }
     else if (!string.IsNullOrEmpty(options.PrintRuntimeVersionForAssembly))
     {
         Console.WriteLine(MdbgVersionPolicy.GetDefaultRuntimeForFile(options.PrintRuntimeVersionForAssembly));
     }
     else
     {
         InitDebugging();
         StartProcess();
         StartMonitoring();
     }
 }
Beispiel #5
0
        private static string FindAttachVersion(int pid)
        {
            var attachVersion     = MdbgVersionPolicy.GetDefaultAttachVersion(pid);
            var installedVersions = new CLRMetaHost().EnumerateInstalledRuntimes().Select(r => r.GetVersionString()).ToList();

            if (installedVersions.Contains(attachVersion))
            {
                return(attachVersion);
            }

            var matchingVersion = installedVersions.Find(v => attachVersion.Contains(v.Replace("v", "")) || v.Contains(attachVersion.Replace("v", "")));

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

            Console.WriteLine("Error: could not find installed runtime attach version.");
            Console.WriteLine("  Default attach version: " + attachVersion);
            Console.WriteLine("  Installed versions: " + string.Join(", ", installedVersions));
            return(null);
        }
        /// <summary>
        /// Attach a debugger to the target process.
        /// </summary>
        void AttachDebuggerToProcess()
        {
            string version =
                MdbgVersionPolicy.GetDefaultAttachVersion(this.DiagnosticsProcess.Id);

            if (string.IsNullOrEmpty(version))
            {
                throw new ApplicationException("Can't determine what version of the CLR to " +
                                               "attach to the process.");
            }
            this.MDbgProcess = this.Debugger.Attach(this.DiagnosticsProcess.Id, null, version);

            bool result = this.MDbgProcess.Go().WaitOne();

            if (!result)
            {
                throw new ApplicationException(
                          string.Format(@"The process with an ID {0} could not be "
                                        + "attached. Operation time out.", this.DiagnosticsProcess.Id));
            }

            this.MDbgProcess.PostDebugEvent +=
                new PostCallbackEventHandler(MDbgProcess_PostDebugEvent);
        }