analysis

package
v0.3.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 12, 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

View Source
const Version = "v0.3.0"

Version is the last tagged version of the analysis tool

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 LoadAnalyzerState

func LoadAnalyzerState(options LoadProgramOptions,
	args []string, cfg *config.Config) (*dataflow.AnalyzerState, error)

LoadAnalyzerState is like LoadProgram but additionally wraps the loaded program in a simple analyzer state. Does not run pointer analysis for example.

func LoadProgram

func LoadProgram(options LoadProgramOptions, args []string) (*ssa.Program, []*packages.Package, 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, spec dataflow.ScanningSpec)

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 IntraAnalysisParams

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

	// ShouldTrack is a function that returns true if the node should be an entrypoint to the analysis.
	// The node may be an entrypoint or an endpoint of an analysis.
	// In particular, ShouldTrack identifies the special nodes that must be tracked but are not callgraph
	// related nodes.
	ShouldTrack func(*dataflow.AnalyzerState, 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 LoadProgramOptions

type LoadProgramOptions struct {
	// BuildMode is the mode used when creating the SSA from the packages.
	BuildMode ssa.BuilderMode
	// LoadTests is a flag indicating whether tests should be loaded with the program.
	LoadTests bool
	// ApplyRewrites is a flag indicating whether the standard source rewrites should be applied.
	ApplyRewrites bool
	// Platform indicates which platform the analysis is being performed on (sets GOOS in env).
	Platform string
	// PackageConfig is the options passed to packages.Load.
	// The GOOS  in the Env of the packageConfig is overridden by the Platform when Platform is set.
	PackageConfig *packages.Config
}

LoadProgramOptions combines all the options that are used when loading programs.

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 syntactic contains syntactic analyses.
Package syntactic contains syntactic analyses.
structinit
Package structinit implements the struct initialization syntactic analysis.
Package structinit implements the struct initialization syntactic analysis.
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