Creating and running a macro: Difference between revisions

From m204wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__TOC__
__TOC__
<span class="f_Para">A Debugger macro is a workstation text file that contains a list of Client [[intro_configurable_components.html#ui_commands|commands]] to execute (as shown in the [[creating_running_macro.html#macro_example|A macro example]] subsection). This section describes how to create and run a macro.</span>
<span class="f_Para">A Debugger macro is a workstation text file that contains a list of Client [[Introducing the configurable components#Commands|commands]] to execute (as shown in the [[Creating and running a macro#A macro example|A macro example]] subsection). This section describes how to create and run a macro.</span>


<span class="f_Para">You run a macro from the </span><span class="f_ListBul2">[[macros_menu.html|Macros menu]],</span><span class="f_Para"> from a Client button or hot key to which you have [[map_macro_to_button.html|assigned]] a macro, or from the [[using_macro_console_cmdline.html#macro_command_line|command line]].  You can also run a macro automatically: </span>
<span class="f_Para">You run a macro from the </span><span class="f_ListBul2">[[Macros menu options|Macros menu]],</span><span class="f_Para"> from a Client button or hot key to which you have [[Mapping a macro to a button or hot key|assigned]] a macro, or from the [[Using the console and command line#The Command Line|command line]].  You can also run a macro automatically: </span>


*If the macro name matches that of an included procedure (and the macro autorun [[file_menu_opts.html#preferences|preference]] has been selected).</span>
*If the macro name matches that of an included procedure (and the macro autorun [[File menu options#Preferences|preference]] has been selected).</span>
*At Client startup, if the macro is specified on the </span><span class="f_CodeExList">startUpMacro=&quot;</span><span class="f_CodeExampleItalic">macroname</span><span class="f_CodeExList">&quot;</span><span class="f_ListBul1">  attribute of the </span><span class="f_CodeExList">&lt;mappings&gt;</span><span class="f_ListBul1"> tag in the [[setup_ui_xml_file.html#startupmacro_att|UI customization file]] </span><span class="f_Monospace">(ui.xml/uiMore.xml)</span><span class="f_Para">.</span><span class="f_Monospace"> </span>
*At Client startup, if the macro is specified on the </span><span class="f_CodeExList">startUpMacro=&quot;</span><span class="term">macroname</span><span class="f_CodeExList">&quot;</span><span class="f_ListBul1">  attribute of the </span><span class="f_CodeExList">&lt;mappings&gt;</span><span class="f_ListBul1"> tag in the [[Setting up the ui.xml file|UI customization file]] </span><span class="term">(ui.xml/uiMore.xml)</span><span class="f_Para">.</span><span class="f_Monospace"> </span>


=== Macro definition  ===
=== Macro definition  ===
Line 11: Line 11:
<span class="f_Para">To define a new macro: </span>
<span class="f_Para">To define a new macro: </span>


1. Start a text file by doing either of these:  
: 1. Start a text file by doing either of these:  
*From the Client's </span><var>File</var><span class="f_ListBul2"> menu, select </span><span class="term">New Blank Macro.</span><span class="f_ListBul2"> </span>
* From the Client's </span><var>File</var><span class="f_ListBul2"> menu, select </span><span class="term">New Blank Macro.</span><span class="f_ListBul2"> </span>
: The &quot;Select name for a new macro&quot; Windows dialog box opens, from which you select where to locate and what to name the macro file.  
:: The &quot;Select name for a new macro&quot; Windows dialog box opens, from which you select where to locate and what to name the macro file.  
: Macro files must have a <var>.macro</var> file extension, and the file name must not contain embedded blanks.  
:: Macro files must have a <var>.macro</var> file extension, and the file name must not contain embedded blanks.  
: When you click the <var>Save</var> button, the macro file opens in </span><var>Notepad.</var>
:: When you click the <var>Save</var> button, the macro file opens in </span><var>Notepad.</var>


[[File:macronotea_zoom50.gif|246x116px|macroNotea]]<span class="f_ListContinue2"> </span>
[[File:macronotea_zoom50.gif|246x116px|macroNotea]]<span class="f_ListContinue2"> </span>


*Alternatively, create a new file in a Windows text editor like </span><var>Notepad.</var><span class="f_ListBul2"> </span>
* Alternatively, create a new file in a Windows text editor like </span><var>Notepad.</var><span class="f_ListBul2"> </span>
: When you later name and save this file after defining its contents, you must specify a <var>.macro</var> file extension and make sure the file name contains no embedded blanks.  
:: When you later name and save this file after defining its contents, you must specify a <var>.macro</var> file extension and make sure the file name contains no embedded blanks.  


'''Note:''' If you decide to store the file in a location other than the Client installation folder, see [[change_location_client_work.html|Changing the location of Client work files.]]
'''Note:''' If you decide to store the file in a location other than the Client installation folder, see [[Changing the location of Client work files|Changing the location of Client work files.]]


2. In the text file, specify the Debugger commands you want to be run consecutively.
: 2. In the text file, specify the Debugger commands you want to be run consecutively.
: These are the formatting guidelines:  
:: These are the formatting guidelines:  
*Specify one command (case does not matter) per line; leading spaces and blank lines are ignored; line can be indefinitely long.  
* Specify one command (case does not matter) per line; leading spaces and blank lines are ignored; line can be indefinitely long.  
*Any line that begins with a number sign (#) is treated as a comment.  
* Any line that begins with a number sign (#) is treated as a comment.  
*Several commands require arguments; specify arguments or [[passing_arguments_to_macros.html|argument variables]] after the command keyword separated by at least one blank. For example:  
* Several commands require arguments; specify arguments or [[Passing a command argument to a macro|argument variables]] after the command keyword separated by at least one blank. For example:  


<p class="syntax"><span class="f_CodeExList">addWatch %i</span><span class="f_CodeExList2"> </span>
<p class="syntax"><span class="f_CodeExList">addWatch %i</span><span class="f_CodeExList2"> </span>
<span class="f_CodeExList2">searchFromTop   </span><span class="f_CodeExample">image foo</span><span class="f_CodeExList2"> </span>
<span class="f_CodeExList2">searchFromTop   </span><span class="f_CodeExample">image foo</span><span class="f_CodeExList2"> </span>
<span class="f_CodeExList2">runUntil daemonnest </span></p>
<span class="f_CodeExList2">runUntil daemonnest </span></p>
*<span class="f_ListContinue2">Separate multiple command arguments by one or more blanks. For example: </span>
* <span class="f_ListContinue2">Separate multiple command arguments by one or more blanks. For example: </span>
<p class="syntax"><span class="f_CodeExList2">traceUntilVariableEqualsValue %i 3  </span></p>
<p class="syntax"><span class="f_CodeExList2">traceUntilVariableEqualsValue %i 3  </span></p>


*For a macro to run another macro, specify either of the following:  
* For a macro to run another macro, specify either of the following:  


<p class="syntax"><span class="f_CodeExList2">include </span><span class="term">macroName</span><span class="f_CodeExList2"> </span>
<p class="syntax"><span class="f_CodeExList2">include </span><span class="term">macroName</span><span class="f_CodeExList2"> </span>
Line 45: Line 45:
<span class="f_CodeExList2">include foo </span></p>
<span class="f_CodeExList2">include foo </span></p>


3. Save and exit the macro file.
: 3. Save and exit the macro file.
: You can easily access this file for editing by selecting the <span class="term">Edit Macro</span><span class="f_ListContinue"> option from the </span><var>Macros</var><span class="f_ListContinue"> menu. </span>
:: You can easily access this file for editing by selecting the <span class="term">Edit Macro</span><span class="f_ListContinue"> option from the </span><var>Macros</var><span class="f_ListContinue"> menu. </span>


4. Consider opening [[Using the console and command line#The Console|the macro console]] (from the </span><var>Macros</var><span class="f_ListBul2"> menu)</span><span class="f_ListNum1"> to </span><span class="f_Para">display information about the macros you run.  
: 4. Consider opening [[Using the console and command line#The Console|the macro console]] (from the </span><var>Macros</var><span class="f_ListBul2"> menu)</span><span class="f_ListNum1"> to </span><span class="f_Para">display information about the macros you run.  
: <span class="f_ListContinue">The console reports the starting and completing of the macro execution, as well as any error messages.</span>
:: <span class="f_ListContinue">The console reports the starting and completing of the macro execution, as well as any error messages.</span>


5. Invoke the macro.  
: 5. Invoke the macro.  
: Use any of the following ways to run a macro:  
:: Use any of the following ways to run a macro:  
*From the </span><var>Macros</var><span class="f_ListBul2"> menu, select the </span><var>Run Macro</var><span class="f_ListBul2"> option. </span>
* From the </span><var>Macros</var><span class="f_ListBul2"> menu, select the </span><var>Run Macro</var><span class="f_ListBul2"> option. </span>
*From the </span><var>Macros</var><span class="f_ListBul2"> menu, select the </span><var>Command Line</var><span class="f_ListBul2"> option. </span>
* From the </span><var>Macros</var><span class="f_ListBul2"> menu, select the </span><var>Command Line</var><span class="f_ListBul2"> option. </span>
*Use a button or hot key combination to which you have [[map_macro_to_button.html|mapped the macro.]] </span>
* Use a button or hot key combination to which you have [[Mapping a macro to a button or hot key|mapped the macro.]] </span>
*Specify the macro name as the value of the </span><span class="f_CodeExList">[[Setting up the ui.xml file#To set up a ui.xml file:|startUpMacro]]</span><span class="f_ListBul2"> attribute in the Client's </span><var>ui.xml</var><span class="f_ListBul2"> file, or as the value of the </span><span class="term">startup</span><span class="f_ListBul2"> attribute in the Client's </span><span class="term">debuggerConfig.xml</span><span class="f_ListBul2"> file. </span>
* Specify the macro name as the value of the </span><span class="f_CodeExList">[[Setting up the ui.xml file#To set up a ui.xml file:|startUpMacro]]</span><span class="f_ListBul2"> attribute in the Client's </span><var>ui.xml</var><span class="f_ListBul2"> file, or as the value of the </span><span class="term">startup</span><span class="f_ListBul2"> attribute in the Client's </span><span class="term">debuggerConfig.xml</span><span class="f_ListBul2"> file. </span>


: <span class="f_ListContinue">The title bar of the main Client window indicates that the macro is executing: </span>
: <span class="f_ListContinue">The title bar of the main Client window indicates that the macro is executing: </span>
Line 135: Line 135:
*&quot;Macro Alpha calls macro Beta which calls macro Alpha&quot; (indirect recursion)  
*&quot;Macro Alpha calls macro Beta which calls macro Alpha&quot; (indirect recursion)  


<span class="f_Para">In either case, when a recursive call is detected, the macro is terminated and a message is displayed in the [[glance_at_status_area.html|Status bar]]. </span>
<span class="f_Para">In either case, when a recursive call is detected, the macro is terminated and a message is displayed in the [[Status bar|Status bar]]. </span>


[[Category:Debugger Home]]
[[Category:Debugger Home]]

Revision as of 01:23, 19 December 2022

A Debugger macro is a workstation text file that contains a list of Client commands to execute (as shown in the A macro example subsection). This section describes how to create and run a macro.

You run a macro from the Macros menu, from a Client button or hot key to which you have assigned a macro, or from the command line.  You can also run a macro automatically:

  • If the macro name matches that of an included procedure (and the macro autorun preference has been selected).
  • At Client startup, if the macro is specified on the startUpMacro="macroname"  attribute of the <mappings> tag in the UI customization file (ui.xml/uiMore.xml).

Macro definition 

To define a new macro:

1. Start a text file by doing either of these:
  • From the Client's File menu, select New Blank Macro.
The "Select name for a new macro" Windows dialog box opens, from which you select where to locate and what to name the macro file.
Macro files must have a .macro file extension, and the file name must not contain embedded blanks.
When you click the Save button, the macro file opens in Notepad.

macroNotea

  • Alternatively, create a new file in a Windows text editor like Notepad.
When you later name and save this file after defining its contents, you must specify a .macro file extension and make sure the file name contains no embedded blanks.

Note: If you decide to store the file in a location other than the Client installation folder, see Changing the location of Client work files.

2. In the text file, specify the Debugger commands you want to be run consecutively.
These are the formatting guidelines:
  • Specify one command (case does not matter) per line; leading spaces and blank lines are ignored; line can be indefinitely long.
  • Any line that begins with a number sign (#) is treated as a comment.  
  • Several commands require arguments; specify arguments or argument variables after the command keyword separated by at least one blank. For example:  

addWatch %i  searchFromTop   image foo  runUntil daemonnest 

  • Separate multiple command arguments by one or more blanks. For example:

traceUntilVariableEqualsValue %i 3  

  • For a macro to run another macro, specify either of the following:

include macroName  macro macroName 

Specifying the extension .macro after the macro name is optional. The following commands are equivalent:

include foo.macro include foo 

3. Save and exit the macro file.
You can easily access this file for editing by selecting the Edit Macro option from the Macros menu.
4. Consider opening the macro console (from the Macros menu) to display information about the macros you run.
The console reports the starting and completing of the macro execution, as well as any error messages.
5. Invoke the macro.
Use any of the following ways to run a macro:
  • From the Macros menu, select the Run Macro option.
  • From the Macros menu, select the Command Line option.
  • Use a button or hot key combination to which you have mapped the macro.
  • Specify the macro name as the value of the startUpMacro attribute in the Client's ui.xml file, or as the value of the startup attribute in the Client's debuggerConfig.xml file.
The title bar of the main Client window indicates that the macro is executing:

. . . macro running 

Potential errors include: an invalid macro command, trying to invoke a macro that does not exist, and violating the context and recursion restrictions.
If you want to stop a macro at any time it is running or in a not-completed state awaiting further input, select the Kill Running Macro option from the Macros menu.

Note: A macro runs until it has exhausted all its commands or encounters a kill command. If a request completes before the macro is finished, the remaining commands in the macro apply to the next request in the session. If you want to prevent these commands from being applied to the next request, use the Kill Running Macro option or the noSpan command.

A macro example

The following sample macro prepares a particular program (shown below the macro) for further debugging:

# Remove any existing breakpoints or watches  clearWatch  clearBreaks     # Set breakpoint on the first line we # want to examine top  breaksAt For 1 record   # watch some variables we are interested in  addWatch %i   addWatch %what     # Run to the breakpoint we set    run 

The sample macro above was designed for a program like this:

begin     %i is float     %what is string len 30     *BREAK      %i = 1      * this should not be recognized as a *break     for 1 record        *breaks        %i = %i + 1        %what = $sirtime       change testfield to %what     end for     *break      %i = %i + 1     assert %i = 3     trace 'hello ....'     *break     audit 'Hey moe...'     print $sirtime     print %i   end   

Macro usage restrictions 

These are the context and calling restrictions you must observe when using macros:

Context restrictions

Some of the commands that may appear in a macro are valid only when you are interactively running a program under the Debugger. If a macro attempts to execute one of these commands when no program code is ready or remains to execute, the macro is terminated, and the following message is displayed in the Client's Status bar:

Invalid context for: Offending command 

The following types of commands are allowed only when executing a program:

  • All run commands
  • All cancel commands
  • All step commands
  • All watch commands
  • All breakpoint commands
  • All trace commands

Similarly, the following commands are allowed only after a program fails to compile. If these commands are issued when there is no compilation error, the Client issues the "Invalid context" message described above:

  • nextCompileError
  • previousCompileError

Recursion restriction

Macros may not be recursively called, either directly or indirectly. These sequences are not allowed:

  • "Macro Alpha calls macro Alpha" (direct recursion)
  • "Macro Alpha calls macro Beta which calls macro Alpha" (indirect recursion)

In either case, when a recursive call is detected, the macro is terminated and a message is displayed in the Status bar.