每次遇到断点时,我都不想拖动执行点或用CTRL SHIFT F10设置它.
我尝试“打印”以下“消息”时命中,但执行继续没有改变.
{return;} {return null;}
请注意,我需要从函数返回而不实际更改代码.
为了阐明Tracepoint是什么:“跟踪点是一个断点,其中包含与之关联的自定义操作.当命中跟踪点时,调试器会执行指定的跟踪点操作,而不是破坏程序执行.”从MSDN起.
如果您不知道“打印消息”的含义,您可能需要阅读有关Tracepoints的this AltDevBlogADay post.很好.
解决方法
请注意,这使用宏并且不能保证与内联委托一起使用;或者使用实际需要返回某些东西的方法.当断点被击中时,它会自动执行@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,然后才能将下一个语句设置到它之外的某个位置.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。