| |||
| Home > Working with the CLI > Source patching with macros | |||
When debugging your application program, sometimes errors can be temporarily patched with source statements. It is often unnecessary to edit the source code, and recompile and link. Instead, you can use a temporary patch by using macros with breakpoints.
To insert a few lines of source code in your program:
Define a macro containing the statements that you want to insert.
Start a debugging session and set a breakpoint on the source line following the point where you want to insert the new lines.
Attach your macro to this breakpoint. See Chapter 2 RealView Debugger Commands for details explaining how to do this using the breakpoint commands. Alternatively, see the RealView Debugger v3.0 User Guide for details explaining how to do this in the GUI.
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.
Using a macro in this way might cause problems with compiler optimizations, for example the ordering of instructions might have been altered by the compiler.
You can also use a similar approach to jump over or skip lines of source code:
Define a macro to set the PC to a point beyond the lines that are not executed.
Start a debugging session and set a breakpoint on the first line to be skipped.
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 from the new position of the PC.
You can also use the JUMP command for looping and skipping over commands, shown in the fragment in Example 1.6. The JUMP command takes a label and an expression. If the expression evaluates to True then control jumps to the specified label. If the label is positioned earlier in the file, this loops. If the label is positioned later in the file, all intermediate commands are skipped.
The expression can test:
symbols, using the isalive() keyword
(see isalive on isalive)
results
local symbols, created with ADD
file tests, using macros.
Example 1.6. Using the JUMP command
add int cnt = 20initialize:repeat /* loop 20 times */some_commandsjump repeat,cnt /* repeat until cnt==0 */ ; ; define some local vars if not defined. ; jump nodefine,isalive(cnt)==1some_commands:nodefine
For more information on the ADD and JUMP commands, see ADD on ADD and JUMP on JUMP.