Beispiel #1
0
 public void Abort()
 {
     try {
         tokenSource.Cancel();
         AbortImpl(Interlocked.Increment(ref abortCalls) - 1);
     }
     catch (OperationCanceledException) {
         // if CancelImpl throw OCE we shouldn't mute it
         throw;
     }
     catch (Exception e) {
         DebuggerLoggingService.LogMessage("Exception in CancelImpl(): {0}", e.Message);
     }
 }
        protected override void OnSetNextStatement(long threadId, string fileName, int line, int column)
        {
            var source = new Source {
                Name = Path.GetFileName(fileName), Path = fileName
            };
            var request = new GotoTargetsRequest(source, line)
            {
                Column = column
            };
            GotoTargetsResponse response;
            GotoTarget          target = null;

            try {
                response = protocolClient.SendRequestSync(request);
            } catch (Exception ex) {
                DebuggerLoggingService.LogError("[VSCodeDebugger] Requesting target locations failed", ex);
                throw new NotSupportedException(ex.Message);
            }

            foreach (var location in response.Targets)
            {
                if (location.Line <= line && location.EndLine >= line && location.Column <= column && location.EndColumn >= column)
                {
                    // exact match for location
                    target = location;
                    break;
                }

                if (target == null)
                {
                    // closest match so far...
                    target = location;
                }
            }

            if (target == null)
            {
                throw new NotSupportedException();
            }

            try {
                protocolClient.SendRequestSync(new GotoRequest((int)threadId, target.Id));
            } catch (Exception ex) {
                DebuggerLoggingService.LogMessage("[VSCodeDebugger] Setting next statement failed", ex);
                throw new NotSupportedException(ex.Message);
            }

            RaiseStopEvent();
        }
Beispiel #3
0
        void HandleResult(string result)
        {
            DebuggerLoggingService.LogMessage("Result: {0}", result);

            var message = JsonConvert.DeserializeObject <V8Message> (result);

            if (message.type == "event")
            {
                HandleEvent(JsonConvert.DeserializeObject <V8Event> (result));
            }
            else if (message.type == "response")
            {
                HandleReponse(JsonConvert.DeserializeObject <V8Response> (result));
            }
        }
 void DebugAgentProcess_Exited(object sender, EventArgs e)
 {
     if (protocolClient != null)
     {
         try {
             HasExited = true;
             protocolClient.RequestReceived -= OnDebugAdaptorRequestReceived;
             protocolClient.Stop();
         } catch (Exception ex) {
             DebuggerLoggingService.LogError("[VSCodeDebugger] Stop request failed", ex);
         }
         protocolClient = null;
     }
     OnTargetEvent(new TargetEventArgs(TargetEventType.TargetExited));
 }
Beispiel #5
0
        public void AbortAll()
        {
            DebuggerLoggingService.LogMessage("Aborting all the current invocations");
            List <IAsyncOperationBase> copy;

            lock (currentOperations) {
                if (disposed)
                {
                    throw new ObjectDisposedException("Already disposed");
                }
                copy = currentOperations.ToList();
                currentOperations.Clear();
            }

            CancelOperations(copy, true);
        }
