Example #1
0
 public Debugger(CommandLineOptions options)
 {
     ValidateOptions(options);
     _options = options;
     _logger = options.Verbose ? Console.Out : TextWriter.Null;
     _dumpFolder = options.DumpFolderForNewlyStartedProcess ?? Directory.GetCurrentDirectory();
 }
Example #2
0
 public Debugger(CommandLineOptions options)
 {
     ValidateOptions(options);
     _options = options;
     _logger = options.Verbose ? Console.Out : TextWriter.Null;
     _dumpFolder = options.DumpFolderForNewlyStartedProcess ?? Path.GetDirectoryName(
         Process.GetCurrentProcess().MainModule.FileName);
 }
Example #3
0
 static void TakeDump(CommandLineOptions options)
 {
     ValidateOptions(options);
     var pid = GetTargetProcessId(options);
     Console.WriteLine("Dumping process id {0}...", pid);
     var dumper = new DumpWriter.DumpWriter(options.Verbose ? Console.Out : null);
     dumper.Dump(pid, OptionToDumpType(options), options.DumpFileName);
     Console.WriteLine("Dump generated successfully, file size {0:N0} bytes",
         new FileInfo(options.DumpFileName).Length);
 }
Example #4
0
        static DumpType OptionToDumpType(CommandLineOptions options)
        {
            if (options.DumpType == 'm')
                return DumpType.Minimal;
            if (options.DumpType == 'h')
                return DumpType.MinimalWithFullCLRHeap;
            if (options.DumpType == 'a')
                return DumpType.FullMemory;

            // Should never get here
            return DumpType.MinimalWithFullCLRHeap;
        }
Example #5
0
        private static DumpType OptionToDumpType(CommandLineOptions options)
        {
            if (options.MinimalDump)
                return DumpType.Minimal;
            if (options.MinimalDumpWithCLRHeap)
                return DumpType.MinimalWithFullCLRHeap;
            if (options.FullDump)
                return DumpType.FullMemory;

            // Should never get here
            return DumpType.MinimalWithFullCLRHeap;
        }
Example #6
0
 static void ValidateOptions(CommandLineOptions options)
 {
     if (string.IsNullOrEmpty(options.ProcessInfo)) {
         throw new ArgumentException("Either a process id or process name is required");
     }
     // file name and dump folder
     if (options.DumpFolderForNewlyStartedProcess != null &&
         !Directory.Exists(options.DumpFolderForNewlyStartedProcess)) {
         throw new ArgumentException("The specified dump folder does not exist.");
     }
     if (options.NoDumpOptionSelected && !string.IsNullOrEmpty(
         options.DumpFolderForNewlyStartedProcess)) {
         throw new ArgumentException("Option to create an immediate dump when starting a process is not supported.");
     }
 }
Example #7
0
 private static int GetTargetProcessId(CommandLineOptions options)
 {
     if (options.ProcessId != 0)
     {
         // Just to make sure it exists
         var proc = Process.GetProcessById(options.ProcessId);
         return proc.Id;
     }
     else
     {
         var procs = Process.GetProcessesByName(options.ProcessName);
         if (procs.Length == 0)
             throw new ArgumentException("Couldn't find a process with the specified name");
         if (procs.Length > 1)
             throw new ArgumentException("There is more than one process with the specified name");
         return procs[0].Id;
     }
 }
Example #8
0
        private static void ValidateOptions(CommandLineOptions options)
        {
            int set = 0;
            set += options.FullDump ? 1 : 0;
            set += options.MinimalDump ? 1 : 0;
            set += options.MinimalDumpWithCLRHeap ? 1 : 0;
            if (set == 0)
            {
                throw new ArgumentException("No dump option specified");
            }
            if (set > 1)
            {
                throw new ArgumentException("More than one dump option specified");
            }

            if (options.ProcessId == 0 && String.IsNullOrEmpty(options.ProcessName))
                throw new ArgumentException("Either a process id or process name is required");

            if (options.ProcessId != 0 && !String.IsNullOrEmpty(options.ProcessName))
                throw new ArgumentException("Expecting either process id or process name, not both");

            if (File.Exists(options.DumpFileName))
                throw new ArgumentException("The specified file already exists");
        }