c# – 使用断点从函数返回
是否可以使用断点/跟踪点自动从函数返回?
每次遇到断点时,我都不想拖动执行点或用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,然后才能将下一个语句设置到它之外的某个位置. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- Flash Builder 4.6 无法生成 html 文件的解决方法
- ruby-on-rails – 对于rails app,如何在html中显示多个flas
- ruby – 在Balanced gem中创建卡时获取Faraday :: Error ::
- ruby – 可能instance_eval一个curried proc?
- 数组 – 在Swift中重复数组
- xml – 动态更改功能区的按钮标签Excel
- ios – 错误:包中的Info.plist必须包含CFBundleIdentifier
- c – 使用gcc的boost :: variant链接器错误
- swift – AppleTv / TvOS – 调整TVContentItems中保存到Im
- reactjs – 如何:使用React JS环境