ARM Technical Support Knowledge Articles

DETECT OVERWRITES ON LOCAL VARIABLES

Applies to: ARM Development Tools

Answer


Information in this article applies to:


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 uVision 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

Article last edited on: 2006-12-12 09:24:53

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential