go: cloud.google.com/go/cmd/go-cloud-debug-agent/internal/valuecollector Index | Files

package valuecollector

import "cloud.google.com/go/cmd/go-cloud-debug-agent/internal/valuecollector"

Package valuecollector is used to collect the values of variables in a program.


Package Files


func LogString Uses

func LogString(s string, evaluatedExpressions []*cd.Variable, varTable []*cd.Variable) string

LogString produces a string for a logpoint, substituting in variable values using evaluatedExpressions and varTable.

type Collector Uses

type Collector struct {
    // contains filtered or unexported fields

Collector is given references to variables from a program being debugged using AddVariable. Then when ReadValues is called, the Collector will fetch the values of those variables. Any variables referred to by those values will also be fetched; e.g. the targets of pointers, members of structs, elements of slices, etc. This continues iteratively, building a graph of values, until all the reachable values are fetched, or a size limit is reached.

Variables are passed to the Collector as debug.Var, which is used by x/debug to represent references to variables. Values are returned as cd.Variable, which is used by the Debuglet Controller to represent the graph of values.

For example, if the program has a struct variable:

foo := SomeStruct{a:42, b:"xyz"}

and we call AddVariable with a reference to foo, we will get back a result like:

cd.Variable{Name:"foo", VarTableIndex:10}

which denotes a variable named "foo" which will have its value stored in element 10 of the table that will later be returned by ReadValues. That element might be:

out[10] = &cd.Variable{Members:{{Name:"a", VarTableIndex:11},{Name:"b", VarTableIndex:12}}}

which denotes a struct with two members a and b, whose values are in elements 11 and 12 of the output table:

out[11] = &cd.Variable{Value:"42"}
out[12] = &cd.Variable{Value:"xyz"}

func NewCollector Uses

func NewCollector(prog debug.Program, limit int) *Collector

NewCollector returns a Collector for the given program and size limit. The limit is the maximum size of the slice of values returned by ReadValues.

func (*Collector) AddVariable Uses

func (c *Collector) AddVariable(lv debug.LocalVar) *cd.Variable

AddVariable adds another variable to be collected. The Collector doesn't get the value immediately; it returns a cd.Variable that contains an index into the table which will later be returned by ReadValues.

func (*Collector) FillValue Uses

func (c *Collector) FillValue(v debug.Value, dcv *cd.Variable)

FillValue copies a value into a cd.Variable. Any variables referred to by that value, e.g. struct members and pointer targets, are added to the collector's queue, to be fetched later by ReadValues.

func (*Collector) ReadValues Uses

func (c *Collector) ReadValues() (out []*cd.Variable)

ReadValues fetches values of the variables that were passed to the Collector with AddVariable. The values of any new variables found are also fetched, e.g. the targets of pointers or the members of structs, until we reach the size limit or we run out of values to fetch. The results are output as a []*cd.Variable, which is the type we need to send to the Debuglet Controller after we trigger a breakpoint.

Package valuecollector imports 6 packages (graph) and is imported by 1 packages. Updated 2017-05-27. Refresh now. Tools for package owners.