Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ (1) — Plan9 4th Edition

Media Vault

Software Library

Restoration Projects

Artifacts Sought

CALLS(1)

NAME

calls − print static call graph of a C program

SYNOPSIS

­calls [ ­−ptv ] [ ­−f ­function ] [ ­−w ­width ...  ] [ ­−D ­def ] [ ­−U ­def ] [ ­−I ­dir ] [ file ...  ]

DESCRIPTION

­Calls reads files, which should be the source of C programs, and writes the analysed calling pattern to standard output. If no file names are given, standard input will be read. ­Calls is intended to help analyse the flow of a program by laying out the functions called in the hierarchical manner used in ­Software Tools by B. Kernighan and P. Plauger. 

All input is first filtered through cpp(1). Functions called but not defined within the source files are shown as:

function ­[external]

Recursive references are shown as:

­<<< function

Options are:

­−f Add ­function as a root of a call graph to be printed. 

­-p Make ­cpp search the APE ­include directories. 

­−t Provides a terse form of output, in which the calling pattern for any function is printed only once on the first occurrence of the function.  Subsequent occurrences output the function name and a notation

...  [see line xx]

This is the default case. 

­−v Full output of function calling patterns on every occurrence. 

−wn Set the output width to n. The default is 80 columns.

−Dname

−Dname=defn
Define the ­name for cpp, as if by #define.  If no definition is given, the name is defined as 1. 

−Uname
Remove any initial definition of name, where ­name is a reserved symbol that is predefined by cpp.

−Idir Change the algorithm for searching for ­#include files whose names do not begin with ­/ to look in ­dir before looking in the directories on the standard list. 

EXAMPLES

What does ­cat call? 

% calls -f main /sys/src/cmd/cat.c
1   main
2       cat
3               read [external]
4               write [external]
5               sysfatal [external]
6       open [external]
7       sysfatal [external]
8       close [external]
9       exits [external]

What internal functions does ­dd call? 

% calls -f main /sys/src/cmd/dd.c | grep -v ’\[external\]’
1   main
5       number
6               <<< number
9       match
17      flsh
21              term
22                      stats
25      term ... [see line 21]
26      stats ... [see line 22]

Note the recursion in number.

Generate the PC kernel’s internal call graph. 

cd /sys/src/9/pc
calls -f main -I../port -I. ../port/∗.c ../ip/∗.c ∗.c |
grep -v external

BUGS

Forward declared functions defined within a function body which are not subsequently used within that function body will be listed as having been called. 

Does not understand calls through function pointers. 

Does not understand the restricted scope of ­static functions. 

Plan 9  —  May 05, 2011

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026