About LPC2368 Stack Trace
Hi all, I’m working on a project using CrossWork IDE and LPC2368. My program consists of a few functions. When I run the program, it works, but after time unexpectedly sticks somewhere in the functions. Then the program is restarted by the watchdog timer. I want to save the stack just before my program be restarted and then to check the stack to find out where the program actually sticks. I found this post in the Internet http://www.embeddedrelated.com/groups/lpc2000/show/49995.php where it’s described how it can be done. I used this code but I wrote it in C. Here is my code.
void RetAddress(void){
asm(“stmfd sp!, {r5}”); // save r5 in stack
asm(“mov r5, r13”); // move stack pointer to r5
asm(“sub r5, r5, #8”); // adjust r5 to point to return address
int *crash;
asm("mov %0, r5" : "=r" (crash) : );
debug_printf(“%d” ",*crash); //show return address in the output console
}
I tried this:
I call my function RetAddress() in every function of my program and I put a break point at the end of the function RetAddress(). I expected to see the return address when the program stops at the break point. Every time when the program stops at the break point the "crash" points address - something like 0x4000xxxx. I think that this address is an address from the stack. I suppose that the "crash" value should be value of the program counter when the program goes out of the previous function, but the value in this address is very different from the program counter value. Can anybody tell me where I am wrong? Thanks in advance!
Please sign in to leave a comment.
Comments
0 comments