Keil Logo

ARM: DETECT OVERWRITES ON LOCAL VARIABLES


Information in this article applies to:

  • Keil Development Tools for ARM

QUESTION

I have a Problem in my application: a local variable gets overwritten. How can I analyze the reason for this error.

The simplified code looks as shown below:

func1 ()  {
  int var;   // this variable is in R6
  :
  func2 ();  // after call of func2 var is destroyed
  :
}

I have analyzed func2 () and all registers are correctly saved by a PUSH instruction:

STMDB     R13!,{R4-R7,R14}

Even the end of func2 () looks OK and uses the corresponding POP instruction:

LDMIA     R13!,{R4-R7,PC}

The function func2 () is pretty complex and calls several other functions. It looks to me as the stack area gets overwritten during function execution.

Is there a way to track this problem?

ANSWER

Yes, the µVision Debugger supports access breakpoints with the simulator and the ULINK USB JTAG Adapter. You may use this feature to set a breakpoint at the memory address that saves the content or R6. This can be done by the following procedure:

  1. Step into the function func2 ().
  2. Use View - Memory Window and enter as address SP-100. Use the context menu in the memory window and select unsigned int as display format. You should now see the value of var as it is saved on the stack.
  3. The memory window should now show the value of var as it is saved on the stack. Determine the memory address (we assume 0x40001000 for this example).
  4. Open the dialog Debug - Breakpoints and define an access breakpoint with:
    Expression: 0x40001000
    Access: Write
    Size: 4 Bytes
    
  5. When you now run your application, the debugger will stop on the instruction that overwrites the stack location.

Note: when you are working with ULINK you can only set a single access breakpoint. Due to ARM Embedded ICE restrictions it is not possible to set other breakpoints in Flash.

MORE INFORMATION

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Tuesday, December 12, 2006


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.