Skip to main content

IAR Embedded Workbench for RL78 5.20

Executing a macro by connecting it to a breakpoint

In this section:

You can connect a macro to a breakpoint. The macro will then be executed when the breakpoint is triggered. The advantage is that you can stop the execution at locations of particular interest and perform specific actions there.

Tip

For instance, you can easily produce log reports containing information such as how the values of variables, symbols, or registers change. To do this you might set a breakpoint on a suspicious location and connect a log macro to the breakpoint. After the execution you can study how the values of the registers have changed.

To create a log macro and connect it to a breakpoint:
  1. Assume this skeleton of a C function in your application source code:

    int fact(int x)
    {
     ...
    }
  2. Create a simple log macro function like this example:

    logfact()
    {
     __message "fact(" ,x, ")";
    } 

    The __message statement will log messages to the Debug Log window.

    Save the macro function in a macro file, with the filename extension mac.

  3. To register the macro, choose View>Macros>Macro Registration to open the Macro Registration window and add your macro file to the list. Select the file to register it. Your macro function will appear in the Debugger Macros window.

  4. To set a code breakpoint, click the Toggle Breakpoint button on the first statement within the function fact in your application source code. Choose View>Breakpoints to open the Breakpoints window. Select your breakpoint in the list of breakpoints and choose the Edit command from the context menu.

  5. To connect the log macro function to the breakpoint, type the name of the macro function, logfact(), in the Action field and click OK to close the dialog box.

  6. Execute your application source code. When the breakpoint is triggered, the macro function will be executed. You can see the result in the Debug Log window.

    Note that the expression in the Action field is evaluated only when the breakpoint causes the execution to really stop. If you want to log a value and then automatically continue execution, you can either:

  7. You can easily enhance the log macro function by, for instance, using the __fmessage statement instead, which will print the log information to a file. For information about the __fmessage statement, see Formatted output.

    For an example where a serial port input buffer is simulated using the method of connecting a macro to a breakpoint, see the tutorial Simulating an interrupt in the Information Center.