Exemplo n.º 1
0
        protected static void WaitForMode(EnvDTE.Debugger debugger, EnvDTE.dbgDebugMode mode) {
            for (int i = 0; i < 30 && debugger.CurrentMode != mode; i++) {
                Thread.Sleep(1000);
            }

            Assert.AreEqual(mode, debugger.CurrentMode);
        }
        public MarkerRenderer(
            ITextView textView,
            ITagAggregator <IVsVisibleTextMarkerTag> markerTagAggregator,
            ITagAggregator <IErrorTag> errorTagAggregator,
            EnvDTE.Debugger debugger,
            SimpleScrollBar scrollBar)
        {
            _textView            = textView;
            _markerTagAggregator = markerTagAggregator;
            _errorTagAggregator  = errorTagAggregator;
            _debugger            = debugger;
            _scrollBar           = scrollBar;

            // ... Pretty convoluted way to get the filename:
            ITextDocument doc;
            bool          success = textView.TextBuffer.Properties.TryGetProperty <ITextDocument>(typeof(ITextDocument), out doc);

            if (success)
            {
                _filename = doc.FilePath;
            }
            else
            {
                _filename = "";
            }
        }
Exemplo n.º 3
0
        internal static DebuggerVariable FindUnderMousePointer(EnvDTE.Debugger debugger, MouseHoverEventArgs e)
        {
            Debug.Assert(debugger != null);

            var point = e.TextPosition.GetPoint(e.TextPosition.AnchorBuffer, PositionAffinity.Predecessor);

            if (!point.HasValue)
            {
                return(null);
            }

            SnapshotSpan span;
            var          name = GetVariableNameAndSpan(point.Value, out span);

            if (name == null)
            {
                return(null);
            }

            var expression = debugger.GetExpression(name);

            if (!expression.IsValidValue)
            {
                return(null);
            }

            return(new DebuggerVariable(debugger, point.Value, span, name, expression));
        }
Exemplo n.º 4
0
		public MarkerRenderer(
			ITextView textView,
			ITagAggregator<IVsVisibleTextMarkerTag> markerTagAggregator,
			ITagAggregator<IErrorTag> errorTagAggregator,
			EnvDTE.Debugger debugger,
			SimpleScrollBar scrollBar)
		{
			_textView = textView;
			_markerTagAggregator = markerTagAggregator;
			_errorTagAggregator = errorTagAggregator;
			_debugger = debugger;
			_scrollBar = scrollBar;

			// ... Pretty convoluted way to get the filename:
			ITextDocument doc;
			bool success = textView.TextBuffer.Properties.TryGetProperty<ITextDocument>(typeof(ITextDocument), out doc);
			if (success)
			{
				_filename = doc.FilePath;
			}
			else
			{
				_filename = "";
			}
		}
Exemplo n.º 5
0
 private DebuggerVariable(EnvDTE.Debugger debugger, SnapshotPoint point, SnapshotSpan span, string name, EnvDTE.Expression expression)
 {
     this.debugger   = debugger;
     this.Point      = point;
     this.Span       = span;
     this.Name       = name;
     this.Type       = expression.Type;
     this.Value      = expression.Value;
     this.Expression = expression;
 }
Exemplo n.º 6
0
        List <Replicate> IMembersProvider.GetMembers(EnvDTE.Debugger debugger, string variableName)
        {
            var members = new List <Replicate>();

            var itemsCount = Int32.Parse(_debugger.GetExpression(String.Concat(variableName, ".Count")).Value);

            for (int i = 0; i < itemsCount; i++)
            {
                members.Add(CreateReplicate(String.Concat(variableName, "(", i.ToString(), ")")));
            }

            return(members);
        }
        public DebuggerScriptResultList Filter(string filter, EnvDTE.Debugger debugger)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            DebuggerScriptResultList newResults = new DebuggerScriptResultList();

            foreach (var result in Results)
            {
                var expr = debugger.GetExpression(string.Format(filter, "(" + result.Expression + ")"), false);
                if (expr != null && expr.Value == "true")
                {
                    newResults.Add(result.Name, result.Expression, result.Index);
                }
            }
            return(newResults);
        }
