You can use the Debug.where() method to display a backtrace of the functions that have been called. Each entry in the backtrace has its own framenumber which can be supplied to the Debug.locate(framenumber) method. Framenumbers start at zero and are incremented for each function call. So framenumber zero is the current location, framenumber one is the caller of the current location, and so on. For example…
> Debug.where() 0) int debug_printf(const char* fmt=5) C:\svn\shared\target\libc\debug_printf.c:6 1) int main() C:\tmp\try\main.c:17 2) ??? C:\svn\arm\arm\source\crt0.s:237 >
…then…
Debug.locate(1)
…will locate the debugger context at main and…
Debug.locate(0)
…will change the debugger location back to debug_printf.
When the debugger locates (either because locate has been called or it has stopped), the corresponding source line is displayed. You can display source lines around the located line by using the Debug.list(before, after) method, which specifies the number of lines to display before and after the located line.
You can set the debugger to locate (and step) to machine instructions using the method Debug.setmode(mode). Setting the mode to 1 selects interleaved mode (source code interleaved with assembly code). Setting the mode to 2 selects assembly mode (disassembly with source code annotation). Setting the mode to 0 selects source mode. For example:
> Debug.setmode(2) 0000031C E1A0C00D mov r12, sp > Debug.stepinto() 00000320 E92DD800 stmfd sp!, {r11-r12, lr-pc} >Debug.setmode(0) >
You can locate the debugger at a specified program counter by using the Debug.locatepc(pc) method. For example, you can disassemble from specific address:
> Debug.setmode(2) > Debug.locatepc(0x2f4) 000002F4 E59F30D0 ldr r3, [pc, #+0x0D0] > Debug.list(0, 1) 000002F4 E59F30D0 ldr r3, [pc, #+0x0D0] 000002F8 E50B3020 str r3, [r11, #-0x020] >
You can locate the debugger to a full register context using the Debug.locateregisters(registers) method. This method takes an array that specifies each register value, typically in ascending register number order. You can use the Debug.printregisters() method to see the the order. For example, for an ARM7, ARM9, or XScale:
var a = new Array() a[0] = 0 // r0 value ⁞ a[15] = 0x2f4 // pc value a[16] = 0x10 // cspr value Debug.locateregisters(a)
You can put the debugger context back at the stopped state by calling Debug.locate without any parameters:
Debug.locate()