public DebuggedProcess(string exe, string args, WorkerThread pollThread, EngineCallback callback)
        {
            MyLogger.Trace("> DebuggedProcess");

            Callback = callback;
            m_pollThread = pollThread;
            tempScriptCache = new TempScriptCache();
            main = exe;
            dbgWorkDir = Path.GetDirectoryName(exe);
            ParseConfig(args);

            proc = new Process();
            if (!dbgConnectOnly) {
                if (nodeExe == null || !File.Exists(nodeExe)) {
                    System.Windows.Forms.MessageBox.Show("ERROR: node.exe not found.\r\n\r\n" +
                        "Please make sure it is on your %PATH% or installed in default location.\r\n\r\n" +
                        "You can download a copy of Node at http://nodejs.org/", "NodeVsDebugger");
                    throw new ArgumentException("node.exe not found");
                }

                proc.StartInfo = new ProcessStartInfo {
                    Arguments = string.Format("--debug-brk={0} \"{1}\"", dbgPort, main),
                    FileName = nodeExe,
                    UseShellExecute = false,
                    WorkingDirectory = dbgWorkDir,
                };
            } else {
                // using fake process and connecting to another machine
                proc.StartInfo = new ProcessStartInfo {
                    FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"cmd.exe"),
                    UseShellExecute = false,
                    CreateNoWindow = true,
                };
            }
            try {
                proc.Start();
                Id = proc.Id;
            } catch (Exception ex) {
                System.Windows.Forms.MessageBox.Show("ERROR: starting process\r\n" + ex, "NodeVsDebugger");
                throw;
            }
            MyLogger.Trace("< DebuggedProcess");
        }
Esempio n. 2
0
        // Launches a process by means of the debug engine.
        // Normally, Visual Studio launches a program using the IDebugPortEx2::LaunchSuspended method and then attaches the debugger
        // to the suspended program. However, there are circumstances in which the debug engine may need to launch a program
        // (for example, if the debug engine is part of an interpreter and the program being debugged is an interpreted language),
        // in which case Visual Studio uses the IDebugEngineLaunch2::LaunchSuspended method
        // The IDebugEngineLaunch2::ResumeProcess method is called to start the process after the process has been successfully launched in a suspended state.
        int IDebugEngineLaunch2.LaunchSuspended(string pszServer, IDebugPort2 port, string exe, string args, string dir, string env, string options, enum_LAUNCH_FLAGS launchFlags, uint hStdInput, uint hStdOutput, uint hStdError, IDebugEventCallback2 ad7Callback, out IDebugProcess2 process)
        {
            //Debug.Assert(Worker.MainThreadId == Worker.CurrentThreadId);
            Debug.Assert(m_pollThread == null);
            Debug.Assert(m_engineCallback == null);
            Debug.Assert(m_debuggedProcess == null);
            Debug.Assert(m_ad7ProgramId == Guid.Empty);

            process = null;

            try {
                // We are being asked to debug a process when we currently aren't debugging anything
                m_pollThread = new WorkerThread();

                m_engineCallback = new EngineCallback(this, ad7Callback);

                // Complete the win32 attach on the poll thread
                m_pollThread.RunOperation(() => m_debuggedProcess = new DebuggedProcess(exe, args, m_pollThread, Callback));

                var adProcessId = new AD_PROCESS_ID {
                    ProcessIdType = (uint)enum_AD_PROCESS_ID.AD_PROCESS_ID_SYSTEM,
                    dwProcessId = (uint)m_debuggedProcess.Id
                };

                EngineUtils.RequireOk(port.GetProcess(adProcessId, out process));

                return Constants.S_OK;
            } catch (Exception e) {
                return EngineUtils.UnexpectedException(e);
            }
        }
Esempio n. 3
0
        // Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM,
        // was received and processed. The only event the sample engine sends in this fashion is Program Destroy.
        // It responds to that event by shutting down the engine.
        int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 eventObject)
        {
            //Debug.Assert(Worker.MainThreadId == Worker.CurrentThreadId);
            try {
                if (eventObject is AD7ProgramDestroyEvent) {
                    var pollThread = m_pollThread;
                    var debuggedProcess = m_debuggedProcess;

                    m_engineCallback = null;
                    m_debuggedProcess = null;
                    m_pollThread = null;
                    m_ad7ProgramId = Guid.Empty;

                    debuggedProcess.Terminate();
                    pollThread.Close();
                } else {
                    Debug.Fail("Unknown syncronious event");
                }
            } catch (Exception e) {
                return EngineUtils.UnexpectedException(e);
            }

            return Constants.S_OK;
        }