2008-10-01 32 views

回答

2

我不知道是什麼DTE功能使用,但你可以非常簡單地錄製宏,可以幾乎做到這一點:

  1. 轉到文件
  2. CTRL頂部 - 轉移 - R(開始錄製)
  3. ctrl -I(增量搜索)
  4. {(搜索第一個{字符)。
  5. F9(設置斷點)
  6. CTRL - (去匹配}字符)
  7. CTRL - 移 - R(停止錄音)

現在只要運行這個遍地(CTRL - SHIFT P重複),直到您到達文件末尾。

如果有名稱空間,然後改變4.:

  • ((搜索 「(」 在函數定義的開始)
  • ESC(停止增量搜索)
  • CTRL - 我(再次增量搜索)
  • {(函數體開始)
  • 這種東西可以無限修改,以適應你的代碼

    +0

    我有匿名命名空間,它會工作嗎? (目前沒有VS來檢查) – Constantin 2008-10-01 22:30:07

    +0

    實際上(忽略我以前的評論)它顯然會跳過命名空間中的代碼。嘗試在 – 2008-10-02 00:40:28

    +0

    中編輯的更改無法在VS 2010中使用此功能 - 錄製宏時禁用增量搜索。 – 2011-07-26 19:14:12

    0

    在文件的頂部將這個:

    #define WANT_BREAK_IN_EVERY_FUNCTION 
    
    #ifdef WANT_BREAK_IN_EVERY_FUNCTION 
    #define DEBUG_BREAK DebugBreak(); 
    #else 
    #define DEBUG_BREAK 
    #endif 
    

    然後在每個函數的開頭插入DEBUG_BREAK,像這樣:

    void function1() 
    { 
        DEBUG_BREAK 
        // the rest of the function 
    } 
    
    void function2() 
    { 
        DEBUG_BREAK 
        // the rest of the function 
    } 
    

    當你不再需要調試中斷,評論行

    // #define WANT_BREAK_IN_EVERY_FUNCTION 
    

    在文件的頂部。

    +1

    我想要一個不引人注目的自動化解決方案。我可以在每個功能中按F9。 – Constantin 2008-10-02 07:56:33

    1

    下面是類似的東西可以在WinDbg中實現:

    bm mymodule!CSpam::* 
    

    這模塊mymodule把斷點類(或命名空間)CSpam的每一個方法。

    我仍然在Visual Studio中尋找任何接近此功能的東西。

    5

    這裏有一個快速實施的1800信息的想法:

    Sub TemporaryMacro() 
        DTE.ActiveDocument.Selection.StartOfDocument() 
        Dim returnValue As vsIncrementalSearchResult 
        While True 
         DTE.ActiveDocument.ActiveWindow.Object.ActivePane.IncrementalSearch.StartForward() 
         returnValue = DTE.ActiveDocument.ActiveWindow.Object.ActivePane.IncrementalSearch.AppendCharAndSearch(AscW("{")) 
         DTE.ActiveDocument.ActiveWindow.Object.ActivePane.IncrementalSearch.Exit() 
         If Not (returnValue = vsIncrementalSearchResult.vsIncrementalSearchResultFound) Then 
          Return 
         End If 
         DTE.ExecuteCommand("Debug.ToggleBreakpoint") 
         DTE.ExecuteCommand("Edit.GotoBrace") 
         DTE.ActiveDocument.Selection.CharRight() 
        End While 
    End Sub 
    
    +0

    +1,但不能接受,因爲它不適用於名稱空間。 – Constantin 2008-12-15 08:28:34

    +2

    如果您遇到命名空間問題,請將註釋轉到文檔開頭的第一行。您需要手動將光標放在要切換的塊的開頭,但它會起作用。 – tfinniga 2010-08-02 16:00:07

    2

    像康斯坦丁的方法......這似乎是WinDbg的領土。

    既然你有cpp(即使你沒有腳本可以編寫腳本),使用logger作爲windows調試工具的一部分應該沒有問題......這是一個非常方便的工具,可惜很少有人使用它。

    記錄器調試的C/COM/C + +輕鬆,具有豐富的符號信息,鉤/分析/靈活的儀器;

    One way to activate Logger is to start CDB or WinDbg and attach to a user-mode target application as usual. Then, use the !logexts.logi or !logexts.loge extension command. This will insert code at the current breakpoint that will jump off to a routine that loads and initializes Logexts.dll in the target application process. This is referred to as "injecting Logger into the target application."

    0

    有一個宏,但我只用c#測試它。

    Sub BreakAtEveryFunction() 
    For Each project In DTE.Solution.Projects 
        SetBreakpointOnEveryFunction(project) 
    Next project 
    End Sub 
    
    
    Sub SetBreakpointOnEveryFunction(ByVal project As Project) 
    Dim cm = project.CodeModel 
    
    ' Look for all the namespaces and classes in the 
    ' project. 
    Dim list As List(Of CodeFunction) 
    list = New List(Of CodeFunction) 
    Dim ce As CodeElement 
    For Each ce In cm.CodeElements 
        If (TypeOf ce Is CodeNamespace) Or (TypeOf ce Is CodeClass) Then 
         ' Determine whether that namespace or class 
         ' contains other classes. 
         GetClass(ce, list) 
        End If 
    Next 
    
    For Each cf As CodeFunction In list 
    
        DTE.Debugger.Breakpoints.Add(cf.FullName) 
    Next 
    
    End Sub 
    
    Sub GetClass(ByVal ct As CodeElement, ByRef list As List(Of CodeFunction)) 
    
    ' Determine whether there are nested namespaces or classes that 
    ' might contain other classes. 
    Dim aspace As CodeNamespace 
    Dim ce As CodeElement 
    Dim cn As CodeNamespace 
    Dim cc As CodeClass 
    Dim elements As CodeElements 
    If (TypeOf ct Is CodeNamespace) Then 
        cn = CType(ct, CodeNamespace) 
        elements = cn.Members 
    Else 
        cc = CType(ct, CodeClass) 
        elements = cc.Members 
    End If 
    Try 
        For Each ce In elements 
         If (TypeOf ce Is CodeNamespace) Or (TypeOf ce Is CodeClass) Then 
          GetClass(ce, list) 
         End If 
         If (TypeOf ce Is CodeFunction) Then 
          list.Add(ce) 
         End If 
        Next 
    Catch 
    End Try 
    End Sub 
    
    0

    下面是做這件事(我警告你,這是哈克):

    EnvDTE.TextSelection textSelection = (EnvDTE.TextSelection)dte.ActiveWindow.Selection; 
    // I'm sure there's a better way to get the line count than this... 
    var lines = File.ReadAllLines(dte.ActiveDocument.FullName).Length; 
    var methods = new List<CodeElement>(); 
    var oldLine = textSelection.AnchorPoint.Line; 
    var oldLineOffset = textSelection.AnchorPoint.LineCharOffset; 
    EnvDTE.CodeElement codeElement = null; 
    for (var i = 0; i < lines; i++) 
    { 
        try 
        { 
         textSelection.MoveToLineAndOffset(i, 1); 
         // I'm sure there's a better way to get a code element by point than this... 
         codeElement = textSelection.ActivePoint.CodeElement[vsCMElement.vsCMElementFunction]; 
         if (codeElement != null) 
         { 
          if (!methods.Contains(codeElement)) 
          { 
           methods.Add(codeElement); 
          } 
         } 
        } 
        catch 
        { 
         //MessageBox.Show("Add error handling here."); 
        } 
    } 
    
    // Restore cursor position 
    textSelection.MoveToLineAndOffset(oldLine, oldLineOffset); 
    
    // This could be in the for-loop above, but it's here instead just for 
    // clarity of the two separate jobs; find all methods, then add the 
    // breakpoints 
    foreach (var method in methods) 
    { 
        dte.Debugger.Breakpoints.Add(
         Line: method.StartPoint.Line, 
         File: dte.ActiveDocument.FullName); 
    } 
    
    相關問題