19

Visual Studio 提供了许多导航热键: F8用于当前面板中的下一项(搜索结果、错误...)、 Control+ KN用于书签、 Alt+-用于返回等等。

我找不到一个热键,我什至找不到它的菜单命令,所以我自己无法创建热键。

我不知道是否存在:上一个和下一个调用堆栈框架。

我在编程时尽量不用鼠标,但是当我需要回栈时,我必须用它来双击上一帧。

任何人?做它的宏怎么样?

4

5 回答 5

19

我写了2个宏来获得它:PreviousStackFrameNextStackFrame分配了快捷方式

Function StackFrameIndex(ByRef aFrames As EnvDTE.StackFrames, ByRef aFrame As EnvDTE.StackFrame) As Long
    For StackFrameIndex = 1 To aFrames.Count
        If aFrames.Item(StackFrameIndex) Is aFrame Then Exit Function
    Next
    StackFrameIndex = -1
End Function

Sub NavigateStack(ByVal aShift As Long)
    If DTE.Debugger.CurrentProgram Is Nothing Then
        DTE.StatusBar.Text = "No program is currently being debugged."
        Exit Sub
    End If

    Dim ind As Long = StackFrameIndex(DTE.Debugger.CurrentThread.StackFrames, DTE.Debugger.CurrentStackFrame)
    If ind = -1 Then
        DTE.StatusBar.Text = "Stack navigation failed"
        Exit Sub
    End If

    ind = ind + aShift
    If ind <= 0 Or ind > DTE.Debugger.CurrentThread.StackFrames.Count Then
        DTE.StatusBar.Text = "Stack frame index is out of range"
        Exit Sub
    End If

    DTE.Debugger.CurrentStackFrame = DTE.Debugger.CurrentThread.StackFrames.Item(ind)
    DTE.StatusBar.Text = "Stack frame index: " & ind & " of " & DTE.Debugger.CurrentThread.StackFrames.Count
End Sub

Sub PreviousStackFrame()
    NavigateStack(1)
End Sub

Sub NextStackFrame()
    NavigateStack(-1)
End Sub
于 2009-07-31T10:17:23.653 回答
3

我已经用AutoHotkey解决了这个问题。我几个月前做的。假设您想使用 Control+1 和 Control+2 并且 Control+Alt+C 必然会显示调用堆栈窗口:

^1::SendInput !^c{down}{enter}
^2::SendInput !^c{up}{enter}

它似乎工作得很好。如果您还没有使用 AutoHotkey 向 Visual Studio 展示谁是老大,请试一试。你的问题表明你会从中受益匪浅。这是一个改变游戏规则的人。祝你好运。

于 2014-11-03T16:26:40.737 回答
2

我认为没有明确的下一帧/前一帧键绑定,但这就是我所做的。

CTRL-ALT-C 已经绑定到“Debug.CallStack” 这将使您集中在调用堆栈工具窗口中

一旦聚焦在 Callstack 窗口中...向上和向下箭头将移动您通过调用堆栈帧

然后我绑定了

CTRL-C、CTRL-S 到“DebuggerContextMenus.CallStackWindow.SwitchToFrame”和 CTRL-C、CTRL-C 到“DebuggerContextMenus.CallStackWindow.SwitchToCode”

两者都会带您回到特定帧的代码窗口。

希望有帮助。

于 2008-10-23T17:34:00.113 回答
1

非常感谢@Oleg Svechkarenko 的回答,这给了我制定这个解决方案的起点。由于现代版本的 Visual Studio 不再有官方宏支持,这应该适合那些使用Visual Commander插件的人,但可能很容易适应任何其他宏扩展。

这是命令的代码,我创建了一个用于向上导航调用堆栈,另一个用于使用相同的代码向下导航,除了传递给的参数MoveStackIndex(),然后将键盘快捷键绑定到它们:

using EnvDTE;
using EnvDTE80;
using System;

public class C : VisualCommanderExt.ICommand
{
    enum MoveDirection
    {
        Up,
        Down,
    }

    private bool IsValidFrame(StackFrame frame)
    {
        string language = frame.Language;

        bool result = (language == "C#"  || 
                       language == "C++" || 
                       language == "VB"  || 
                       language == "Python");

        return result;
    }

    private void MoveStackIndex(EnvDTE80.DTE2 DTE, MoveDirection direction)
    {
        StackFrame currentFrame = DTE.Debugger.CurrentStackFrame;

        bool foundTarget = false;
        bool pastCurrent = false;

        StackFrame lastValid = null;
        foreach (StackFrame frame in DTE.Debugger.CurrentThread.StackFrames)
        {
            bool isCurrent = frame == currentFrame;

            if (direction == MoveDirection.Down)
            {
                if (isCurrent)
                {
                    if (lastValid == null)
                    {
                        // No valid frames below this one
                        break;
                    }
                    else
                    {
                        DTE.Debugger.CurrentStackFrame = lastValid;
                        foundTarget = true;
                        break;                      
                    }
                }
                else
                {
                    if (IsValidFrame(frame))
                    {
                        lastValid = frame;
                    }
                }
            }

            if (direction == MoveDirection.Up && pastCurrent)
            {
                if (IsValidFrame(frame))
                {
                    DTE.Debugger.CurrentStackFrame = frame;
                    foundTarget = true;
                    break;
                }               
            }

            if (isCurrent)
            {
                pastCurrent = true;
            }
        }

        if (!foundTarget)
        {
            DTE.StatusBar.Text = "Failed to find valid stack frame in that direction.";
        }
    }

    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
    {
        if (DTE.Debugger.CurrentProgram == null)
        {
            DTE.StatusBar.Text = "Debug session not active.";
        }
        else
        {
            // NOTE: Change param 2 to MoveDirection.Up for the up command
            MoveStackIndex(DTE, MoveDirection.Down);
        }
    }
}
于 2018-07-05T04:58:09.917 回答
-1

查看Tools->Options->Environment->Keyboard。输入“stack”或“frame”,将出现相关菜单。似乎没有下一个和上一个调用堆栈框架。

于 2008-10-23T11:32:38.907 回答