Esempio n. 1
0
 public CorProcess DebugActiveProcess(int processId, bool win32Attach, CorRemoteTarget target)
 {
     ICorDebugProcess proc = null;
     if (target == null)
     {
         m_debugger.DebugActiveProcess((uint)processId, win32Attach ? 1 : 0, out proc);
     }
     else
     {
         m_remoteDebugger.DebugActiveProcessEx(target, (uint)processId, win32Attach ? 1 : 0, out proc);
     }
     return CorProcess.GetCorProcess(proc);
 }
Esempio n. 2
0
        public CorProcess CreateProcess(CorRemoteTarget target,
                                         String applicationName,
                                         String commandLine,
                                         SECURITY_ATTRIBUTES processAttributes,
                                         SECURITY_ATTRIBUTES threadAttributes,
                                         bool inheritHandles,
                                         int creationFlags,
                                         IntPtr environment,
                                         String currentDirectory,
                                         STARTUPINFO startupInfo,
                                         ref PROCESS_INFORMATION processInformation,
                                         CorDebugCreateProcessFlags debuggingFlags)
        {
            /*
             * If commandLine is: <c:\a b\a arg1 arg2> and c:\a.exe does not exist, 
             *    then without this logic, "c:\a b\a.exe" would be tried next.
             * To prevent this ambiguity, this forces the user to quote if the path 
             *    has spaces in it: <"c:\a b\a" arg1 arg2>
             */
            if (null == applicationName && !commandLine.StartsWith("\""))
            {
                int firstSpace = commandLine.IndexOf(" ");
                if (firstSpace != -1)
                    commandLine = String.Format(CultureInfo.InvariantCulture, "\"{0}\" {1}", commandLine.Substring(0, firstSpace), commandLine.Substring(firstSpace, commandLine.Length - firstSpace));
            }

            ICorDebugProcess proc = null;

            if (target == null)
            {
                m_debugger.CreateProcess(
                                      applicationName,
                                      commandLine,
                                      processAttributes,
                                      threadAttributes,
                                      inheritHandles ? 1 : 0,
                                      (uint)creationFlags,
                                      environment,
                                      currentDirectory,
                                      startupInfo,
                                      processInformation,
                                      debuggingFlags,
                                      out proc);
            }
            else
            {
                m_remoteDebugger.CreateProcessEx(target,
                                                 applicationName,
                                                 commandLine,
                                                 processAttributes,
                                                 threadAttributes,
                                                 inheritHandles ? 1 : 0,
                                                 (uint)creationFlags,
                                                 environment,
                                                 currentDirectory,
                                                 startupInfo,
                                                 processInformation,
                                                 debuggingFlags,
                                                 out proc);

            }

            return CorProcess.GetCorProcess(proc);
        }
Esempio n. 3
0
        public void Attach(int processId, SafeWin32Handle attachContinuationEvent, CorRemoteTarget target)
        {
            Debug.Assert(!IsAlive);
            if (IsAlive)
                throw new InvalidOperationException("cannot call Attach on active process");

            m_stopGo = new V2StopGoController(this);

            m_processAttaching = true;
            try
            {
                m_corProcess = m_corDebugger.DebugActiveProcess(processId,/*win32Attach*/ false, target);
                NativeProcessCreated();
            }
            catch
            {
                // if an attach fails, we need to remove the process object from active processes.
                CleanAfterProcessExit();
                throw;
            }

            // User's breakpoint should start with number 0. When launching, 1st breakpoint created is
            // special -- user entry point and it's given number 0.
            // In case of attach we don't create any such breakpoint but we still want
            // to start numbering breakpoints with 1; therefore we'll increase free breakpoint number.
            if (Breakpoints.m_freeBreakpointNumber == 0)
            {
                Breakpoints.m_freeBreakpointNumber = 1;
            }

            InitDebuggerCallbacks();

            // resume the debuggee
            // for pure managed debugging this is legal as long as DebugActiveProcess has returned
            if (attachContinuationEvent != null)
            {
                Microsoft.Samples.Debugging.Native.NativeMethods.SetEvent(attachContinuationEvent);
                attachContinuationEvent.Close();
            }
        }
Esempio n. 4
0
        public CorProcess CreateProcess(String applicationName,
                                        String commandLine,
                                        String currentDirectory,
                                        int flags,
                                        CorRemoteTarget target)
        {
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();

            STARTUPINFO si = new STARTUPINFO();
            si.cb = Marshal.SizeOf(si);

            // initialize safe handles 
            si.hStdInput = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);
            si.hStdOutput = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);
            si.hStdError = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);

            CorProcess ret;

            //constrained execution region (Cer)
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                ret = CreateProcess(target,
                                     applicationName,
                                     commandLine,
                                     null,
                                     null,
                                     true,   // inherit handles
                                     flags,  // creation flags
                                     new IntPtr(0),      // environment
                                     currentDirectory,
                                     si,     // startup info
                                     ref pi, // process information
                                     CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS);
                NativeMethods.CloseHandle(pi.hProcess);
                NativeMethods.CloseHandle(pi.hThread);
            }

            return ret;
        }
Esempio n. 5
0
        public void CreateProcess(string commandLine, string commandArguments, string workingDirectory, CorRemoteTarget target)
        {
            Debug.Assert(!IsAlive);
            if (IsAlive)
                throw new InvalidOperationException("cannot call CreateProcess on active process");

            m_stopGo = new V2StopGoController(this);

            int flags = (int)(m_engine.Options.CreateProcessWithNewConsole ? CreateProcessFlags.CREATE_NEW_CONSOLE : 0);

            try
            {
                m_corProcess = m_corDebugger.CreateProcess(commandLine, commandArguments, workingDirectory, flags, target);
                NativeProcessCreated();

            }
            catch
            {
                CleanAfterProcessExit();                    // remove process from process list in case of failure
                throw;
            }

            InitDebuggerCallbacks();

            if (commandLine != null)
                m_name = commandLine;
            else
                m_name = commandArguments;
        }