2.3.38. DEFINE

Creates a macro for use by other RealView Debugger components.

Note

Because a macro definition requires multiple lines, you cannot use the DEFINE command from the RealView Debugger command prompt. Instead, you must either:

  • Use the macro command GUI.

  • Write your macro definition in a text file and load it into RealView Debugger using the INCLUDE command.

Syntax

DEFINE [/R] [return_type] macro_name ([parameters]) [parameter_definitions] { macro_body } .

where:

/R

The new macro can replace an existing symbol with the same name.

return_type

Specifies the return type of the macro. If a type is not specified, return_type defaults to type int.

macro_name

Specifies the name of the macro.

parameters

Lists parameters (comma-separated list within parentheses). These parameters can be used throughout the macro definition and are later replaced with the values of the actual parameters in the macro call.

param_definitions

Defines the types of the variables in parameter_list. If types are not specified, the default type int is assumed.

macro_body

Represents the contents of the macro, and is split over many lines. The syntax for macro_body is:

[local_definitions]
macro_statement;[macro_statement;] ...

local_definitions are the variables used within the macro_body.

A macro_statement is any legal C statement except switch and goto statements, or a debugger command. If macro_statement is a debugger command, it must start with a dollar sign ($) and end with a dollar sign and a semicolon ($;). All statements are terminated by a semicolon.

The macro_body ends with a line containing only a period (full stop).

Description

The definition contains a macro name, the parameters passed to the macro, the source lines of the macro, and a terminating period as the first and only character on the last line.

After a macro has been loaded into RealView Debugger, the definition is stored in the symbol table. If the symbol table is recreated, for example when an image is loaded with symbols, any macros are automatically deleted. The number of macros that can be defined is limited only by the available memory on your workstation.

Macros can be invoked by name on the command line where the name does not conflict with other commands or aliases and the return value is not required. You can also invoke a macro on the command line using the MACRO command, and in expressions, for example using the CEXPRESSION command.

Macros can also be invoked as actions associated with:

  • a window, for example VMACRO

  • the GO and GOSTEP commands

  • a breakpoint, for example BREAKEXECUTION

  • deferred commands, for example BGLOBAL.

Note

Macros invoked as associated actions cannot execute GO, or GOSTEP, or any of the stepping commands, for example STEPINSTR.

If you require a breakpoint that, when the condition is met, does something and then continues program execution, you must use the breakpoint continue qualifier, or return 1 from the macro call, instead of the GO command. See the breakpoint command descriptions for more details.

Restrictions on the use of DEFINE

The DEFINE command is not allowed in a macro.

Examples

The following examples show how to use DEFINE:

define float square(f)
 float f;
{
  return (f*f);
}
.

define show_i()
{
  int i;
  i = 10;
  $printf "value of i = %d\n", i$;
  return (1);
}
.

define /R int userPrompt()
{
  char userPromptBuffer[100];
  int retval;
  retval = prompt_text( "Please enter text", userPromptBuffer );
  if (retval == 0) {
    $printf "Clicked OK\n"$;
    $printf "%s\n", userPromptBuffer$;
  } else
    $printf "Clicked Cancel\n"$;
  return 1;
}
.

See also

Copyright © 2002-2011 ARM. All rights reserved.ARM DUI 0175N
Non-ConfidentialID052111