# Avoiding The Needless Multiplication Of Forms

Dr Andrew Moss

2020-11-19

## Call path grep

Reviewing pieces of code requires an understanding of both details and context. We need to understand what the code does - but also we need to know when that happens, and what is being operated on. This typically means tracing the call paths to find out where functions are called from. Sometimes we do it the other way around and chase the calls that a piece of code makes to find out what they do.
Normally I would do this with grep so I have some basic functions defined in my shell:

## Limitations

The backtracking search is not particularly efficient. This is because the constant factors are quite low so it is not worth the effort to optimize (typically this would mean performing the NFA to DFA construction to compile state tracking information into the search instead). But the ratio between CPU speed and callgraph size on a modern machine is high enough that the tool is instanteous on my use-cases so it is not interesting to optimize.
The call-graph that LLVM generates is the statically defined call-graph for the program so it misses many call paths. Any program that uses callbacks (or other dynamic despatch constructs) will have call sequences that are not found. Using "The Trick" to specialize this for small sets of possible targets is the subject of the next part...