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

  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 Chapter 2 RealView Debugger Commands for details explaining how to do this using the breakpoint commands. Alternatively, see the RealView Debugger v1.8 User Guide for details explaining how to do this in the GUI.

  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 1.5. 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 1.5. Using the JUMP command

add int cnt = 20
initialize 
: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 ADD and JUMP commands, see ADD on ADD and JUMP on JUMP.

Copyright © 2002-2005 ARM Limited. All rights reserved.ARM DUI 0175G
Non-Confidential