Map methods on the call stack while debugging - Visual Studio 2015 (original) (raw)


Share via


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

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

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