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.

###### Setting up again

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:

- From the Debug menu, click Debug Windows then Registers 1.

—or—

- Type Ctrl+T, R, 1.

Your registers window will look something like this:

This register view is displaying the registers for the active processor mode. You can also display the entire set of ARM registers, to do this select CPU - ALL from the Groups menu on the toolbar.

There are four register windows so you can open and display four sets of peripheral registers at the same time.

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.

###### Debugging modes

The debugger supports three modes of debug

- Source mode where the source code is displayed in a code editor.
- Interleaved mode where the editor displays an interleaved listing of the currently located source code. All single stepping is done an instruction at a time.
- Assembly mode where a disassembly of the instructions around the currently located instruction is shown in the editor. All single stepping is done an instruction at a time.

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.

###### Stopping and starting debugging

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.