简体   繁体   English

在 Visual Studio 2008 中单步执行 C# 时如何找到方法调用者?

[英]How can I find a method caller when stepping through C# in Visual Studio 2008?

如果我在方法上设置断点,当在 Visual Studio 2008 中遇到断点时,如何查看调用了该方法的内容?

Check the Call Stack window (Debug, Windows, Call Stack).检查调用堆栈窗口(调试、Windows、调用堆栈)。 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.您还可以右键单击它以启用/禁用显示外部代码项和来自其他线程的调用。

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.您可以通过调试菜单->Windows->调用堆栈来打开该窗口。

You can also bring it up by the shortcut Alt+Ctrl+C您也可以通过快捷键 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.或者,您可以使用 Call Browser(通过转到 View->Other windows->Call Browser)并搜索您的方法名称。

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.无法获取堆栈的另一种情况:您点击 Debug>Break All 并且主线程处于等待/睡眠状态,调试器在构建调用堆栈时可能会出现问题。 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.尝试附加(或启动)混合模式(本机和托管)代码调试器,看看是否能解决问题。

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:我会建议著名的 R 动作序列:

  • Retry重试
  • Recompile重新编译
  • Restart重新开始
  • Reinstall :)重新安装:)

如果断点位于由事件引发的函数中,则您可能没有返回调用者的直接调用堆栈,并且需要启用查看所有代码,而不仅仅是“仅我的代码”。

对于 Visual Studio 2019 打开View菜单并选择Call Hierarchy ,或只需按CTRL+ALT+K

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在Visual C#2008 Studio中找不到Var关键字? - Why can't I find the Var keyword in my Visual C# 2008 Studio? Visual Studio 2008 / C#:如何在项目中找到死代码? - Visual Studio 2008 / C# : How to find dead code in a project? 使用Visual Studio 2010 C#进行调试时,如何避免进入常用功能? - When debugging using Visual Studio 2010 C#, how to avoid stepping into common functions? Visual Studio 2008 C#-我可以在dataviewgrid中搜索数据吗? - Visual Studio 2008 C# - Can I search for data in dataviewgrid? 为什么在逐步使用C#代码时,Visual Studio 2010可以在C ++模式下进行漂亮打印? - Why is Visual Studio 2010 pretty-printing in C++ mode while stepping through C# code? 进入调试器时,Visual Studio 2008,Excel加载项挂起 - Visual Studio 2008, excel add-in hangs when stepping in debugger C# 如何获取调用者的调用者成员名称? - C# How can I get the caller member name of the caller? 通过Visual Studio 2010 C#访问sql 2008数据库 - Accessing sql 2008 database through visual studio 2010 C# 如何使用Visual C#Express 2008制作图表? - How can I make a chart with visual c# express 2008? C#,Visual Studio 2008 - C#, Visual Studio 2008
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM