Debugging with Intellitrace Using Visual Studio 2010 Ultimate

Debugging with Intellitrace Using Visual Studio 2010 Ultimate

Hands-On Lab

Debugging with IntelliTrace using Visual Studio 2010 Ultimate

Lab version: 1.0.0

Last updated:5/19/2019

Contents

Overview

Exercise 1: Introduction to IntelliTrace

Exercise 2: Using IntelliTrace with Call Information

Overview

In this lab you will learn about the new IntelliTrace debugging feature provided in Visual Studio 2010 Ultimate. Before the addition of IntelliTrace, debugging was done from a specific point in time going forward. If you wanted to find out more information for a previous call, you would set a breakpoint and then re-run the application. IntelliTrace now enables you to seek to a large number of execution points, that occurred in the past, and drill into any of them, comparing variables, call stacks, etc. in order to help pinpoint causes of issues without having to reproduce the problem.

System Requirements

In order to complete this lab you will need the Visual Studio 2010 virtual machine provided by Microsoft. For more information on acquiring and using this virtual machine, please see this blog post.

Exercises

This Hands-On Lab comprises the following exercises:

  1. Introduction to IntelliTrace
  2. Using IntelliTrace with Call Information

Estimated time to complete this lab: 60 minutes.

Next Step

Exercise 1: Introduction to IntelliTrace

Exercise 1: Introduction to IntelliTrace

In this exercise, you will be see how the default settings for IntelliTrace can help debug an XML data failure on an ASP.NET website.

Supported applications and debugging scenarios:

IntelliTrace supports debugging Visual Basic and C# applications that use .NET version 2.0, 3.0, 3.5, or 4 (ASP.NET, Windows Forms, WPF, Windows Workflow, and WCF). IntelliTrace does not support debugging C++, script, or non-managed languages. For more detailed information about IntelliTrace support, please refer to the Visual Studio 2010 documentation on the Microsoft Developer Network (

  1. Log in as Abu Obeida Bakhach (Dev) if you have not already done so. The password is P2ssw0rd (capital letter P, the number two, the letter s, the letter s, the letter w, the number zero, the letter r, and the letter d). Please see “Working with the Visual Studio 2010 Virtual Machine” for instructions on how to log into the VM.
  2. Open Microsoft Visual Studio from Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
  3. In Source Control Explorer (View | Other Windows | Source Control Explorer), navigate to Tailspin Toys | Development | Iteration 2 and double-click on the TailspinToys.sln file to open the Tailspin Toys solution.
  4. Rebuild the solution (Build | Rebuild Solution from the main menu). This step may take a few minutes to complete.
  5. Open the Options window from Tools | Options... and click on the IntelliTrace node.
  6. Ensure that the Enable IntelliTrace checkbox is checked and that it is set to “IntelliTrace events only”. This is the default setting because it has minimal performance implications.

Figure 2

IntelliTrace options

Note: IntelliTrace records events to a IntelliTrace file, which has an .iTrace extension. These files can be saved and used later in order to perform debugging with IntelliTrace, enabling testers to attach this detailed debugging information directly to bug reports.

  1. Start a debugging session by pressing F5. This will load the default page for the fictional Tailspin Toys company.

Note: If the Tailspin.Web project is not set as the startup project, right-click on the Tailspin.Web node in Solution Explorer and select the “Set as StartUp Project” option.

Figure 3

Tailspin Toys Default page

  1. Select the About Us link in the footer of the page. This will generate an exception and show a custom ASP.NET error page for the Tailspin Toys application.

Figure 4

Error page shown when loading About Us

  1. Switch back to Visual Studio and select Debug | Break All so that we can begin the debugging process. If the IntelliTrace window is not visible, open it by selecting Debug | Windows | IntelliTrace Events from the main menu. The IntelliTrace Events window shows a sequential list of events that have been collected since you started the debugging session, with the most recent being at the bottom.

Figure 5

IntelliTrace window showing recorded events

Note: IntelliTrace is by default configured to collect certain events when debugging, some of which you can see in the IntelliTrace Events window now. You can configure which event categories or even specific events are collected in the IntelliTrace options node (Tools | Options).

  1. In the IntelliTrace Events window, locate and select the “Exception Thrown” event that occurs after the ‘/Views/Home/About” page is loaded. This will show details about the exception that occurred, as well as provide links to the Locals and Call Stack windows. This exception lets us know that there is a problem with an XML file on line 10, column 49, but it does not tell us which XML file this is in referring to.

Figure 6

Exception thrown when parsing an XML file

Figure 7

Locals and Call Stack windows state during selected exception

  1. Select the “XML Loading” event immediately preceding the exception to see the file that was accessed just before the exception occurred.

Figure 8

XML loading event

  1. Open the Ads.xml file by clicking on the provided link and navigating to the Tailspin.Web\Content\XML\Ads.xml file and selecting the Open button.

Note: You will need to navigate to the Iteration 2 folder at c:\ws\abuobe\Tailspin Toys\Development\Iteration 2.

  1. Observe that there is a red squiggly line under the “&b=1” characters which are invalid in this context. Note that this is on line 10, column 49 just as we expected from the XML exception.

Figure 9

Ads.xml showing invalid characters

  1. Remove the invalid characters and save the file. The final URL should be .

