Пример #1
0
        public static void Main(string[] args)
        {
            Options options = new Options();

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                return;
            }

            Process process = null;

            try
            {
                process = GetProcess(options.Process);
            }
            catch (ArgumentException ex)
            {
                ConsoleMixins.WriteError(ex.Message);
                Environment.ExitCode = -1;
                return;
            }


            if (RedirectToX86(process, Console.Out, Console.Error))
            {
                return;
            }

            if (!string.IsNullOrEmpty(options.OutputFolder) || !IsAnyOptionSet(options))
            {
                options.FullDump = true;
            }
            using (var output = GetOutput(options))
                try
                {
                    Dumper.Start(options, process, output);
                }
                catch (ClrDiagnosticsException cex) when(cex.HResult == (int)ClrDiagnosticsException.HR.DebuggerError)
                {
                    ConsoleMixins.WriteError(
                        "Error attaching to process: {0}. Is another debugger attached?{3}Additional details: {2}",
                        process.ProcessName, process.Id, cex.Message, Environment.NewLine);
                    Environment.ExitCode = -1;
                }
            catch (Exception ex)
            {
                ConsoleMixins.WriteError("Error attaching to process '{0}' (pid: {1}).", process.ProcessName,
                                         process.Id);
                ConsoleMixins.WriteError("Additional details: {1}", ex.Message);
                Environment.ExitCode = -1;
            }
        }
Пример #2
0
        public void DumpThreadStacks(IList <Tuple <int, string> > threads)
        {
            if (threads.Count == 0)
            {
                return;
            }

            try
            {
                _clrRuntime.Value.Flush();
                foreach (var stack in threads.Select(i => DumpThreadStack(i.Item1, i.Item2, _clrRuntime.Value)))
                {
                    Console.WriteLine(stack);
                }
            }
            catch (Exception ex)
            {
                ConsoleMixins.WriteError(ex.Message);
            }
        }