在 Visual Studio 2008 中单步执行 C# 时如何找到方法调用方?
如果我在方法上设置断点,当在 Visual Studio 2008 中命中断点时,如何查看调用该方法的内容?
If I set a breakpoint on a method, how can I see what called the method, when the breakpoint is hit in Visual Studio 2008?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
检查“调用堆栈”窗口(从菜单:“调试”>“窗口”>“调用堆栈”)。 双击每个条目将转到调用语句。 您还可以右键单击它以启用/禁用显示外部代码项和来自其他线程的调用。
Check the Call Stack window (from the menu: Debug > Windows > Call Stack). Double clicking each entry there will take you to the calling statement. You can also right click on it to enable/disable showing external code items and calls from other threads.
当断点被击中时,您可以查看整个调用堆栈。 您可以通过“调试”菜单 ->“Windows”->“调用堆栈”来打开该窗口。
您还可以通过快捷键 Alt+Ctrl+C
编辑来调出它:
您还可以右键单击函数名称,然后查看“调用者图表”,它将显示您的方法的所有调用者。 或者,您可以打开调用浏览器(通过查看 -> 其他窗口 -> 调用浏览器)并搜索方法的名称。
When the breakpoint is hit, you can view the entire call stack. You can bring that window up by going through the Debug menu->Windows->Call Stack.
You can also bring it up by the shortcut Alt+Ctrl+C
EDIT:
You can also right-click on a function name, and view the "Callers Graph", which will show you all the callers for your method. Alternatively, you can bring the Call Browser (by going to View->Other windows->Call Browser ) and search for your method's name.
如果您在用户设置的断点处看不到调用堆栈中的任何内容,通常意味着它是从本机代码调用的。
另一种无法获取堆栈的情况:您点击“调试”>“全部中断”并且主线程处于等待/睡眠状态,调试器在构建调用堆栈时可能会出现问题。 我相信调试器使用主线程进行隐式函数评估。
尝试附加(或启动)混合模式(本机和托管)代码调试器,看看是否可以解决问题。
If you can't see anything in the call stack at a user-set breakpoint, it generally means it was called from native code.
Another case where it can't get a stack: You hit Debug>Break All and the main thread is in a wait/sleep state, the debugger can have problems building the call stack. I believe the debugger uses the main thread for its implicit function evaluation.
Try attaching (or launching) the mixed-mode (native & managed) code debugger and see if that straightens it out.
如果您在“调用堆栈”窗口中看不到任何内容,则肯定有问题。 我建议使用著名的 R 操作序列:
If you can't see anything in the Call Stack window, then there's definitely something wrong. I would suggest the famous sequence of R-actions:
如果断点位于由事件引发的函数中,您可能没有返回调用者的直接调用堆栈,并且需要启用查看所有代码,而不仅仅是“只是我的代码”。
If the break point is in a function that is raised by an event, you might not have a direct call stack back to the caller, and will need to enable viewing all code, and not just "just my code".
对于 Visual Studio 2019 打开查看菜单并选择调用层次结构,
或者只需按CTRL+ALT+K
For Visual Studio 2019 Open View menu and select Call Hierarchy,
or simply press CTRL+ALT+K