16.2.3. Using CLI commands in macros

You can define a macro that contains a sequence of debugger CLI commands. When used in this way, each command must be enclosed by dollar signs ($), as shown in Example 16.1.

Example 16.1. Using CLI commands in macros

some_commandsdefine int registers()
  int mIndex;
  for(mIndex = 0; mIndex < 6; mIndex++)
    macro_bin_str[mIndex + 8] = macro_cpsr_mode[mIndex + (6*macro_cpsr_key)];
  macro_bin_str[14] = 0x00;
  $printf "  r0 = 0x%x" ,@r0$;
  $printf "  r1 = 0x%x" ,@r1$;
  $printf "  r2 = 0x%x" ,@r2$;

Macros containing commands are similar to command files and can be used for setting up complex initialization conditions. These macros are executed by entering the macro name and any parameters on the RealView Debugger command line.

Because macros can return a value, they can also be used in expressions.

Using variable substitution in commands within a macro

You can substitute the value of an integer variable in a CLI command before the command is executed. The value is converted to hexadecimal. To do this, you must enclose the variable name between the characters ${ and }, for example:

define /R int tstMacro()
    int num;
    num = 1;
    $FOPEN 150, "C:\\myfiles\\myfile${num}.txt"$; // substitution
    $FPRINTF 150, "Test value: %d", num$;
    $VCLOSE 150$;

The filename in this example is myfile0x1.txt. The text written to the file is "Test value: 1".

Considerations for breakpoint and tracepoint commands

If you want to use breakpoint and tracepoint commands within a macro and use a variable to specify the address, then enclose the variable name between the characters ${ and }. Otherwise, when you view the breakpoint or tracepoint command in the Break/Tracepoints pane, the variable name is shown instead of the address. For example, if addr has the value 0x9000:

  • $breakinstruction addr$;

    This shows the breakpoint command as breakinstruction addr.

  • $breakinstruction ${addr}$;

    This shows the breakpoint command as breakinstruction 0x9000.

Commands prohibited inside a macro

RealView Debugger prohibits the use of the following commands inside a macro:

  • ADD



  • DEFINE (unless it is the macro definition itself)




  • HELP

  • HOST


  • QUIT.

See also

Copyright © 2002-2007 ARM Limited. All rights reserved.ARM DUI 0153I