analysis

package
v0.1.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package analysis contains helper functions for running analysis passes.

Index

Constants

PkgLoadMode is the default loading mode in the analyses. We load all possible information

Variables

This section is empty.

Functions

func AllPackages

func AllPackages(funcs map[*ssa.Function]bool) []*ssa.Package

AllPackages returns the slice of all packages the set of functions provided as argument belong to.

func ClosureLocationsStats

func ClosureLocationsStats(log *log.Logger, functions *map[*ssa.Function]bool, withPkgPrefix string)

ClosureLocationsStats logs information about the number of closures in each function in the map, focusing on those functions whose package name starts with interestPrefix

func LoadProgram

func LoadProgram(config *packages.Config,
	platform string,
	buildmode ssa.BuilderMode,
	args []string) (*ssa.Program, error)

LoadProgram loads a program on platform "platform" using the buildmode provided and the args. To understand how to specify the args, look at the documentation of packages.Load.

func RunInterProcedural

func RunInterProcedural(state *dataflow.AnalyzerState, visitor dataflow.Visitor, params InterProceduralParams)

RunInterProcedural runs the inter-procedural analysis pass. It builds args.FlowGraph and populates args.DataFlowCandidates based on additional data from the analysis.

func RunIntraProceduralPass

func RunIntraProceduralPass(state *dataflow.AnalyzerState, numRoutines int, args IntraAnalysisParams)

RunIntraProceduralPass runs an intra-procedural analysis pass of program prog in parallel using numRoutines, using the analyzer state. The args specify the intraprocedural analysis parameters. RunIntraProceduralPass updates the summaries stored in the state's FlowGraph

Types

type ClosureUsageStatistics

type ClosureUsageStatistics struct {
	// AnonsCapturingChannels is the set of anonymous functions capturing channels
	AnonsCapturingChannels map[*ssa.Function]bool
	// TotalAnonCalls is the total number of anonymous functions called
	TotalAnonCalls int
	// TotalAnonFunctions is the total number of anonymous functions defined
	TotalAnonFunctions int
	// TotalMakeClosures is the total number of closure creations
	TotalMakeClosures int
	// ClosuresCalled maps call instructions to the instruction where the closure is created
	ClosuresCalled map[ssa.CallInstruction]ssa.Instruction
	// ClosuresImmediatelyCalled is the set of instructions where a closure is immediately called
	ClosuresImmediatelyCalled map[ssa.Instruction]bool
	// ClosuresNoClass is the set of closures that have not been classified in ClosuresImmediatelyCalled,
	// ClosuresPassedAsArgs or ClosuresReturned
	ClosuresNoClass map[ssa.Instruction]bool
	// ClosuresPassedAsArgs is the set of call instructions where a closure is passed as an argument
	ClosuresPassedAsArgs map[ssa.CallInstruction]ssa.Instruction
	// ClosuresReturned is the set of instructions where a closure is being returned by a function
	ClosuresReturned map[ssa.Instruction]bool
}

ClosureUsageStatistics is a simple record that contains information about usage of closures in a program

func ComputeClosureUsageStats

func ComputeClosureUsageStats(state *dataflow.AnalyzerState) (ClosureUsageStatistics, error)

ComputeClosureUsageStats computes statistics about the usage of closures in the program contained in the state. This requires the pointer analysis to have been computed in the state.

type DeferStat

type DeferStat struct {
	NumDefers    int
	NumRunDefers int
}

DeferStat is a statistic for a single function

type DeferStatsResult

type DeferStatsResult struct {
	NumFunctionsWithDefers  int
	NumDefers               int
	NumRunDefers            int
	FunctionsWithManyDefers map[string]DeferStat
}

DeferStatsResult holds the information gathered by DeferStats on defers

func DeferStats

func DeferStats(functions *map[*ssa.Function]bool) DeferStatsResult

DeferStats logs information about the number of defers in each functions in the map

type InterProceduralParams

type InterProceduralParams struct {
	// IsEntryPoint is a predicate that defines which ssa nodes are entry points of the analysis.
	IsEntrypoint func(ssa.Node) bool
}

InterProceduralParams represents the arguments to RunInterProcedural.

type IntraAnalysisParams

type IntraAnalysisParams struct {
	// ShouldBuildSummary indicates whether the summary should be built when it is created
	ShouldBuildSummary func(*dataflow.AnalyzerState, *ssa.Function) bool

	// IsEntrypoint is a function that returns true if the node should be an entrypoint to the analysis.
	// The entrypoint node is treated as a "source" of data.
	IsEntrypoint func(*config.Config, *pointer.Result, ssa.Node) bool

	// PostBlockCallback will be called each time a block is analyzed if the analysis is running on a single core
	// This is useful for debugging purposes
	PostBlockCallback func(state *dataflow.IntraAnalysisState)
}

IntraAnalysisParams represents the arguments for RunIntraProcedural.

type Result

type Result struct {
	NumberOfFunctions         uint
	NumberOfNonemptyFunctions uint
	NumberOfBlocks            uint
	NumberOfInstructions      uint
}

Result contains the simple statistics returned by running the SSAStatistics function

func SSAStatistics

func SSAStatistics(functions *map[*ssa.Function]bool, exclude []string) Result

SSAStatistics returns a Result with general statistics about the SSA representation of the functions. The exclude parameter is currently ignored.

Directories

Path Synopsis
Package backtrace defines a dataflow analysis that finds all the backwards dataflow paths from an entrypoint.
Package backtrace defines a dataflow analysis that finds all the backwards dataflow paths from an entrypoint.
Package config provides a simple way to manage configuration files.
Package config provides a simple way to manage configuration files.
Package dataflow implements the core of the dataflow analysis.
Package dataflow implements the core of the dataflow analysis.
Package defers implements an analysis that determines which set of defer instructions can reach each program point.
Package defers implements an analysis that determines which set of defer instructions can reach each program point.
Package escape provides an escape analysis which computes a representation of which references in the program are to objects that are local to the current function and goroutine.
Package escape provides an escape analysis which computes a representation of which references in the program are to objects that are local to the current function and goroutine.
Package lang contains functions to help manipulate different objects representing elements of the Go language and the ssa.
Package lang contains functions to help manipulate different objects representing elements of the Go language and the ssa.
Package render provides functions to build a inter-procedural dataflow graph.
Package render provides functions to build a inter-procedural dataflow graph.
Package summaries defines how data flow information can be summarized for a given function.
Package summaries defines how data flow information can be summarized for a given function.
Package taint implements most of the taint analysis functionality.
Package taint implements most of the taint analysis functionality.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL