User`s manual

Dynamic C Users Manual digi.com 93
6.3 Debugging Tools
This section describes the different tools available for debugging, including their pros and cons, as well as
when you might want to use them, how to use them and an example of using them. The examples are sug-
gestions and are not meant to be restrictive. While there may be some collaboration, bug hunting is largely
a solitary sport, with different people using different tools and methods to solve the same problem.
6.3.1 printf()
The printf() function has always been available in Dynamic C, with output going to the Stdio window
by default, and optionally to a file (by configuring the Stdio window contents to log to a file). The ability
to redirect output to any one of the serial ports A, B, C or D was introduced in Dynamic C 7.25. In DC
8.51, serial ports E and F were added for the Rabbit 3000. See Samples\stdio_serial.c for
instructions on how to use the serial port redirect. This feature is intended for debug purposes only.
The syntax for printf() is explained in detail in the Dynamic C Function Reference Manual, including
a listing of allowable conversion characters.
Pros A printf() statement is quick, easy and sometimes all that is needed to nail
down a problem.
You can use #ifdef directives to create levels of debugging information that
can be conditionally compiled using macro definitions. This is a technique used
by Rabbit engineers when developing Dynamic C libraries. In the library code
you will see statements such as:
#ifdef LIBNAME_DEBUG
printf(“Insert information here.\n”);
...
#endif
...
#ifdef LIBNAME_VERBOSE
printf(“Insert more information.\n”);
...
#endif
By defining the above mentioned macro(s) you include the corresponding printf
statements.
Cons The printf() function is so easy to use, it is easy to overuse. This can lead to
a shortage of root memory. A solution to this that allows you to still have lots of
printf strings is to place the strings in extended memory (xmem) using the key-
word xdata and then call printf() with the conversion character “%ls.” An
overuse of printf statements can also affect execution time.
Uses Use to check a program’s flow without stopping its execution.