public DebuggedProcess(IPEndPoint endPoint, IEngineCallback engineCallback, IWorkerThread workerThread, AD7Engine engine) { _engineCallback = engineCallback; WorkerThread = workerThread; Engine = engine; ProcessState = ProcessState.NotConnected; _rokuController = new RokuController(endPoint); _rokuController.OnOutput += RokuControllerOnOutput; _rokuController.OnBackTrace += RokuControllerOnOnBackTrace; _rokuController.OnVariables += RokuControllerOnOnVariables; _rokuController.RunModeEvent += RokuControllerOnRunModeEvent; _rokuController.BreakModeEvent += RokuControllerOnBreakModeEvent; _rokuController.ProcessExitEvent += RokuControllerOnProcessExitEvent; CommandFactory = new CommandFactory(_rokuController); ThreadCache = new ThreadCache(engineCallback, Engine, CommandFactory); // we do NOT have real Win32 process IDs, so we use a guid AD_PROCESS_ID pid = new AD_PROCESS_ID(); pid.ProcessIdType = (int)enum_AD_PROCESS_ID.AD_PROCESS_ID_GUID; pid.guidProcessId = Guid.NewGuid(); this.Id = pid; }
// 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(_pollThread == null); Debug.Assert(_engineCallback == null); Debug.Assert(_debuggedProcess == null); Debug.Assert(_ad7ProgramId == Guid.Empty); process = null; _engineCallback = new EngineCallback(this, ad7Callback); try { // We are being asked to debug a process when we currently aren't debugging anything _pollThread = new WorkerThread(); _pollThread.RunOperation(() => { var endpoint = new IPEndPoint(IPAddress.Parse(args.Split('=')[1]), 8085); _debuggedProcess = new DebuggedProcess(endpoint, _engineCallback, _pollThread, this); _pollThread.PostedOperationErrorEvent += _debuggedProcess.OnPostedOperationError; return(_debuggedProcess.Initialize()); }); EngineUtils.RequireOk(port.GetProcess(_debuggedProcess.Id, out process)); return(VSConstants.S_OK); } catch (Exception e) when(ExceptionHelper.BeforeCatch(e, reportOnlyCorrupting: true)) { // If we just return the exception as an HRESULT, we will loose our message, so we instead send up an error event, and then // return E_ABORT. SendStartDebuggingError(e); } Dispose(); return(VSConstants.E_ABORT); }
public MainViewModel() { _closeCommand = new RelayCommand(_ => { _channelMessageProducer.Dispose(); }); Channels = new ObservableCollection <ChannelViewModel>(); _channelMessageProducer = new ChannelMessageWorkerThread(); _channelMessageProducer.Start(this); }
public async Task Run(IKernel ninject) { var window = ninject.Get <WindowState>(); var graphics = ninject.Get <GraphicsState>(); if (!graphics.Device.Features.ShaderFloat64) { Log.Fatal("gpu doesn't support shaderFloat64"); return; } var workers = new IWorkerThread[] { ninject.Get <LogicThread>(), ninject.Get <ViewThread>() }; var workerTasks = workers.Select(x => Task.Run(x.Run)).ToArray(); var(lastW, lastH) = (1280, 720); while (!window.ShouldQuit) { if (SDL_PollEvent(out var e) == 1) { switch (e.type) { case SDL_EventType.SDL_QUIT: window.ShouldQuit = true; continue; } } if (graphics.FrameReady) { SDL_GetWindowSize(window.Handle, out var w, out var h); if (w != lastW || h != lastH) { graphics.Device.ResizeMainWindow((uint)w, (uint)h); lastW = w; lastH = h; Log.Debug("window resized"); } graphics.Device.SwapBuffers(); graphics.FrameReady = false; } } await Task.WhenAll(workerTasks); // todo dispose ninject Log.Info("Window quit"); }
void InitAndRunFreeThreads(IWorkerThread Thread) { if (Thread.GetState() == WorkerThreadState.Free) { TaskFinished.BeginInvoke(Thread.GetCurrentTask(), null, null); InitThread(Thread); } else { Logger.UltraLogger.Instance.AddToLog("Worker: Thread is not free. Cant init thread after end of previous task.", Logger.MsgType.Error); throw new NotImplementedException(); } }
// Attach the debug engine to a program. int IDebugEngine2.Attach(IDebugProgram2[] rgpPrograms, IDebugProgramNode2[] rgpProgramNodes, uint celtPrograms, IDebugEventCallback2 ad7Callback, enum_ATTACH_REASON dwReason) { Debug.Assert(_ad7ProgramId == Guid.Empty); if (celtPrograms != 1) { Debug.Fail("SampleEngine only expects to see one program in a process"); throw new ArgumentException(); } try { AD_PROCESS_ID processId = EngineUtils.GetProcessId(rgpPrograms[0]); 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 (_pollThread == null) { // We are being asked to debug a process when we currently aren't debugging anything _pollThread = new WorkerThread(); _engineCallback = new EngineCallback(this, ad7Callback); _pollThread.PostedOperationErrorEvent += _debuggedProcess.OnPostedOperationError; } else { if (!EngineUtils.ProcIdEquals(processId, _debuggedProcess.Id)) { Debug.Fail("Asked to attach to a process while we are debugging"); return(VSConstants.E_FAIL); } } AD7EngineCreateEvent.Send(this); AD7ProgramCreateEvent.Send(this); this.ProgramCreateEventSent = true; return(VSConstants.S_OK); } catch (MIException e) { return(e.HResult); } catch (Exception e) when(ExceptionHelper.BeforeCatch(e, reportOnlyCorrupting: true)) { return(EngineUtils.UnexpectedException(e)); } }
public MainViewModel() { _closeCommand = new RelayCommand(_ => { _channelMessageProducer.Dispose(); }); _syncChannels = new object(); Channels = new ObservableCollection <ChannelViewModel>(); BindingOperations.EnableCollectionSynchronization(Channels, _syncChannels); _channelMessageProducer = new ChannelMessageWorkerThread(); _channelMessageProducer.Start(this); }
private void Dispose() { IWorkerThread pollThread = _pollThread; IDebuggedProcess debuggedProcess = _debuggedProcess; _engineCallback?.Close(); _engineCallback = null; _debuggedProcess = null; _pollThread = null; _ad7ProgramId = Guid.Empty; debuggedProcess?.Close(); pollThread?.Close(); }
public bool InitThread(IWorkerThread Thread) { bool OK = true; Task Task; if (TaskQueue.Count == 0) { AddTasks(Params.MaxThreads); } if (TaskQueue.TryDequeue(out Task)) { Thread.Init(new WorkerThreadParams(Task)); Thread.Start(); } else { if (TaskQueue.Count > 0) { Logger.UltraLogger.Instance.AddToLog("Worker: Coudn't dequeue Task.", Logger.MsgType.Error); OK = false; } } return(OK); }
public BackgroundThread(DisposableCommand command_to_execute, IWorkerThread worker_thread) { this.worker_thread = worker_thread; worker_thread.DoWork += (sender, e) => command_to_execute.run(); worker_thread.Disposed += (sender, e) => command_to_execute.Dispose(); }