Export (0) Print
Expand All

Debugging a Card Game with IntelliTrace: Part I

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

This topic shows you how to use IntelliTrace to debug a application when an event handler problem causes the application to display an incorrect result. It provides a basic introduction to using IntelliTrace with default settings.

Traditional debuggers show you the state of your application at the current time with limited information about events that occurred in the past. You must either infer events that occurred in the past, based on the state of your application at the current time, or restart the application to re-create past events. If you view a call stack, for example, you see the call stack as it exists at the current point in time. If you want to find information about a previous call, you have to set a breakpoint and restart the debugging session.

With IntelliTrace, you can navigate to various points in time where events of interest have been recorded. At each point, you can drill down into debugging data, examine the call stack, and use other debugging tools to isolate the bug.

The screen shots in this topic show the steps performed in debugging an event handler problem with IntelliTrace. You can read this topic and understand its lessons without installing the sample application. If you prefer, you can install the sample application and perform the actual steps yourself. You can download the sample application from the MSDN Code Gallery.

Because IntelliTrace is turned on by default in Visual Studio Ultimate, you do not have to adjust any settings to complete this walkthrough. The walkthrough is designed to work with the default IntelliTrace settings, but the steps will still work if you have enabled additional settings. 

The application in this topic is written in Visual Basic but should be comprehensible to C# programmers with a basic reading knowledge of Visual Basic code.

Test the Black Jack application

  1. In Visual Studio, open CardGame\CardGame.sln.

  2. On the Debug menu, click Start Debugging.

    The Black Jack application starts and the first page of the application appears.

  3. Click New Game.

    A card table, with playing cards and chips, appears in the window.

  4. Click the 10 button to place a $10 bet.

    At this point, the My Bet box shows that you have bet $25, instead of the $10 you expected.

    This is the bug. Something is wrong with the event handler for the 10 button.

Debug the Button handler bug

  1. To start debugging this problem, you must first break into the debugger. If you have used the Visual Studio debugger before, you know that you can do this from the Debug menu. With Visual Studio Ultimate, you can still do that, but you also have another way to do it. In the IntelliTrace window, several links are displayed. One of these links is Break All, as shown in the following screen shot.

    Debug History Window
  2. In the IntelliTrace window, click Break All.

  3. The IntelliTrace window changes. Instead of the command links, it now shows a list of diagnostic events that IntelliTrace recorded while the Black Jack application ran.

    Diagnostic Events List

    This view of the IntelliTrace window is called the IntelliTrace Events view. Take a moment to examine the diagnostic events and note the controls that appear in this view. Notice the Search box, which enables you to find diagnostic events that match a specified string. There are also two drop-down controls, that you can use to filter the list. These drop-down controls are useful if you want to find events that fall into a specific category or events that occur in a specific thread.

    Each diagnostic event has descriptive text. You can adjust the width of the IntelliTrace window, if necessary, to display the full description.

  4. Notice the event labeled Gesture: Clicked "10" Button. This is the diagnostic event that you are interested in, so click it.

  5. As soon as you click the event, it expands to show additional information:

    Expanded diagnostic event

    The IntelliTrace window now displays a more detailed description of the event, the name and ID number of the thread where the event occurred, and the Related views links. The related views are debugger windows that contain information that might be relevant to the event. You can click a link to open the related view.

    IntelliTrace has automatically located and highlighted the event handler for the Gesture: Clicked "10" Button event, which you clicked in Step 4.

    Now, examine the source code window:

    Source code window

    By examining the source code, you can now see that event is handled by TwentyFiveBtn_Click, instead of TenBtn_Click, which is clearly incorrect. You can now fix this bug.

Show:
© 2014 Microsoft