19.3.4. Manipulating registers and variables

With a thread selected into a Code window, the Register pane displays the registers associated with the thread, which might not have the same values as the current processor registers.

You can change the value in a register in the usual way (as described in the Changing register contents), but the changed value is not necessarily written into the processor register. Instead, unless the thread is currently running on the processor, it is written to the RTOS Task Control Block (TCB) for the selected thread. When that thread is next scheduled by the RTOS scheduler, the registers used by the new thread are read from the TCB into the processor.

When a thread is interrupted, the Code window displays the code around the last Program Counter (PC) addresses of the thread. This is not necessarily the last PC address of the processor. Similarly, the Stack Pointer (SP) is that of the thread. You can therefore display and change the local variables of the thread.

If you are debugging ARM® code, the ARM-Thumb® Procedure Call Standard (ATPCS) specifies that the first four parameters to a function are passed in registers. In addition, some local variables are optimized into registers by the compiler for parts of the function. Therefore if you modify a local variable that is stored in a register, the debugger modifies the TCB state in order to transfer the value into a processor register instead of modifying the target memory allocated to that variable.

Note

If you are modifying a value that you expect to be shared by several threads, for example a global variable, the compiler might have cached that value in a register for one or more of the threads, and so the modification you desire is not propagated to all of the threads that reference the variable. In order to ensure that such modifications operate correctly, you must either:

  • modify the variable and then, if at the point you have stopped the processor any thread has a cached copy of the variable, modify the copy as well

  • declare the variable to be volatile and recompile the program.

Copyright © 2003, 2004 ARM Limited. All rights reserved.ARM DUI 0234B
Non-Confidential