Chapter 6: Using Macros and Command Files
Using Macros
•
Example
If you have the following macro definition:
Debugger Macro Add int ten_to_the(y)
int
{
.
the macro will compute 10**y by calling the previously defined macro power().
To call a macro on execution of a breakpoint
• Select Attach Macro from the Code window pop-up menu.
Or:
• When using the command line to set a breakpoint, add a semicolon (;) and the
name of the macro to the command.
When setting breakpoints, you can attach a macro to the breakpoint.
Whenever the breakpoint is encountered, the macro is executed. Depending
on the return value of the macro, program execution will either stop or
continue.
•
•
Macros attached to breakpoints can test program or user-defined variables
before determining whether execution should break or not (by returning zero
or nonzero values, respectively).
Macro control flow statements within a breakpoint macro can alter execution
flow in the target environment based on target or debugger variable values.
You can also include C expressions in macros. By using control flow
statements and C expressions in macros, you can patch your C programs.
198
The macro cannot call itself.
y;
return power(10,y); }
If the macro returns zero, program execution stops at the breakpoint.
If the macro returns a nonzero value, program execution continues at the
breakpoint.