10.3. Source patching with macros

When debugging your application program, errors can sometimes 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 breakpoint macros.

To insert a few lines of source code in your program:

  1. Define a macro containing the statements that you want to insert.

  2. Start a debugging session and set a breakpoint on the source line following the point where you want to insert the new lines.

  3. Attach your macro to this breakpoint, see Attaching macros to breakpoints for details explaining how to do this.

  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.

Note

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:

  1. Define a macro to set the PC to a point beyond the lines that are not executed.

  2. Start a debugging session and set a breakpoint on the first line to be skipped.

  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 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 10.1. 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:

Example 10.1. Using the JUMP command

add int cnt = 20
initialise
:repeat                             /* loop 20 times */ 
some_commands
jump repeat,cnt                    /* repeat until cnt==0 */
;
; define some local vars if not defined.
;
jump nodefine,isalive(cnt)==1
some_commands
:nodefine

For more information on the JUMP and ADD commands, see the chapter describing commands in RealView Developer Kit v1.0 Debugger Command Line Reference Guide.

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