Map methods on the call stack while debugging in Visual Studio

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Create a code map to visually trace the call stack while you’re debugging. You can make notes on the map to track what the code is doing so you can focus on finding bugs.

Debugging with call stacks on code maps

You’ll need:

Map the call stack

  1. Start debugging. (Keyboard: F5)

  2. After your app enters break mode or you step into a function, choose Code Map. (Keyboard: Ctrl + Shift + `)

    Choose Code Map to start mapping call stack

    The current call stack appears in orange on a new code map:

    See call stack on code map

    The map will update automatically while you continue debugging. See Update the map with the next call stack.

Make notes about the code

Add comments to track what’s happening in the code. To add a new line in a comment, press Shift + Return.

Add comment to call stack on code map

Update the map with the next call stack

Run your app to the next breakpoint or step into a function. The map adds a new call stack.

Update code map with next call stack

Add related code to the map

Now you’ve got a map – what next? If you’re working with Visual C# .NET or Visual Basic .NET, add items, such as fields, properties, and other methods, to track what’s happening in the code.

Double-click a method to see its code definition, or use the shortcut menu for the method. (Keyboard: Select the method on the map and press F12)

Go to code definition for a method on code map

Add the items that you want to track on the map.

Show fields in a method on call stack code map

Note

By default, adding items to the map also adds the parent group nodes such as the class, namespace, and assembly. While this is useful, you can keep the map simple by turning off this feature using the Include Parents button on the map toolbar, or by pressing CTRL when you add items.

Fields related to a method on call stack code map

Here you can easily see which methods use the same fields. The most recently added items appear in green.

Continue building the map to see more code.

See methods that use a field: call stack code map

Methods that use a field on call stack code map

Find bugs using the map

Visualizing your code can help you find bugs faster. For example, suppose you’re investigating a bug in a drawing program. When you draw a line and try to undo it, nothing happens until you draw another line.

So you set breakpoints in the clear, undo, and Repaint methods, start debugging, and build a map like this one:

Add another call stack to code map

You notice that all the user gestures on the map call Repaint, except for undo. This might explain why undo doesn’t work immediately.

After you fix the bug and continue running the program, the map adds the new call from undo to Repaint:

Add new method call to call stack on code map

Q & A

  • Not all calls appear on the map. Why?

    By default, only your own code appears on the map. To see external code, turn it on in the Call Stack window:

    Display external code using the Call Stack window

    or turn off Enable Just My Code in the Visual Studio debugging options:

    Show external code using Options dialog

  • Does changing the map affect the code?

    Changing the map doesn’t affect the code in any way. Feel free to rename, move, or remove anything on the map.

  • What does this message mean: “The diagram may be based on an older version of the code”?

    The code might have changed after you last updated the map. For example, a call on the map might not exist in code anymore. Close the message, then try rebuilding the solution before updating the map again.

  • How do I control the map’s layout?

    Open the Layout menu on the map toolbar:

    • Change the default layout.

    • To stop rearranging the map automatically, turn off Automatically Layout when Debugging.

    • To rearrange the map as little as possible when you add items, turn off Incremental Layout.

  • Can I share the map with others?

    You can export the map, send it to others if you have Microsoft Outlook, or save it to your solution so you can check it into Team Foundation version control.

    Share call stack code map with others

  • How do I stop the map from adding new call stacks automatically?

    Choose Button - Show call stack on code map automatically on the map toolbar. To manually add the current call stack to the map, press Ctrl + Shift + `.

    The map will continue highlighting existing call stacks on the map while you’re debugging.

  • What do the item icons and arrows mean?

    To get more info about an item, move the mouse pointer over it and look at the item’s tooltip. You can also look at the Legend to learn what each icon means.

    What do icons on the call stack code map mean?

    See: Map the call stackMake notes about the codeUpdate the map with the next call stackAdd related code to the mapFind bugs using the map

See Also

Map dependencies across your solutions Use code maps to debug your applications Find potential problems using code map analyzers Browse and rearrange code maps