Beispiel #6
0
        void ReloadValues()
        {
            var frame = DebuggingService.CurrentFrame;

            if (frame == null)
            {
                return;
            }

            var locals = frame.GetAllLocals();

            DebuggerLoggingService.LogMessage("Begin Local Variables:");
            foreach (var local in locals)
            {
                DebuggerLoggingService.LogMessage("\t{0}", local.Name);
            }
            DebuggerLoggingService.LogMessage("End Local Variables");

            if (UseNewTreeView)
            {
                controller.ClearValues();
                controller.AddValues(locals);

                //var xx = new System.Collections.Generic.List<ObjectValueNode> ();

                //xx.Add (new FakeObjectValueNode ("f1"));
                //xx.Add (new FakeIsImplicitNotSupportedObjectValueNode ());

                //xx.Add (new FakeEvaluatingGroupObjectValueNode (1));
                //xx.Add (new FakeEvaluatingGroupObjectValueNode (0));
                //xx.Add (new FakeEvaluatingGroupObjectValueNode (5));

                //xx.Add (new FakeEvaluatingObjectValueNode ());
                //xx.Add (new FakeEnumerableObjectValueNode (10));
                //xx.Add (new FakeEnumerableObjectValueNode (20));
                //xx.Add (new FakeEnumerableObjectValueNode (23));

                //controller.AddValues (xx);
            }
            else
            {
                tree.ClearValues();
                tree.AddValues(locals);
            }
        }
        protected override void AbortImpl(int abortCallTimes)
        {
            try {
                if (abortCallTimes < 10)
                {
                    DebuggerLoggingService.LogMessage("Calling Abort() for {0} time", abortCallTimes);
                    eval.Abort();
                }
                else
                {
                    if (abortCallTimes == 20)
                    {
                        // if Abort() and RudeAbort() didn't bring any result let's try to resume all the threads to free possible deadlocks in target process
                        // maybe this can help to abort hanging evaluations
                        DebuggerLoggingService.LogMessage("RudeAbort() didn't stop eval after {0} times", abortCallTimes - 1);
                        DebuggerLoggingService.LogMessage("Calling Stop()");
                        context.Session.Process.Stop(0);
                        DebuggerLoggingService.LogMessage("Calling SetAllThreadsDebugState(THREAD_RUN)");
                        context.Session.Process.SetAllThreadsDebugState(CorApi.Portable.CorDebugThreadState.ThreadRun, null);
                        DebuggerLoggingService.LogMessage("Calling Continue()");
                        context.Session.Process.Continue(false);
                    }
                    DebuggerLoggingService.LogMessage("Calling RudeAbort() for {0} time", abortCallTimes);

                    eval.RudeAbort();
                }
            } catch (COMException e) {
                var hResult = e.ToHResult <HResult> ();
                switch (hResult)
                {
                case HResult.CORDBG_E_PROCESS_TERMINATED:
                    DebuggerLoggingService.LogMessage("Process was terminated. Set cancelled for eval");
                    tcs.TrySetCanceled();
                    return;

                case HResult.CORDBG_E_OBJECT_NEUTERED:
                    DebuggerLoggingService.LogMessage("Eval object was neutered. Set cancelled for eval");
                    tcs.TrySetCanceled();
                    return;
                }
                tcs.SetException(e);
                throw;
            }
        }
 void DoProcessEvalFinished(CorApi.Portable.EvalEventArgs evalArgs, bool isException)
 {
     if (!ComObject.EqualsComObject(evalArgs.Eval, eval))
     {
         return;
     }
     context.Session.OnEndEvaluating();
     evalArgs.Continue = false;
     if (Token.IsCancellationRequested)
     {
         DebuggerLoggingService.LogMessage("EvalFinished() but evaluation was cancelled");
         tcs.TrySetCanceled();
     }
     else
     {
         DebuggerLoggingService.LogMessage("EvalFinished(). Setting the result");
         tcs.TrySetResult(new OperationResult <CorApi.Portable.Value> (evalArgs.Eval.Result, isException));
     }
 }
Beispiel #9
0
        void ReloadValues()
        {
            var frame = DebuggingService.CurrentFrame;

            if (frame == null)
            {
                return;
            }

            var locals = frame.GetAllLocals();

            DebuggerLoggingService.LogMessage("Begin Local Variables:");
            foreach (var local in locals)
            {
                DebuggerLoggingService.LogMessage("\t{0}", local.Name);
            }
            DebuggerLoggingService.LogMessage("End Local Variables");

            if (UseNewTreeView)
            {
                _treeview.BeginUpdates();
                try {
                    controller.ClearValues();
                    controller.AddValues(locals);
                } finally {
                    _treeview.EndUpdates();
                }


                if (EnableFakeNodes)
                {
                    AddFakeNodes();
                }
            }
            else
            {
                tree.ClearValues();
                tree.AddValues(locals);
            }
        }
        protected override ThreadInfo [] OnGetThreads(long processId)
        {
            ThreadsResponse response;

            try {
                response = protocolClient.SendRequestSync(new ThreadsRequest());
            } catch (Exception ex) {
                DebuggerLoggingService.LogError("[VSCodeDebugger] Error getting threads", ex);
                return(new ThreadInfo[0]);
            }

            var threads = new ThreadInfo[response.Threads.Count];

            for (int i = 0; i < threads.Length; i++)
            {
                var thread = response.Threads[i];

                threads[i] = new ThreadInfo(processId, thread.Id, thread.Name, null);
            }

            return(threads);
        }
