Expert C Programming

(Jeff_L) #1

manpage for each, and try running each on a couple of different a.out's—the "hello world" program,
and a big program.


Go through these carefully—investing 15 minutes now in trying each one will save you hours later in
solving a hard bug.


Table 6-1. Tools to Examine Source
Tool Where to
Find It

What It Does

cb Comes with


the compiler

C program beautifier. Run your source through this filter to put it in a
standard layout and indentation. Comes from Berkeley.

indent Does the same things cb does. Comes from AT & T.


cdecl This book Unscrambles C declarations.


cflow Comes with


the compiler

Prints the caller/callee relationships of a program.

cscope Comes with


the compiler

An interactive ASCII-based C program browser. We use it in the OS


group to check the impact of changes to header files. It provides quick
answers to questions like: "How many commands use libthread?" or "Who
are all the kmem readers?"

ctags /usr/bin Creates a tags file for use in vi editor. A tags file speeds up examining


program source by maintaining a table of where most objects are located.

lint Comes with


the compiler

A C program checker.

sccs /usr/ccs/bin A source code version control system.


vgrind /usr/bin A formatter for printing nice C listings.


Doctors can use x-rays, sonograms, arthroscopes, and exploratory operations to look inside their
patients. These tools are the x-rays of the software world.


Table 6-2. Tools to Examine Executables
Tool Where to
Find It

What It Does

dis /usr/ccs/bin Object code disassembler


dump -


Lv


/usr/ccs/bin Prints dynamic linking information

ldd /usr/bin Prints the dynamic libraries this file needs


nm /usr/ccs/bin Prints the symbol table of an object file


strings /usr/bin Looks at the strings embedded in a binary. Useful for looking at the error


messages a binary can generate, built-in file names, and (sometimes)
symbol names or version and copyright information.

sum /usr/bin Prints checksum and block count for a file. An-swers questions like: "Are


two executables the same version?" "Did the transmission go OK?"

Table 6-3. Tools to Help with Debugging
Free download pdf