Reputation: 46460
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?
Upvotes: 31
Views: 17764
Reputation: 421968
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.
Upvotes: 63
Reputation: 2799
For Visual Studio 2019 Open View menu and select Call Hierarchy, or simply press CTRL+ALT+K
Upvotes: 0
Reputation: 1756
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".
Upvotes: 1
Reputation: 99859
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.
Upvotes: 4
Reputation: 1970
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:
Upvotes: 1
Reputation: 862
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.
Upvotes: 4