Documentation
¶
Index ¶
- Constants
- func CapabilityGraph(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, ...)
- func GetCapabilityCounts(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, ...) *cpb.CapabilityCountList
- func GetCapabilityInfo(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, ...) *cpb.CapabilityInfoList
- func GetCapabilityStats(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, ...) *cpb.CapabilityStatList
- func GetClassifier(excludeUnanalyzed bool) *interesting.Classifier
- func GetQueriedPackages(pkgs []*packages.Package) map[*types.Package]struct{}
- func LoadPackages(packageNames []string, lcfg LoadConfig) ([]*packages.Package, error)
- func RunCapslock(args []string, output string, pkgs []*packages.Package, ...) error
- type CapabilityCounter
- type Classifier
- type Config
- type DifferenceFoundError
- type GraphOutputCallFn
- type GraphOutputCapabilityFn
- type GraphOutputNodeFn
- type LoadConfig
Constants ¶
const PackagesLoadModeNeeded packages.LoadMode = packages.NeedName | packages.NeedFiles | packages.NeedCompiledGoFiles | packages.NeedImports | packages.NeedDeps | packages.NeedTypes | packages.NeedSyntax | packages.NeedTypesInfo | packages.NeedTypesSizes | packages.NeedModule
PackagesLoadModeNeeded is a packages.LoadMode that has all the bits set for the information that this package uses to perform its analysis. Users should load packages for analysis using this LoadMode (or a superset.)
Variables ¶
This section is empty.
Functions ¶
func CapabilityGraph ¶
func CapabilityGraph(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, config *Config, outputNode GraphOutputNodeFn, outputCall GraphOutputCallFn, outputCapability GraphOutputCapabilityFn, filter func(capability cpb.Capability) bool, )
CapabilityGraph analyzes the callgraph for the packages in pkgs.
It outputs the graph containing all paths from a function belonging to one of the packages in queriedPackages to a function which has some capability.
outputNode is called for each node in the graph. Along with the node itself, it is passed the state of the BFS search from the queried packages, and the state of the BFS search from functions with a capability, so that the user can reconstruct an example call path including the node.
outputCall is called for each edge between two nodes.
outputCapability is called for each node in the graph that has some capability.
If filter is non-nil, it is called once for each capability. If it returns true, then CapabilityGraph generates a call graph for that individual capability and calls the relevant output functions, before proceeding to the next capability. If filter is nil, a single graph is generated including paths for all capabilities.
func GetCapabilityCounts ¶
func GetCapabilityCounts(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, config *Config) *cpb.CapabilityCountList
GetCapabilityCount analyzes the packages in pkgs. For each function in those packages which have a path in the callgraph to an "interesting" function (see the "interesting" package), we give an aggregate count of the capability usage.
func GetCapabilityInfo ¶
func GetCapabilityInfo(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, config *Config) *cpb.CapabilityInfoList
GetCapabilityInfo analyzes the packages in pkgs. For each function in those packages which have a path in the callgraph to an "interesting" function (see the "interesting" package), we log details of the capability usage.
One CapabilityInfo is returned for every (function, capability) pair, with one example path in the callgraph that demonstrates that capability.
func GetCapabilityStats ¶
func GetCapabilityStats(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, config *Config) *cpb.CapabilityStatList
GetCapabilityStats analyzes the packages in pkgs. For each function in those packages which have a path in the callgraph to an "interesting" function (see the "interesting" package), we give aggregated statistics about the capability usage.
func GetClassifier ¶
func GetClassifier(excludeUnanalyzed bool) *interesting.Classifier
GetClassifier returns a classifier for mapping packages and functions to the appropriate capability. If excludedUnanalyzed is true, the UNANALYZED capability is never returned.
func GetQueriedPackages ¶
GetQueriedPackages builds a set of *types.Package matching the input query so that we can limit the output to only functions in these packages, not their dependencies too.
func LoadPackages ¶
func LoadPackages(packageNames []string, lcfg LoadConfig) ([]*packages.Package, error)
Types ¶
type CapabilityCounter ¶
type CapabilityCounter struct {
// contains filtered or unexported fields
}
type Classifier ¶ added in v0.2.0
type Classifier interface {
// FunctionCategory returns a Category for the given function specified by
// a package name and function name. Examples of function names include
// "math.Cos", "(time.Time).Clock", and "(*sync.Cond).Signal".
//
// If the return value is Unspecified, then we have not declared it to be
// either safe or unsafe, so its descendants will have to be considered by the
// static analysis.
FunctionCategory(pkg string, name string) cpb.Capability
// IncludeCall returns true if a call from one function to another should be
// considered when searching for transitive capabilities. Usually this should
// return true, unless there is some reason to know that the particular call
// cannot lead to additional capabilities for a function.
IncludeCall(edge *callgraph.Edge) bool
}
Classifier is an interface for types that help map code features to capabilities.
type Config ¶ added in v0.2.0
type Config struct {
// Classifier is used to assign capabilities to functions.
Classifier Classifier
// DisableBuiltin disables some additional source-code analyses that find
// more capabilities in functions.
DisableBuiltin bool
// Granularity can be "package" or "function". It determines whether
// capability sets are examined per-package or per-function when doing
// comparisons.
Granularity string
// Capabilities is a comma-separated list of capabilities to use for graph
// output mode. Optionally, the capabilities can all be prefixed with a '-'
// character to indicate capabilities to omit.
// If the string is empty, all capabilities are used.
Capabilities string
}
Config holds configuration for the analyzer.
type DifferenceFoundError ¶ added in v0.2.3
type DifferenceFoundError struct{}
DifferenceFoundError indicates that a comparison was successfully run, and a difference was found.
func (DifferenceFoundError) Error ¶ added in v0.2.3
func (d DifferenceFoundError) Error() string
type GraphOutputCallFn ¶ added in v0.2.3
GraphOutputCallFn represents a function which is called by CapabilityGraph for each edge.
type GraphOutputCapabilityFn ¶ added in v0.2.3
type GraphOutputCapabilityFn func(fn *callgraph.Node, c cpb.Capability)
GraphOutputCapabilityFn represents a function which is called by CapabilityGraph for each function capability.
type GraphOutputNodeFn ¶ added in v0.2.3
GraphOutputNodeFn represents a function which is called by CapabilityGraph for each node.
type LoadConfig ¶
LoadConfig specifies the build tags, GOOS value, and GOARCH value to use when loading packages. These will be used to determine when a file's build constraint is satisfied. See https://pkg.go.dev/cmd/go#hdr-Build_constraints for more information.