Beispiel #11
0
        void WaitAfterCancel(IAsyncOperationBase op)
        {
            var desc = op.Description;

            DebuggerLoggingService.LogMessage(string.Format("Waiting for cancel of invoke {0}", desc));
            if (!op.RawTask.Wait(ShortCancelTimeout))
            {
                try {
                    ChangeBusyState(true, desc);
                    while (true)
                    {
                        op.Abort();
                        if (op.RawTask.Wait(ShortCancelTimeout))
                        {
                            break;
                        }
                    }
                }
                finally {
                    ChangeBusyState(false, desc);
                }
            }
        }
Beispiel #12
0
        void SendRequest(Request request)
        {
            var requestEvent = new ManualResetEvent(false);

            requestEvents [request.seq] = requestEvent;

            var jsonString = JsonConvert.SerializeObject(request);
            var data       = string.Format("Content-Length: {0}\r\n\r\n{1}", jsonString.Length, jsonString);

            DebuggerLoggingService.LogMessage("Request: {0}", jsonString);

            stdInOutProtocol.WriteStandardInput(data);

            // Wait for response
            requestEvent.WaitOne();

            if (requestException != null)
            {
                var e = requestException;
                requestException = null;
                throw e;
            }
        }
Beispiel #13
0
 void CancelOperations(List <IAsyncOperationBase> operations, bool wait)
 {
     foreach (var operation in operations)
     {
         var taskDescription = operation.Description;
         try {
             operation.Abort();
             if (wait)
             {
                 WaitAfterCancel(operation);
             }
         }
         catch (Exception e) {
             if (IsOperationCancelledException(e))
             {
                 DebuggerLoggingService.LogMessage(string.Format("Invocation of {0} cancelled in CancelOperations()", taskDescription));
             }
             else
             {
                 DebuggerLoggingService.LogError(string.Format("Invocation of {0} thrown an exception in CancelOperations()", taskDescription), e);
             }
         }
     }
 }
        public ObjectValue CreateObjectValue(EvaluationOptions options)
        {
            if (!CanEvaluate(options))
            {
                return(DC.ObjectValue.CreateImplicitNotSupported(this, new ObjectPath(Name), Context.Adapter.GetDisplayTypeName(GetContext(options), Type), Flags));
            }

            Connect();
            try {
                return(OnCreateObjectValue(options));
            } catch (ImplicitEvaluationDisabledException) {
                return(DC.ObjectValue.CreateImplicitNotSupported(this, new ObjectPath(Name), Context.Adapter.GetDisplayTypeName(GetContext(options), Type), Flags));
            } catch (NotSupportedExpressionException ex) {
                return(DC.ObjectValue.CreateNotSupported(this, new ObjectPath(Name), Context.Adapter.GetDisplayTypeName(GetContext(options), Type), ex.Message, Flags));
            } catch (EvaluatorExceptionThrownException ex) {
                return(DC.ObjectValue.CreateEvaluationException(Context, Context.ExpressionValueSource, new ObjectPath(Name), ex));
            } catch (EvaluatorException ex) {
                return(DC.ObjectValue.CreateError(this, new ObjectPath(Name), "", ex.Message, Flags));
            }
            catch (Exception ex) {
                DebuggerLoggingService.LogError("Exception in CreateObjectValue()", ex);
                return(DC.ObjectValue.CreateUnknown(Name));
            }
        }
 public void Error(string message, Exception e)
 {
     DebuggerLoggingService.LogError(message, e);
 }
 public void Info(string message)
 {
     DebuggerLoggingService.LogMessage(message);
 }
