1.8.3. Patching example to re-implement a loop

The source code being debugged contains the following lines:

24
25 count = 5;
26 for (i=0; i < MAXNUM; i++)
27 {
28      array[i]=1;
29      count=count+2;
30      k=count*i;
31 }
32

To jump over or skip lines 29 and 30, and to insert a new line temporarily, which increments count by 1:

  1. Define a macro that contains statements to increment count and move the PC over the two lines:

    DEFINE patch_29()
    {
        count++;            /* increment count by 1 */
        $SETREG @PC = #31$; /* reset program counter so skipping 29 & 30 */
        return(1);          /* return 1 to continue normal execution */
    }
    .
    
  2. Start a debugging session and set an instruction breakpoint on line 29.

  3. Attach your macro to this breakpoint.

  4. Run the program until execution stops at the breakpoint.

  5. The source statements in your macro are interpreted and executed. The macro completes.

  6. Program execution continues normally.

See also

Copyright © 2002-2011 ARM. All rights reserved.ARM DUI 0175N
Non-ConfidentialID052111