Exemplo n.º 1
0
        // Attach the debug engine to a program.
        int IDebugEngine2.Attach(IDebugProgram2[] rgpPrograms, IDebugProgramNode2[] rgpProgramNodes, uint celtPrograms, IDebugEventCallback2 ad7Callback, enum_ATTACH_REASON dwReason)
        {
            Debug.WriteLine("PythonEngine Attach Begin " + GetHashCode());

            AssertMainThread();
            Debug.Assert(_ad7ProgramId == Guid.Empty);

            if (celtPrograms != 1)
            {
                Debug.Fail("Python debugging only supports one program in a process");
                throw new ArgumentException();
            }

            int processId = EngineUtils.GetProcessId(rgpPrograms[0]);

            if (processId == 0)
            {
                // engine only supports system processes
                Debug.WriteLine("PythonEngine failed to get process id during attach");
                return(VSConstants.E_NOTIMPL);
            }

            EngineUtils.RequireOk(rgpPrograms[0].GetProgramId(out _ad7ProgramId));

            // Attach can either be called to attach to a new process, or to complete an attach
            // to a launched process
            if (_process == null)
            {
                // TODO: Where do we get the language version from?
                _events = ad7Callback;

                var attachRes = PythonProcess.TryAttach(processId, out _process);
                if (attachRes != ConnErrorMessages.None)
                {
                    string msg;
                    switch (attachRes)
                    {
                    case ConnErrorMessages.CannotInjectThread: msg = "Cannot create thread in debuggee process"; break;

                    case ConnErrorMessages.CannotOpenProcess: msg = "Cannot open process for debugging"; break;

                    case ConnErrorMessages.InterpreterNotInitialized: msg = "Python interpreter has not been initialized in this process"; break;

                    case ConnErrorMessages.LoadDebuggerBadDebugger: msg = "Failed to load debugging script (incorrect version of script?)"; break;

                    case ConnErrorMessages.LoadDebuggerFailed: msg = "Failed to compile debugging script"; break;

                    case ConnErrorMessages.OutOfMemory: msg = "Out of memory"; break;

                    case ConnErrorMessages.PythonNotFound: msg = "Python interpreter not found"; break;

                    case ConnErrorMessages.TimeOut: msg = "Timeout while attaching"; break;

                    case ConnErrorMessages.UnknownVersion: msg = "Unknown Python version loaded in process"; break;

                    case ConnErrorMessages.SysNotFound: msg = "sys module not found"; break;

                    case ConnErrorMessages.SysSetTraceNotFound: msg = "settrace not found in sys module"; break;

                    case ConnErrorMessages.PyDebugAttachNotFound: msg = "Cannot find PyDebugAttach.dll at " + attachRes; break;

                    default: msg = "Unknown error"; break;
                    }

                    MessageBox.Show("Failed to attach debugger: " + msg);
                    return(VSConstants.E_FAIL);
                }

                AttachEvents(_process);
                _attached = true;
            }
            else
            {
                if (processId != _process.Id)
                {
                    Debug.Fail("Asked to attach to a process while we are debugging");
                    return(VSConstants.E_FAIL);
                }
                _attached = false;
            }

            AD7EngineCreateEvent.Send(this);

            lock (_syncLock) {
                _programCreated = true;
                AD7ProgramCreateEvent.Send(this);

                if (_processLoadedThread != null)
                {
                    SendLoadComplete(_processLoadedThread);
                }
            }

            Debug.WriteLine("PythonEngine Attach returning S_OK");
            return(VSConstants.S_OK);
        }
Exemplo n.º 2
0
        public static void Send(AD7Engine engine)
        {
            AD7EngineCreateEvent eventObject = new AD7EngineCreateEvent(engine);

            engine.Send(eventObject, IID, null, null);
        }
Exemplo n.º 3
0
 public static void Send(AD7Engine engine) {
     AD7EngineCreateEvent eventObject = new AD7EngineCreateEvent(engine);
     engine.Send(eventObject, IID, null, null);
 }