Skip to main content

IAR Embedded Workbench for RH850 3.20.x

Useful breakpoint hints

In this section:

Below are some useful hints related to setting breakpoints.

Bulb.png Tracing incorrect function arguments

If a function with a pointer argument is sometimes incorrectly called with a NULL argument, you might want to debug that behavior. These methods can be useful:

  • Set a breakpoint on the first line of the function with a condition that is true only when the parameter is 0. The breakpoint will then not be triggered until the problematic situation actually occurs. The advantage of this method is that no extra source code is needed. The drawback is that the execution speed might become unacceptably low.

  • You can use the assert macro in your problematic function, for example:

    int MyFunction(int * MyPtr)
    {
      assert(MyPtr != 0); /* Assert macro added to your source code. */
      /* Here comes the rest of your function. */
    }

    The execution will break whenever the condition is true. The advantage is that the execution speed is only slightly affected, but the drawback is that you will get a small extra footprint in your source code. In addition, the only way to get rid of the execution stop is to remove the macro and rebuild your source code.

  • Instead of using the assert macro, you can modify your function like this:

    int MyFunction(int * MyPtr)
    {
      if(MyPtr == 0)
         MyDummyStatement; /* Dummy statement where you set a breakpoint. */
      /* Here comes the rest of your function. */
    }

    You must also set a breakpoint on the extra dummy statement, so that the execution will break whenever the condition is true. The advantage is that the execution speed is only very slightly affected, but the drawback is that you will still get a small extra footprint in your source code. However, in this way you can get rid of the execution stop by just removing the breakpoint.

Bulb.png Performing a task and continuing execution

You can perform a task when a breakpoint is triggered and then automatically continue execution.

You can use the Action text box to associate an action with the breakpoint, for instance a C-SPY macro function. When the breakpoint is triggered and the execution of your application has stopped, the macro function will be executed. In this case, the execution will not continue automatically.

Instead, you can set a condition which returns 0 (false). When the breakpoint is triggered, the condition—which can be a call to a C-SPY macro that performs a task— is evaluated and because it is not true, execution continues.

Consider this example where the C-SPY macro function performs a simple task:

__var my_counter;

count()
{
  my_counter += 1;
  return 0;
}

To use this function as a condition for the breakpoint, type count() in the Expression text box under Conditions. The task will then be performed when the breakpoint is triggered. Because the macro function count returns 0, the condition is false and the execution of the program will resume automatically, without any stop.