Beispiel #17
0
        void ReloadValues(bool frameChanged)
        {
            var frame = DebuggingService.CurrentFrame;

            if (frame == null)
            {
                return;
            }

            ObjectValue[] locals;
            TimeSpan      elapsed;

            using (var timer = frame.DebuggerSession.LocalVariableStats.StartTimer()) {
                try {
                    locals = frame.GetAllLocals();
                    timer.Stop(true);
                } catch {
                    locals = new ObjectValue[0];
                    timer.Stop(false);
                }

                elapsed = timer.Elapsed;
            }

            if (frameChanged)
            {
                var metadata = new Dictionary <string, object> ();
                metadata["LocalsCount"] = locals.Length;
                metadata["Elapsed"]     = elapsed.TotalMilliseconds;

                Counters.LocalsPadFrameChanged.Inc(1, null, metadata);
            }

            DebuggerLoggingService.LogMessage("Begin Local Variables:");
            foreach (var local in locals)
            {
                DebuggerLoggingService.LogMessage("\t{0}", local.Name);
            }
            DebuggerLoggingService.LogMessage("End Local Variables");

            if (UseNewTreeView)
            {
                _treeview.BeginUpdates();
                try {
                    controller.ClearValues();
                    controller.AddValues(locals);
                } finally {
                    _treeview.EndUpdates();
                }

                if (EnableFakeNodes)
                {
                    AddFakeNodes();
                }
            }
            else
            {
                tree.ClearValues();
                tree.AddValues(locals);
            }
        }
Beispiel #18
0
        public OperationResult <TValue> Invoke <TValue> (AsyncOperationBase <TValue> mc, int timeout)
        {
            if (timeout <= 0)
            {
                throw new ArgumentOutOfRangeException("timeout", timeout, "timeout must be greater than 0");
            }

            Task <OperationResult <TValue> > task;
            var description = mc.Description;

            lock (currentOperations) {
                if (disposed)
                {
                    throw new ObjectDisposedException("Already disposed");
                }
                DebuggerLoggingService.LogMessage(string.Format("Starting invoke for {0}", description));
                task = mc.InvokeAsync();
                currentOperations.Add(mc);
            }

            bool cancelledAfterTimeout = false;

            try {
                if (task.Wait(timeout))
                {
                    DebuggerLoggingService.LogMessage(string.Format("Invoke {0} succeeded in {1} ms", description, timeout));
                    return(task.Result);
                }
                DebuggerLoggingService.LogMessage(string.Format("Invoke {0} timed out after {1} ms. Cancelling.", description, timeout));
                mc.Abort();
                try {
                    WaitAfterCancel(mc);
                }
                catch (Exception e) {
                    if (IsOperationCancelledException(e))
                    {
                        DebuggerLoggingService.LogMessage(string.Format("Invoke {0} was cancelled after timeout", description));
                        cancelledAfterTimeout = true;
                    }
                    throw;
                }
                DebuggerLoggingService.LogMessage(string.Format("{0} cancelling timed out", description));
                throw new TimeOutException();
            }
            catch (Exception e) {
                if (IsOperationCancelledException(e))
                {
                    if (cancelledAfterTimeout)
                    {
                        throw new TimeOutException();
                    }
                    DebuggerLoggingService.LogMessage(string.Format("Invoke {0} was cancelled outside before timeout", description));
                    throw new EvaluatorAbortedException();
                }
                throw;
            }
            finally {
                lock (currentOperations) {
                    currentOperations.Remove(mc);
                }
            }
        }
 protected override void OnNextLine()
 {
     protocolClient.SendRequest(new NextRequest(currentThreadId), null, (args, ex) => {
         DebuggerLoggingService.LogError("[VSCodeDebugger] StepOver request failed", ex);
     });
 }