This section describes how to debug your application at the register and instruction level. Debugging at a high level is all very well, but there are occasions where you need to look a little more closely into the way that your program executes to track down the causes of difficult-to-find bugs and CrossStudio provides the tools you need to do just this.
What we'll now do is run the sample application, but look at how it executes at the machine level. If you haven't done so already, stop the program executing by typing Shift+F5, by selecting Stop Debugging from the Debug menu, or clicking the Stop Debugging button on the Debug tool bar. Now run the program so that it stops at the first breakpoint again.
You can see the current processor state in the Register windows. To show the first registers window, do one of the following:
—or—
Your registers window will look something like this:
There are four register windows so you can open and display four sets of peripheral registers at the same time. You can change the register display from bytes to words. Click the first tool button on the Registers window tool bar and then check CPU (Word). The registers are then shown as register pairs.
You can also display the contents of peripheral registers in a register window. Click the first tool button on the Registers window tool bar and then check BOOT_LOAD. The bootloader registers are then shown.
You can configure which registers and peripherals to display in the Registers windows individually. As you single step the program, the contents of the Registers window updates automatically and any change in a register value is highlighted in red.
The debugger supports three modes of debug
You have already seen debugging at the source level. To single step at the assembly level, from the Debug menu click Control then Interleaved Mode. The editor window now interleaves the source code of the application with the assembly language generated by the compiler:
In interleaved mode, debugging controls such as single step, step into, and step out work at the instruction level, not the source level. To return to high-level source debugging, select Debug > Control > Source Mode.
There are other windows that help you with debugging, such as the memory view and the watch windows, and the CrossStudio Window Reference describes these.
You can stop debugging using Debug > Stop. If you wish to restart debugging without reloading the program then you can use Debug > Debug From Reset. Note that when you debug from reset no loading takes place so it is expected that your program is built in a way such that any resetting of data values is done as part of the program startup. You can also attach the debugger to a running target using the Debug > Attach Debugger.