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 ($). Example 16.1 shows and example.

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. A format specifier can also be included:


decimal format

h or x

hexadecimal format (this is the default).

The syntax for variable substitution is ${variable[:format]}. For example:

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

The filename in this example is myfile1.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 view, 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.

    You can also use the optional format specifier, for example ${addr:d}.

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.


Macros that are not directly invoked from the command line cannot use execution-type commands, such as GO or STEPINSTR.

See also

Copyright © 2002-2009 ARM Limited. All rights reserved.ARM DUI 0153K