Note: Select the Edit button when prompted by the Edit and Continue window.

  1. Press F5 twice to continue running the application.
  2. Switch back to Internet Explorer and click the About Us link again to verify that the problem is now fixed. The bottom of the About page shows one of the ads that is specified in the Ads.xml file.

Figure 10

About page with working ad

  1. Stop the current debugging session (Debug | Stop Debugging).

Next Step

Exercise 2: Using IntelliTrace with Call Information

Exercise 2: Using IntelliTrace with Call Information

In this exercise, you will learn how to use IntelliTrace to collect additional call information in order to solve a more complicated user code error.

  1. By default, only IntelliTrace events are collected when debugging, but we can also opt to collect data at every method enter/exit and call site. To enable this, select Tools | Options from the main menu in Visual Studio, locate the IntelliTrace node, and select the “IntelliTrace events and call information” option.

Figure 11

IntelliTrace options adjusted to record call information

  1. Select the OK button to continue.
  2. Start a debugging session by pressing F5.
  3. Let’s test out the shopping cart functionality by adding a couple of products to the cart. Select the “Paper Airplanes” header to see a catalog of planes.

Figure 12

Catalog of paper airplanes

  1. Next, select the “View Plane” button for the Contoso Cloud Explorer.

Figure 13

Contoso Cloud Explorer product page

  1. Select the “Add To Cart” button and verify that the Quantity of the item in the cart is 1.

Figure 14

Shopping cart showing 1 airplane

  1. Add another “Contoso Cloud Explorer” to the shopping cart by selecting the “Contoso Cloud Explorer” link and selecting the “Add To Cart” button once again. Note that the Quantity value is still 1 even though we added 2 products.
  2. Return to Visual Studio and select Debug | Break All. By default, we see the IntelliTrace Events window showing the sequence of recorded events leading up to the debugger break. In this case, however, the events will not be of much use in debugging the Tailspin Toys shopping cart logic sine this code is not part of the .NET framework.
  3. In the search box at the top of the IntelliTrace window, type “post” and press Enter to conduct a search. This will return two “Post” events, one for each shopping cart item added.
  4. Select the second “Post /Cart/AddItem/” event. We will use this as a reference point to aid in navigating to the point in the debugging session where the Add Item logic begins.

Figure 15

Second ASP.NET POST event selected

  1. Return to the full list of recorded events by clicking the blue “X” to the right of the search box.
  2. Select the “Calls View” link at the bottom of the selected event to show a complete call hierarchy of the debugging session. The top frame of the calls view shows the stack for the currently selected call.

Note: You can also use the “Show Calls View” button at the top of the IntelliTrace window.

Figure 16

Location of “Calls View” link

Figure 17

IntelliTrace calls view

  1. In the IntelliTrace calls view, double-click on the call “Tailspin.Web.App.Controllers.CartController.AddItem(string sku = “papcce”)”. Each time you double-click on a call in the bottom half of the calls view, the call is popped to the bottom of the top frame and the Instruction Pointer syncs in the code editor to the method entry point of the call just like in live debugging when you walk up the stack.
  2. In the IntelliTrace calls view, double-click on the call “Tailspin.Model.ShoppingCart.AddItem(Tailspin.Model.Product produt = {Tailspin.Model.Product})”.
  3. In the IntelliTrace calls view, double-click on the call to AddItem that shows “Tailspin.Model.Product product = {Tailspin.Model.Product}, int quantity = 1)” as the parameter.
  4. In the IntelliTrace calls view, double-click on the call to AddItem that shows “Tailspin.Model.Product product = {Tailspin.Model.Product}, int quantity = 1, System.DateTime dateAdded = …)” as the parameter. Navigating through the calls view is a quick way to gain an overview of the call hierarchy and to make large jumps across the call hierarchy without stepping through line by line.

Figure 18

IntelliTrace calls view showing call to AddItem method

  1. In the Locals window, expand the “AddItem” function call to validate that the correct product was being added to the cart and that the quantity being added was 1. At any point in IntelliTrace debugging, you can look at the collected variables in the Autos/Locals/Watch window or by using the datatips in the editor.

Figure 19

Locals window showing parameters during call to AddItem

  1. Step forward two calls by pressing F10 twice. Keep in mind that since we are in IntelliTrace debugging mode, we are stepping through recorded events and call sites, not line by line of code.

Figure 20

Location in AddItem method where AdjustQuantity is called

Note: You can also use the new set of “VCR” style controls shown in the gutter of the source code window.

  1. In the Locals window, expand the “AdjustQuantity” function call to see what quantity the cart is being set to after adding the second product. Since we are expecting the adjusted quantity to be 2, we have found the location of the bug.
  2. Stop the current debugging session (Debug | Stop Debugging).
  3. Change the AdjustQuantity(…) call so that it adds in the new quantity passed to the AddItem method.

Figure 21

Fixed call to AdjustQuantity method

  1. Verify the fix by adding the same product twice to ensure that the shopping cart quantity shows the value 2.

Figure 22

Shopping cart showing correct quantity of product items

Note: You can clear out the current shopping cart by manually removing items or by selecting Safety | Delete Browsing History from the main menu in Internet Explorer.

To give feedback please write to

Copyright © 2010 by Microsoft Corporation. All rights reserved.