Exemplo n.º 8
0
        internal static async System.Threading.Tasks.Task RefreshVariableViews(this IServiceProvider serviceProvider)
        {
            EnvDTE.Debugger debugger = serviceProvider.GetDTE().Debugger;
            AD7Engine       engine   = AD7Engine.GetEngineForProcess(debugger.CurrentProcess);

            if (engine != null)
            {
                await engine.RefreshThreadFrames(debugger.CurrentThread.ID);

                var vsDebugger = (IDebugRefreshNotification140)serviceProvider.GetShellDebugger();
                if (vsDebugger != null)
                {
                    // Passing fCallstackFormattingAffected = TRUE to OnExpressionEvaluationRefreshRequested to force refresh
                    vsDebugger.OnExpressionEvaluationRefreshRequested(1);
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Apply changes through debugger.ExecuteStatement
        /// </summary>
        /// <param name="debugger"></param>
        public void ApplyChanges(EnvDTE.Debugger debugger)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            string[] queries = this.Compare(lastSyncObject);

            if (queries == null || queries.Length == 0)
            {
                return;
            }

            foreach (var query in queries)
            {
                debugger.ExecuteStatement(query);
            }

            lastSyncObject = this.Clone();
        }
Exemplo n.º 10
0
        public void OnDebuggerAttached(EnvDTE.dbgEventReason Reason, ref EnvDTE.dbgExecutionAction ExecutionAction)
        {
            if (Reason == EnvDTE.dbgEventReason.dbgEventReasonBreakpoint)
            {
                try
                {
                    EnvDTE.Debugger debugger = Utils.GetDTE().Debugger;

                    if (debugger.CurrentMode == EnvDTE.dbgDebugMode.dbgBreakMode)
                    {
                        if (debugger.CurrentProgram != null && debugger.CurrentProgram.Process != null && debugger.CurrentProgram.Process.Name.EndsWith("csws.exe", StringComparison.OrdinalIgnoreCase))
                        {
                            int processId = debugger.CurrentProgram.Process.ProcessID;
                            if (processId != lastDebgProcessId)
                            {
                                lastDebgProcessId = processId;

                                bool isJustMyCodeEnabled = ((int)Registry.CurrentUser.GetValue(@"Software\Microsoft\VisualStudio\11.0\Debugger\JustMyCode", 0) == 1);

                                if (isJustMyCodeEnabled)
                                {
                                    ExecutionAction = EnvDTE.dbgExecutionAction.dbgExecutionActionStepInto;
                                }
                                else
                                {
                                    string scriptFile = ReadDebuggingMetadata(processId);
                                    if (scriptFile != null)
                                    {
                                        Utils.GetDTE().ItemOperations.OpenFile(scriptFile);
                                        ExecutionAction = EnvDTE.dbgExecutionAction.dbgExecutionActionStepInto;
                                    }
                                    else
                                    {
                                        MessageBox.Show("Debugger cannot step into the script code automatically.\nPlease either enable 'Just My Code' Debugger option or load the script file (and set the breakpoint) manually.", "CS-Script");
                                    }
                                }
                            }
                        }
                    }
                }
                catch { }
            }
        }
Exemplo n.º 11
0
        internal static async Task RefreshVariableViewsAsync(this IServiceProvider serviceProvider, CancellationToken ct = default(CancellationToken))
        {
            serviceProvider.GetUIThread().MustBeCalledFromUIThread();
            EnvDTE.Debugger debugger = serviceProvider.GetDTE()?.Debugger;
            if (debugger == null)
            {
                return;
            }
            AD7Engine engine = AD7Engine.GetEngineForProcess(debugger.CurrentProcess);

            if (engine != null)
            {
                await engine.RefreshThreadFrames(debugger.CurrentThread.ID, ct);

                var vsDebugger = serviceProvider.GetShellDebugger() as IDebugRefreshNotification140;
                if (vsDebugger != null)
                {
                    // Passing fCallstackFormattingAffected = TRUE to OnExpressionEvaluationRefreshRequested to force refresh
                    vsDebugger.OnExpressionEvaluationRefreshRequested(1);
                }
            }
        }
Exemplo n.º 12
0
        public void Evaluate(EnvDTE.Debugger debugger)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            Value = "<Unknown value>";

            if (IsLiteral)
            {
                Value = Expression;
                return;
            }

            try
            {
                if (debugger != null)
                {
                    EnvDTE.Expression expr = debugger.GetExpression(Expression, true);
                    if (expr != null)
                    {
                        Value = expr.Value;
                        Type  = expr.Type;
                    }

                    if (UseAddressForName)
                    {
                        EnvDTE.Expression nameExpr = debugger.GetExpression("&" + Expression, false);
                        if (nameExpr != null)
                        {
                            Name = nameExpr.Value;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Value = "Exception thrown: " + e.Message;
            }
        }
Exemplo n.º 13
0
        private static async Task PollBreakpointsAsync(EnvDTE.Debugger debuggerDte, CancellationToken cancellationToken)
        {
            await VSPackage.TaskFactory.SwitchToMainThreadAsync();

            var activeBreakpoints = new Dictionary <string, EnvDTE.Breakpoint>();

            while (!cancellationToken.IsCancellationRequested)
            {
                if (debuggerDte.Breakpoints != null)
                {
                    foreach (EnvDTE.Breakpoint newBp in debuggerDte.Breakpoints)
                    {
                        if (!newBp.Enabled)
                        {
                            continue;
                        }
                        // If the breakpoint is enabled and does not match the previously active one, disable the latter
                        if (activeBreakpoints.TryGetValue(newBp.File, out var oldBp))
                        {
                            if (newBp != oldBp)
                            {
                                try { oldBp.Enabled = false; }
                                catch (COMException) { } // the old breakpoint is deleted

                                activeBreakpoints[newBp.File] = newBp;
                            }
                        }
                        else
                        {
                            activeBreakpoints[newBp.File] = newBp;
                        }
                    }
                }
                await Task.Delay(_pollDelay);
            }
        }
Exemplo n.º 14
0
 /// <summary>
 /// Forces debugger to refresh its variable views (Locals, Autos etc) by re-querying the debug engine.
 /// </summary>
 /// <param name="debugger"></param>
 public static void RefreshVariableViews(this EnvDTE.Debugger debugger)
 {
     // There's no proper way to do this, so just "change" a property that would invalidate the view.
     debugger.HexDisplayMode = debugger.HexDisplayMode;
 }
Exemplo n.º 15
0
 private Debugger_InProc()
 {
     _debugger = GetDTE().Debugger;
 }
Exemplo n.º 16
0
        /// <summary>
        /// Attach to the debugger.
        /// </summary>
        public static void AttemptDebugAttach()
        {
            bool requiresAttach = !Debugger.IsAttached;

            // If I don't have a debugger attached, try to attach
            if (requiresAttach)
            {
                Stopwatch timer = Stopwatch.StartNew();
                //log.Debug("Attaching debugger.");
                int        tries = 4;
                EnvDTE.DTE dte   = null;
                while (tries-- > 0)
                {
                    try
                    {
                        dte = VisualStudioHelper.GetRunningInstance().FirstOrDefault();
                        if (dte == null)
                        {
                            //log.Debug("Could not attach Visual Studio debugger. No instances found or missing user privileges.");
                            return;
                        }
                        EnvDTE.Debugger debugger = dte.Debugger;
                        foreach (EnvDTE.Process program in debugger.LocalProcesses)
                        {
                            if (program.ProcessID == Process.GetCurrentProcess().Id)
                            {
                                program.Attach();
                                //log.Debug(timer, "Debugger attached.");
                                return;
                            }
                        }
                    }
                    catch (System.Runtime.InteropServices.COMException ex)
                    {
                        if (ex.ErrorCode == unchecked ((int)0x8001010A)) // RPC_E_SERVERCALL_RETRYLATER
                        {
                            //log.Debug("Visual Studio was busy while trying to attach. Retrying shortly.");
                            System.Threading.Thread.Sleep(500);
                        }
                        else
                        {
                            //log.Debug(ex);
                            // this probably means someone else was launching at the same time, so you blew up. try again after a brief sleep
                            System.Threading.Thread.Sleep(50);
                        }
                    }
                    catch
                    {
                        //log.Debug(ex);
                        // this probably means someone else was launching at the same time, so you blew up. try again after a brief sleep
                        System.Threading.Thread.Sleep(50);
                    }
                    finally
                    {
                        //Need to release teh com object so other processes get a chance to use it
                        VisualStudioHelper.ReleaseInstance(dte);
                    }
                }
            }
            else
            {
                //log.Debug("Debugger already attached.");
            }
        }