| |||
| Home > Working with the CLI > Source patching with macros > 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:
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 */
}
.
Start a debugging session and set an instruction breakpoint on line 29.
Attach your macro to this breakpoint.
Run the program until execution stops at the breakpoint.
The source statements in your macro are interpreted and executed. The macro completes.
Program execution continues normally.
the following in the RealView Debugger User Guide: