1.4.3 Debugging


Debugging in Code Builder

Code Builder has features that allow you to debug your Origin C and LabTalk code. You can set and remove breakpoints, step through your code one statement at a time, step into and out of functions, and monitor the values of variables. Debugging is turned on by default. You can turn debugging on or off using the Enable Breakpoints item on the Debug menu. If there is a check mark next to the item then debugging is turned on.

When debugging Origin C code, you can hover on a variable name with your mouse to see a tooltip with the variable's current value.

When a variable has a more complex structure, the tooltip can display a tree-like structure. To disable tree display, add the following to OIDEOptions.ini:

[Environment]
bTreeLikeDataTip=0

Macros for Debugging

Origin C allows users to define multi-parameter macros which have many uses. Many programmers use output statements while developing code to indicate program flow and display the values of variables at key moments.

Create an Output Macro

A convenient debugging technique is to define an output macro and then place that macro throughout your code as shown below.

#define    DBG_OUT(_text, _value)     out_int(_text, _value);
 
void DebugStatements()
{
     int ii;
     DBG_OUT("ii at t0 = ", ii)
     ii++;
     DBG_OUT("ii at t1 = ", ii)
     ii++;
     DBG_OUT("ii at t2 = ", ii)
     ii++;
     DBG_OUT("ii at t3 = ", ii)
     printf("Finished running DebugMacros.");
}

Comment the Debug Macro Body

During the development cycle the body of the macro can remain defined as above causing the desired debug messages to be shown on the message box. However, once development is complete (or at least stable) the macro can be redefined as below causing the debug statements to disappear.

#define    DBG_OUT(_text, _value)   //  out_int(_text, _value);

Commenting out the body of the DBG_OUT macro (and rebuilding) causes the debug statements to disappear without having to remove the many possible instances of its use, saving them for possible reuse in the future. Should the code ever need to be modified or debugged again the body of the macro can simply be uncommented.