Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous contents
Next: Some Common mistakes Up: Debugging Previous: Debugging   Contents

Utilities and routines

Some compilers have flags to turn on extra checking. gcc for example has a -Wall option which gives a list of suspicious constructions as well as the usual compile errors.

There are also routines that are useful

If using these fail, try some of the following. If your machine's lacking any of these programs, look for public domain versions.

lint :-
is a program which gives the sort of warning messages about `unused variables' and `wrong number of arguments' that non-C compilers usually give. lint takes most of the same arguments as the compiler. It needs special libraries which are already provided.

cflow :-
To show which functions call which, use cflow. This produces an indented output which also gives an idea of function call nesting. An ansi-ized, much enhanced version is available by ftp from sunsite.unc.edu:/pub/linux/devel/C

cb :-
To standardise the indentation of your program, send it through cb, a C beautifier;
  cb ugly.c > lovely.c

cxrefs :-
tells you where variables and functions are mentioned. It's especially useful with multi-file sources.

adb :-
I only use adb to see why a core dump happened. If `myprog' causes a core dump then
   adb myprog
   $c
will show you what function's return addresses were on the stack when the crash happened, and what hex arguments they were called with. Quit using $q

Symbolic Debuggers :-
dbx, xdb, or gdb may be available to you. They are symbolic source-level debuggers under which you can run a program in trace mode allowing you to use breakpoints, query values, etc. To use this you will have to first compile your program with the -g flag.

cdecl :-
This program can help with C declarations. See man page for details. Some examples:-
unix: cdecl declare fptab as array of pointer to function returning int
int (*fptab[])()
unix:   cdecl explain int '(*fptab[])()' 
declare fptab as array of pointer to function returning int

cdecl is available from archives in comp.sources.unix/volume6.

array bounds :-
If you're using gcc there's a patch that lets you check whether you're going off the end of an array.


next up previous contents
Next: Some Common mistakes Up: Debugging Previous: Debugging   Contents
Tim Love 2010-04-27