This tutorial explores the basic facilities of the C-SPY® debugger while debugging the application used in the previous tutorial Creating an application project. The tutorial assumes that you are using the C-SPY simulator.Contains utility routines required by Fibonacci.c for the Fibonacci calculations.
1 In the IDE and if Information Center is not open, choose Help>Information Center.
2 Click the Product explorer button.
3 Under the heading Getting started using IAR Embedded Workbench, click Open tutorial workspace. Choose a destination for your project in the browse dialog box that appears. We recommend that you create a specific directory (with a subdirectory) where you store all your tutorial files, if not already done. In this tutorial we call the directory MyTutorials and the subdirectory GettingStarted.After you have chosen a destination directory, the GettingStarted workspace which contains the BasicDebugging project, is opened in the IDE.For more information about debugging, see the C-SPY® Debugging Guide.Choose Project>Options and then the Debugger category. On the Setup page, make sure that you have chosen Simulator from the Driver drop-down list and that Run to main is selected. Click OK.
2 Choose Project>Download and Debug. Alternatively, click the Download and Debug button in the toolbar. C-SPY starts with the BasicDebugging project loaded. In addition to the windows already opened in the IDE, a set of C-SPY-specific windows are now available.
3 In the IDE, you can dock windows at specific places, and organize them in tab groups. You can also make a window floating, which means it is always on top of other windows. If you change the size or position of a floating window, other currently open windows are not affected.Depending on the toolchain you are using, the current position—indicated by a green arrow—might now be main or callCount.Before inspecting the source statements, make sure the Fibonacci.c file is open.
1 With Fibonacci.c displayed in the editor window, use the Debug>Step Over command until you reach the call to the InitFib function.Alternatively, click the Step Over button on the toolbar.
2 Alternatively, click the Step Into button on the toolbar.At source level, the Step Over and Step Into commands allow you to execute your application one statement at a time. Step Into continues stepping inside function or subroutine calls, whereas Step Over executes each function call in a single step. For more information, see the C-SPY® Debugging Guide.When Step Into is executed you will notice that the active window changes to Utilities.c because the function InitFib is located in this file.
3
4 Use Step Over until you are back at the top of the for loop. Notice that the step points are on a function call level, not on a statement level.You can also step on a statement level. Choose Debug>Next statement to execute one statement at a time. Alternatively, click the Next statement button on the toolbar.Choose View>Disassembly to open the Disassembly window, if it is not already open.You will see the assembler code corresponding to the current C statement.Click in the Disassembly window to make it active and try the step commands also in the Disassembly window.
In this example procedure, you will look into some of these methods. For more information about inspecting variables, see the C-SPY® Debugging Guide.When the optimization level None is used, all non-static variables will live during their entire scope and thus the variables are fully debuggable. When higher levels of optimizations are used, variables might not be fully debuggable.To use the Auto window:
1
1
2 Set a watchpoint on the variable i using this procedure:
In the entry field that appears, type i and press the Enter key.
3 You can also drag a variable from the editor window to the Watch window. Select the Fib array in the InitFib function, then drag it to the Watch window.The Watch window will show the current value of i and Fib. You can expand the Fib array to watch it in more detail.
4 Execute some more steps to see how the values of i and Fib change. To change a value manually, select it and type a new value.
5
1
2 Right-click and choose Toggle Breakpoint (Code) from the context menu.A breakpoint will be set at this function call. The function call will be highlighted and there will be a red dot in the margin to show that there is a breakpoint there.
Place the insertion point where you want to set the breakpoint and click the Toggle Breakpoint button () on the toolbar.
Place the insertion point where you want to set the breakpoint and choose Edit>Toggle Breakpoint from the main menu bar.
Use the breakpoints dialog box. Choose View>Breakpoints to open the Breakpoints window. In this window, right-click and choose New Breakpoint from the context menu. In the dialog box that appears, specify the breakpoint characteristics.To view the defined breakpoints, choose View>Breakpoints to open the Breakpoints window. You can find information about the breakpoint execution in the Debug Log window.Alternatively, click the Go button on the toolbar.The application will execute up to the breakpoint you have set. The Watch window displays the value of the Fib expression and the Debug Log window contains information about the breakpoint.
1
2 Select the breakpoint, right-click and choose Edit from the context menu.The Edit Breakpoint dialog box appears.
3 Click OK.
4 Click the Go button (). In the Watch window you can see that the execution has stopped according to the condition you specified; thus, the value of i is now 5.
5 Select the breakpoint, right-click and choose Toggle Breakpoint (Code) from the context menu, alternatively choose Toggle Breakpoint from the Edit menu to remove the breakpoint.For more information about breakpoints, see the C-SPY® Debugging Guide.
1 About the Registers window:
2 Click Step Over () to execute the next instructions, and watch how the values change in the Registers window.
3 The Memory window lets you monitor selected areas of memory. In this example procedure, the memory corresponding to the array Fib will be monitored.
1
2 Make the Utilities.c window active and select Fib. Then drag it from the editor window to the Memory window.
3 Depending on the size of your data objects, you might want to change the size of the display format of the memory units. To display the memory contents as 32-bit data units, choose the 4x Units command from the drop-down arrow menu on the Memory window toolbar.If not all memory units have been initialized by the InitFib function of the C application yet, continue to step over and you will notice how the memory contents are updated.To change the memory contents, edit the values in the Memory window. Just place the insertion point at the memory content that you want to edit and type the desired value.Sometimes you must debug applications that use stdin and stdout without having hardware support available. C-SPY lets you simulate stdin and stdout by using the Terminal I/O window.
1 Choose View>Terminal I/O to display the output from the I/O operations.
2 The contents of the window depends on how far you have executed the application.Alternatively, click the Go button on the toolbar.As no more breakpoints are encountered, C-SPY reaches the end of the application and a Program exit reached message is printed in the Debug Log window.If you want to start again with the existing application, choose Debug>Reset, or click the Reset button on the toolbar.
2 To exit from C-SPY, choose Debug>Stop Debugging. Alternatively, click the Stop Debugging button on the toolbar. The IAR Embedded Workbench IDE main window is displayed.For more information about how to use C-SPY, see the C-SPY® Debugging Guide.