好吧,有點你周圍挖後可以做到這一點 - 但它不會在所有情況下工作。
請注意,它使用宏並且不能保證與內聯代理一起使用;或者實際需要返回某些東西的方法。它自動執行@juergen d和@Erno描述的過程,當斷點被擊中時;使用非常簡單的啓發式查找當前函數的結束位置。
您首先需要將此宏添加到您的宏環境(使用VS中的ALT + F11打開)。此代碼可能不是好,因爲它可能是因爲我剛剛在地方衝出來:)
Sub ExitStack()
'get the last-hit breakpoint
Dim breakPoint As EnvDTE.Breakpoint
breakPoint = DTE.Debugger.BreakpointLastHit()
'if the currently open file is the same as where the breakpoint is set
'(could search and open it, but the debugger *should* already have done that)
If (DTE.ActiveDocument.FullName = breakPoint.File) Then
Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
Dim editPoint As EnvDTE.EditPoint
'move the cursor to where the breakpoint is actually defined
selection.MoveToLineAndOffset(breakPoint.FileLine, breakPoint.FileColumn)
Dim codeElement As EnvDTE.CodeElement
codeElement = DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElementFromPoint(selection.ActivePoint, vsCMElement.vsCMElementFunction)
'if a function is found, move the cursor to the last character of it
If Not (codeElement Is Nothing) Then
Dim lastLine As EnvDTE.TextPoint
lastLine = codeElement.GetEndPoint()
selection.MoveToPoint(lastLine)
selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
'execute the SetNextStatement command.
'Has to be done via ExecuteCommand
DTE.ExecuteCommand("Debug.SetNextStatement")
End If
End If
End Sub
就這樣,現在你可以設置你的斷點 - 右鍵單擊它,然後按下When hit...
菜單選項(這隻適用於VS2010我相信)。 ScottGu在this博客文章中對此進行了描述。
從對話框中找到ExitStack
宏,你剛剛粘貼進來。
運行與調試器的代碼連接,當斷點命中函數的代碼的其餘部分應被跳過。這應該服從其他調試器技巧 - 如條件等。
注 - 我使用this SO來解決我遇到的問題;最初我直接調用調試器的SetNextStatement方法,它不起作用
我不知道應該返回的方法將如何表現 - 理論上它們應該返回當前返回值的任何值,但在某些情況下事實是,這根本行不通!
同樣,如果斷點位於try/catch塊中,那麼它將不起作用 - 因爲try/catch必須先退出,然後才能將下一個語句設置到它之外的某個位置。
很酷。我仍然希望有人有一個非宏觀,價值回報的答案,但這是目前爲止最好的答案。 –
@Protectorone沒有一個 - 除非你編寫你自己的調試器。如果一個方法返回一個局部變量,你可以使用watch(甚至使用另一個宏)來設置局部變量,然後使用這個變量返回。 –