简体   繁体   中英

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

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.

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:

  • Retry
  • Recompile
  • Restart
  • Reinstall :)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM