Package callgraph defines the call graph and various algorithms and utilities to operate on it.
A call graph is a labelled directed graph whose nodes represent functions and whose edge labels represent syntactic function call sites. The presence of a labelled edge (caller, site, callee) indicates that caller may call callee at the specified call site.
A call graph is a multigraph: it may contain multiple edges (caller, *, callee) connecting the same pair of nodes, so long as the edges differ by label; this occurs when one function calls another function from multiple call sites. Also, it may contain multiple edges (caller, site, *) that differ only by callee; this indicates a polymorphic call.
A SOUND call graph is one that overapproximates the dynamic calling behaviors of the program in all possible executions. One call graph is more PRECISE than another if it is a smaller overapproximation of the dynamic behavior.
All call graphs have a synthetic root node which is responsible for calling main() and init().
Calls to built-in functions (e.g. panic, println) are not represented in the call graph; they are treated like built-in operators of the language.
- func AddEdge(caller *Node, site ssa.CallInstruction, callee *Node)
- func CalleesOf(caller *Node) map[*Node]bool
- func GraphVisitEdges(g *Graph, edge func(*Edge) error) error
- type Edge
- func PathSearch(start *Node, isEnd func(*Node) bool) *Edge
- func (e Edge) Description() string
- func (e Edge) Pos() token.Pos
- func (e Edge) String() string
- type Graph
- func New(root *ssa.Function) *Graph
- func (g *Graph) CreateNode(fn *ssa.Function) *Node
- func (g *Graph) DeleteNode(n *Node)
- func (g *Graph) DeleteSyntheticNodes()
- type Node
Package Files ¶
func AddEdge ¶
AddEdge adds the edge (caller, site, callee) to the call graph. Elimination of duplicate edges is the caller's responsibility.
func CalleesOf ¶
CalleesOf returns a new set containing all direct callees of the caller node.
func GraphVisitEdges ¶
GraphVisitEdges visits all the edges in graph g in depth-first order. The edge function is called for each edge in postorder. If it returns non-nil, visitation stops and GraphVisitEdges returns that value.
type Edge ¶
A Edge represents an edge in the call graph.
Site is nil for edges originating in synthetic or intrinsic functions, e.g. reflect.Value.Call or the root of the call graph.
func PathSearch ¶
PathSearch finds an arbitrary path starting at node start and ending at some node for which isEnd() returns true. On success, PathSearch returns the path as an ordered list of edges; on failure, it returns nil.
func (Edge) Description ¶
func (Edge) Pos ¶
func (Edge) String ¶
type Graph ¶
A Graph represents a call graph.
A graph may contain nodes that are not reachable from the root. If the call graph is sound, such nodes indicate unreachable functions.
func New ¶
New returns a new Graph with the specified root node.
func (*Graph) CreateNode ¶
CreateNode returns the Node for fn, creating it if not present.
func (*Graph) DeleteNode ¶
DeleteNode removes node n and its edges from the graph g. (NB: not efficient for batch deletion.)
func (*Graph) DeleteSyntheticNodes ¶
func (g *Graph) DeleteSyntheticNodes()
DeleteSyntheticNodes removes from call graph g all nodes for synthetic functions (except g.Root and package initializers), preserving the topology. In effect, calls to synthetic wrappers are "inlined".
type Node ¶
A Node represents a node in a call graph.
func (*Node) String ¶
|go/callgraph/cha||Package cha computes the call graph of a Go program using the Class Hierarchy Analysis (CHA) algorithm.|
|go/callgraph/rta||This package provides Rapid Type Analysis (RTA) for Go, a fast algorithm for call graph construction and discovery of reachable code (and hence dead code) and runtime types.|
|go/callgraph/static||Package static computes the call graph of a Go program containing only static call edges.|
Version v0.1.8 (latest) | Published Dec 2, 2021 | Platform: linux/amd64 | Updated 3 weeks agoTools for package owners.