10.3.1. Patching example to reset Program Counter

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 incrementing count by 1:

  1. Define a macro containing the 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 (True) 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.

Copyright © 2003, 2004 ARM Limited. All rights reserved.ARM DUI 0234B
Non-Confidential