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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1235823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:50:07  来源:igfitidea点击:

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

c#.netvisual-studiodebuggingbreakpoints

提问by Ronnie Overby

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?

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

回答by Mehrdad Afshari

Check the Call Stack window (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、调用堆栈)。双击每个条目将带您到调用语句。您还可以右键单击它以启用/禁用显示外部代码项和来自其他线程的调用。

回答by Sam Harwell

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.

无法获取堆栈的另一种情况:您点击 Debug>Break All 并且主线程处于等待/睡眠状态,调试器在构建调用堆栈时可能会出现问题。我相信调试器使用主线程进行隐式函数评估。

Try attaching (or launching) the mixed-mode (native & managed) code debugger and see if that straightens it out.

尝试附加(或启动)混合模式(本机和托管)代码调试器,看看是否能解决问题。

回答by Umair

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)并搜索您的方法名称。

回答by Roman Plá?il

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 :)
  • 重试
  • 重新编译
  • 重新开始
  • 重新安装:)

回答by Miki Watts

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".

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