internal override void OnConnected()
        {
            // Finish initialization now that the socket connection has been established
            var          threads      = _process.GetThreads();
            PythonThread activeThread = null;

            var dte = _serviceProvider.GetDTE();

            if (dte != null)
            {
                // If we are broken into the debugger, let's set the debug REPL active thread
                // to be the one that is active in the debugger
                var dteDebugger = dte.Debugger;
                if (dteDebugger.CurrentMode == EnvDTE.dbgDebugMode.dbgBreakMode &&
                    dteDebugger.CurrentProcess != null &&
                    dteDebugger.CurrentThread != null)
                {
                    if (_process.Id == dteDebugger.CurrentProcess.ProcessID)
                    {
                        var activeThreadId = _threadIdMapper.GetPythonThreadId((uint)dteDebugger.CurrentThread.ID);
                        activeThread = threads.SingleOrDefault(t => t.Id == activeThreadId);
                    }
                }
            }

            if (activeThread == null)
            {
                activeThread = threads.Count > 0 ? threads[0] : null;
            }

            if (activeThread != null)
            {
                SwitchThread(activeThread, false);
            }
        }
Beispiel #2
0
 public PythonDebugProcessReplEvaluator(IServiceProvider serviceProvider, PythonProcess process, IThreadIdMapper threadIdMapper)
     : base(serviceProvider)
 {
     _process          = process;
     _threadIdMapper   = threadIdMapper;
     _threadId         = process.GetThreads()[0].Id;
     _languageVersion  = process.LanguageVersion;
     _currentScopeName = CurrentFrameScopeFixedName;
     DisplayName       = Strings.DebugReplDisplayName;
 }
        public PythonDebugProcessReplEvaluator(IServiceProvider serviceProvider, PythonProcess process, PythonToolsService pyService, IThreadIdMapper threadIdMapper)
            : base(serviceProvider, pyService, GetOptions(serviceProvider, pyService))
        {
            _process         = process;
            _threadIdMapper  = threadIdMapper;
            _threadId        = process.GetThreads()[0].Id;
            _languageVersion = process.LanguageVersion;

            EnsureConnected();
        }
        public PythonDebugProcessReplEvaluator(IServiceProvider serviceProvider, PythonProcess process, IThreadIdMapper threadIdMapper)
            : base(serviceProvider)
        {
            _process         = process;
            _threadIdMapper  = threadIdMapper;
            _threadId        = process.GetThreads()[0].Id;
            _languageVersion = process.LanguageVersion;
            DisplayName      = "Debug";

            EnsureConnectedOnCreate();
        }
Beispiel #5
0
        public override async Task <ExecutionResult> InitializeAsync()
        {
            var result = await base.InitializeAsync();

            if (!result.IsSuccessful)
            {
                return(result);
            }

            result = await _serviceProvider.GetUIThread().InvokeTask(async() => {
                try {
                    UpdatePropertiesFromProjectMoniker();
                } catch (NoInterpretersException ex) {
                    WriteError(ex.ToString());
                } catch (MissingInterpreterException ex) {
                    WriteError(ex.ToString());
                } catch (DirectoryNotFoundException ex) {
                    WriteError(ex.ToString());
                } catch (Exception ex) when(!ex.IsCriticalException())
                {
                    WriteError(ex.ToUnhandledExceptionMessage(GetType()));
                }

                var remoteProcess = _process as PythonRemoteProcess;

                try {
                    _serviceProvider.GetPythonToolsService().Logger.LogEvent(Logging.PythonLogEvent.DebugRepl, new Logging.DebugReplInfo {
                        RemoteProcess = remoteProcess != null,
                        Version       = _process.LanguageVersion.ToVersion().ToString()
                    });
                } catch (Exception ex) {
                    Debug.Fail(ex.ToUnhandledExceptionMessage(GetType()));
                }

                _process.ModulesChanged += OnModulesChanged;

                var threads = _process.GetThreads();
                PythonThread activeThread = null;

                var dte = _serviceProvider.GetDTE();
                if (dte != null)
                {
                    // If we are broken into the debugger, let's set the debug REPL active thread
                    // to be the one that is active in the debugger
                    var dteDebugger = dte.Debugger;
                    if (dteDebugger.CurrentMode == EnvDTE.dbgDebugMode.dbgBreakMode &&
                        dteDebugger.CurrentProcess != null &&
                        dteDebugger.CurrentThread != null)
                    {
                        if (_process.Id == dteDebugger.CurrentProcess.ProcessID)
                        {
                            var activeThreadId = _threadIdMapper.GetPythonThreadId((uint)dteDebugger.CurrentThread.ID);
                            activeThread       = threads.SingleOrDefault(t => t.Id == activeThreadId);
                        }
                    }
                }

                if (activeThread == null)
                {
                    activeThread = threads.Count > 0 ? threads[0] : null;
                }

                if (activeThread != null)
                {
                    SwitchThread(activeThread, false);
                }

                return(ExecutionResult.Success);
            });

            return(result);
        }