HPlogo HP/DDE Debugger User's Guide: HP 9000 Series 700/800 Computers > Chapter 5 Using Debugger Commands

Creating Alias and Define Macros

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Glossary

 » Index

You can use the alias and define commands to create two types of macros:

  • An alias macro serves as a synonym for one or more debugger commands. The debugger expands alias macros only when the macro is at the beginning of a command line, or when the macro follows a semicolon in a line of commands.

  • A define macro serves as a synonym for any string of text, including debugger commands. The debugger always expands a define macro no matter what position the macro occupies in a command line.

For example, consider the following series of commands:

alias show print alias ali_X total
define def_X total
show ali_X
"ali_X" not found in current environment.
show def_X
total: 20

The alias commands create show as a synonym for the print command, and ali_X as a synonym for the variable total. The define command also creates a synonym for total, but gives it the name def_X.

The debugger does not expand ali_X in the command show ali_X since ali_X does not appear at the beginning of the line and it does not follow a semicolon. However, the debugger does expand def_X since define macros can appear anywhere on the command line. Also, since the alias show appears first in both of the last two command lines, the debugger expands show in both cases.

The debugger expands macros from left to right in the command line. Upon finding a macro with arguments, the debugger inserts the arguments into the macro definition. Then the debugger rescans the command line, starting from where it found the macro.

You can define macros in terms of other macros and nest them. Note that macros cannot be recursive.

Macro names may begin with a letter, a grave (`) accent, a hyphen (-) or an underscore (_). Macros accept parameters and are defined like C language macros. See the descriptions of the alias and define commands in the online command reference for syntax details.

You must delimit a macro name in a command string with characters not allowed in a macro name, such as the space character. For example:

define X len

Defines macro X as len.

print X

Expands to print len.

print myX

Does not expand because the debugger does not treat the letter y as a delimiter.

Start a macro name with a grave accent (`) to form a macro that can concatenate its text with other strings. For example:

define `X len

Defines macro `X as len.

print `X

Expands to print len.

print my`X

Expands to print mylen.

Like arguments to debugger commands, macros are case-sensitive. You can list alias macros using the list aliases command; use list defines to list define macros.

You can specify any string as the value for an actual parameter. The debugger recognizes any string within matching brackets [], braces `{}'', or parentheses () as a single argument. However, bracket pairs within the string are treated in a special manner, and quotation marks are treated as part of the string. The outermost brackets (within the parentheses that delimit the argument) must balance; brackets, characters, and punctuation marks within the outermost brackets are considered part of the argument.

A period (.) preceding a command string prevents the debugger from trying to expand the string in an alias or define macro. For example, using the period can prevent infinite looping in the following alias:

alias s[tep] .step -ignore

Without the period, when the debugger encounters the step command string, it would continue to apply the alias definition indefinitely.