Documentation ¶
Index ¶
- Variables
- func SortBreaks(brk []*Break)
- func SortVars(vrs []*Variable)
- type AllState
- func (as *AllState) AddBreak(fpath string, line int) *Break
- func (as *AllState) BlankState()
- func (as *AllState) BreakByFile(fpath string, line int) (*Break, int)
- func (as *AllState) BreakByID(id int) (*Break, int)
- func (as *AllState) DeleteBreakByFile(fpath string, line int) bool
- func (as *AllState) DeleteBreakByID(id int) bool
- func (as *AllState) MergeBreaks()
- func (as *AllState) StackFrame(idx int) *Frame
- func (as *AllState) VarByName(varNm string) *Variable
- type Break
- type Frame
- type GiDebug
- type Location
- type Modes
- type Params
- type State
- type Status
- func (i Status) Desc() string
- func (i Status) Int64() int64
- func (i Status) IsValid() bool
- func (i Status) MarshalText() ([]byte, error)
- func (i *Status) SetInt64(in int64)
- func (i *Status) SetString(s string) error
- func (i Status) String() string
- func (i *Status) UnmarshalText(text []byte) error
- func (i Status) Values() []enums.Enum
- type Task
- type Thread
- type VarParams
- type Variable
- func (vr *Variable) CopyFieldsFrom(frm any)
- func (vr *Variable) FollowPtr()
- func (t *Variable) KiType() *gti.Type
- func (vr *Variable) Label() string
- func (t *Variable) New() ki.Ki
- func (t *Variable) SetAddr(v uintptr) *Variable
- func (t *Variable) SetCap(v int64) *Variable
- func (t *Variable) SetDbg(v GiDebug) *Variable
- func (t *Variable) SetElValue(v string) *Variable
- func (t *Variable) SetFullTypeStr(v string) *Variable
- func (t *Variable) SetHeap(v bool) *Variable
- func (t *Variable) SetKind(v syms.Kinds) *Variable
- func (t *Variable) SetLen(v int64) *Variable
- func (t *Variable) SetList(v []string) *Variable
- func (t *Variable) SetLoc(v Location) *Variable
- func (t *Variable) SetMap(v map[string]string) *Variable
- func (t *Variable) SetMapVar(v map[string]*Variable) *Variable
- func (t *Variable) SetTypeStr(v string) *Variable
- func (t *Variable) SetValue(v string) *Variable
- func (vr *Variable) TypeInfo(newlines bool) string
- func (vr *Variable) ValueString(newlines bool, ident int, maxdepth, maxlen int, outType bool) string
Constants ¶
This section is empty.
Variables ¶
var ( NotStartedErr = errors.New("debugger not started") IsRunningErr = errors.New("debugger is currently running and cannot return info") )
var DefaultParams = Params{ VarList: VarParams{ FollowPointers: false, MaxRecurse: 4, MaxStringLen: 100, MaxArrayValues: 10, MaxStructFields: -1, }, GetVar: VarParams{ FollowPointers: false, MaxRecurse: 10, MaxStringLen: 1024, MaxArrayValues: 1024, MaxStructFields: -1, }, }
DefaultParams are default parameter values
var VariableType = gti.AddType(>i.Type{ Name: "goki.dev/gide/v2/gidebug.Variable", ShortName: "gidebug.Variable", IDName: "variable", Doc: "Variable describes a variable. It is a Ki tree type so that full tree\ncan be visualized.", Directives: gti.Directives{}, Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{ {"Value", >i.Field{Name: "Value", Type: "string", LocalType: "string", Doc: "value of variable -- may be truncated if long", Directives: gti.Directives{}, Tag: "inactive:\"-\" width:\"60\""}}, {"TypeStr", >i.Field{Name: "TypeStr", Type: "string", LocalType: "string", Doc: "type of variable as a string expression (shortened for display)", Directives: gti.Directives{}, Tag: "inactive:\"-\""}}, {"FullTypeStr", >i.Field{Name: "FullTypeStr", Type: "string", LocalType: "string", Doc: "type of variable as a string expression (full length)", Directives: gti.Directives{}, Tag: "view:\"-\" inactive:\"-\""}}, {"Kind", >i.Field{Name: "Kind", Type: "goki.dev/pi/v2/syms.Kinds", LocalType: "syms.Kinds", Doc: "kind of element", Directives: gti.Directives{}, Tag: "inactive:\"-\""}}, {"ElValue", >i.Field{Name: "ElValue", Type: "string", LocalType: "string", Doc: "own elemental value of variable (blank for composite types)", Directives: gti.Directives{}, Tag: "inactive:\"-\" view:\"-\""}}, {"Len", >i.Field{Name: "Len", Type: "int64", LocalType: "int64", Doc: "length of variable (slices, maps, strings etc)", Directives: gti.Directives{}, Tag: "inactive:\"-\""}}, {"Cap", >i.Field{Name: "Cap", Type: "int64", LocalType: "int64", Doc: "capacity of vaiable", Directives: gti.Directives{}, Tag: "inactive:\"-\" tableview:\"-\""}}, {"Addr", >i.Field{Name: "Addr", Type: "uintptr", LocalType: "uintptr", Doc: "address where variable is located in memory", Directives: gti.Directives{}, Tag: "inactive:\"-\""}}, {"Heap", >i.Field{Name: "Heap", Type: "bool", LocalType: "bool", Doc: "if true, the variable is stored in the main memory heap, not the stack", Directives: gti.Directives{}, Tag: "inactive:\"-\""}}, {"Loc", >i.Field{Name: "Loc", Type: "goki.dev/gide/v2/gidebug.Location", LocalType: "Location", Doc: "location where the variable was defined in source", Directives: gti.Directives{}, Tag: "inactive:\"-\" tableview:\"-\""}}, {"List", >i.Field{Name: "List", Type: "[]string", LocalType: "[]string", Doc: "if kind is a list type (array, slice), and elements are primitive types, this is the contents", Directives: gti.Directives{}, Tag: "tableview:\"-\""}}, {"Map", >i.Field{Name: "Map", Type: "map[string]string", LocalType: "map[string]string", Doc: "if kind is a map, and elements are primitive types, this is the contents", Directives: gti.Directives{}, Tag: "tableview:\"-\""}}, {"MapVar", >i.Field{Name: "MapVar", Type: "map[string]*goki.dev/gide/v2/gidebug.Variable", LocalType: "map[string]*Variable", Doc: "if kind is a map, and elements are not primitive types, this is the contents", Directives: gti.Directives{}, Tag: "tableview:\"-\""}}, {"Dbg", >i.Field{Name: "Dbg", Type: "goki.dev/gide/v2/gidebug.GiDebug", LocalType: "GiDebug", Doc: "our debugger -- for getting further variable data", Directives: gti.Directives{}, Tag: "view:\"-\""}}, }), Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{ {"Node", >i.Field{Name: "Node", Type: "goki.dev/ki/v2.Node", LocalType: "ki.Node", Doc: "", Directives: gti.Directives{}, Tag: ""}}, }), Methods: ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}), Instance: &Variable{}, })
Functions ¶
Types ¶
type AllState ¶
type AllState struct { // mode we're running in Mode Modes // overall debugger status Status Status // current run state State State // id of the current system thread to examine CurThread int // id of the current task to examine CurTask int // frame number within current thread CurFrame int // current breakpoint that we stopped at -- will be 0 if none, after UpdateState CurBreak int // all breakpoints that have been set -- some may not be On Breaks []*Break // current, active breakpoints as retrieved from debugger CurBreaks []*Break // all system threads Threads []*Thread // all tasks Tasks []*Task // current stack frame for current thread / task Stack []*Frame // current local variables and args for current frame Vars []*Variable // global variables for current thread / task GlobalVars []*Variable // current find-frames result FindFrames []*Frame }
AllState holds all relevant state information. This can be maintained and updated in the debug view.
func (*AllState) AddBreak ¶
AddBreak adds file path and line to full list of breaks. checks for an existing and turns it on if so.
func (*AllState) BlankState ¶
func (as *AllState) BlankState()
BlankState initializes state with a blank initial state with the various slices having a single entry -- for GUI initialization.
func (*AllState) BreakByFile ¶
BreakByFile returns the given breakpoint by file path and line from list. returns nil, -1 if not found.
func (*AllState) BreakByID ¶
BreakByID returns the given breakpoint by ID from full list, and index. returns nil, -1 if not found.
func (*AllState) DeleteBreakByFile ¶
DeleteBreakByFile deletes given break by File and Line from full list. Returns true if deleted.
func (*AllState) DeleteBreakByID ¶
DeleteBreakByID deletes given break by ID from full list. Returns true if deleted.
func (*AllState) MergeBreaks ¶
func (as *AllState) MergeBreaks()
MergeBreaks merges the current breaks with AllBreaks -- any not in Cur are indicated as !On
func (*AllState) StackFrame ¶
StackFrame safely returns the given stack frame -- nil if out of range
type Break ¶
type Break struct { // unique numerical ID of the breakpoint ID int `edit:"-"` // whether the breakpoint is currently enabled On bool `width:"4"` // program counter (address) -- may be subset of multiple PC uint64 `edit:"-" format:"%#X"` // file name (trimmed up to point of project base path) File string `edit:"-"` // line within file Line int `edit:"-"` // full path to file FPath string `edit:"-" view:"-" tableview:"-"` // the name of the function Func string `edit:"-"` // condition for conditional breakbpoint Cond string // if true, execution does not stop -- just a message is reported when this point is hit Trace bool `width:"7"` }
Break describes one breakpoint
func BreakByFile ¶
BreakByFile returns the given breakpoint by file path and line from list. returns nil, -1 if not found.
type Frame ¶
type Frame struct { // depth in overall stack -- 0 is the bottom (currently executing) frame, and it counts up from there Depth int // the Task or Thread id that this frame belongs to ThreadID int // program counter (address) -- may be subset of multiple PC uint64 `format:"%#X"` // file name (trimmed up to point of project base path) File string // line within file Line int // full path to file FPath string `tableview:"-" tableview:"-"` // the name of the function Func string // values of the local variables at this frame Vars []*Variable `tableview:"-"` // values of the local function args at this frame Args []*Variable `tableview:"-"` }
Frame describes one frame in a stack trace.
type GiDebug ¶
type GiDebug interface { // HasTasks returns true if the debugger supports a level of threading // below the system thread level. If true, then use Task data // otherwise, use Threads HasTasks() bool // Start starts the debugger for a given exe path, and overall project // root path (for trimming file names), and sets output of debugger // session to given textbuf which is used to monitor output. // params must have relevant settings in place (StatFunc, Mode, etc). Start(path, rootPath string, outbuf *texteditor.Buf, pars *Params) error // SetParams sets the current parameters to control how info is returned SetParams(params *Params) // IsActive returns true if the debugger is active and ready for commands IsActive() bool // Returns the pid of the process we are debugging. ProcessPid() int // LastModified returns the time that the process' executable was modified. LastModified() time.Time // Detach detaches the debugger, optionally killing the process. Detach(killProcess bool) error // Disconnect closes the connection to the server without // sending a Detach request first. If cont is true a continue // command will be sent instead. Disconnect(cont bool) error // Restarts program. Restart() error // GetState returns the current debugger state. // This will return immediately -- if the target is running then // the Running flag will be set and a Stop bus be called to // get any further information about the target. GetState() (*State, error) // Continue resumes process execution. The channel will block until the // process stops by any means. Tracepoints are automatically handled by // the debugger, and do not appear. Typically there is just one State // in the channel, but perhaps there could be more -- use a range to iterate // over all items in the channel -- it will close after data is sent. // The last state can be used for further updating. Continue(all *AllState) <-chan *State // StepOver continues to the next source line, not entering function calls. StepOver() (*State, error) // StepInto continues to the next source line, entering function calls. StepInto() (*State, error) // StepOut continues to the return point of the current function StepOut() (*State, error) // StepSingle step a single cpu instruction. StepSingle() (*State, error) // SwitchThread switches the current system thread context to given one SwitchThread(threadID int) (*State, error) // SwitchTask switches the current thread to given one SwitchTask(threadID int) (*State, error) // Stop suspends the process. Stop() (*State, error) // GetBreak gets info about a breakpoint by ID. GetBreak(id int) (*Break, error) // SetBreak sets a new breakpoint at given file (must be enough to be unique) // and line number SetBreak(fname string, line int) (*Break, error) // ListBreaks gets all breakpoints. ListBreaks() ([]*Break, error) // ClearBreak deletes a breakpoint by ID. ClearBreak(id int) error // AmmendBreak updates the Condition and Trace information // for the given breakpoint AmendBreak(id int, fname string, line int, cond string, trace bool) error // UpdateBreaks updates current breakpoints based on given list of breakpoints. // first gets the current list, and does actions to ensure that the list is set. UpdateBreaks(brk *[]*Break) error // Cancels a Next or Step call that was interrupted by a // manual stop or by another breakpoint CancelNext() error // InitAllState initializes the given AllState with relevant info // for current debugger state. Does NOT get AllVars. InitAllState(all *AllState) error // UpdateAllState updates the state for given threadId and // frame number (only info different from current results is updated). // For given thread (lowest-level supported by language, // e.g., Task if supported, else Thread), and frame number. UpdateAllState(all *AllState, threadID int, frame int) error // FindFrames looks through the Stacks of all Tasks / Threads // for the closest Stack Frame to given file and line number. // Results are sorted by line number proximity to given line. FindFrames(all *AllState, fname string, line int) ([]*Frame, error) // CurThreadID returns the proper current threadID (task or thread) // based on debugger, from given state. CurThreadID(all *AllState) int // ListThreads lists all system threads. ListThreads() ([]*Thread, error) // GetThread gets a thread by its ID. GetThread(id int) (*Thread, error) // ListTasks lists all the currently active threads (if supported) ListTasks() ([]*Task, error) // Stack returns the current stack, up to given depth, // for given thread (lowest-level supported by language, // e.g., Task if supported, else Thread), and frame number. Stack(threadID int, depth int) ([]*Frame, error) // ListGlobalVars lists global variables (subject to filter) in the context // of the current thread. ListGlobalVars(filter string) ([]*Variable, error) // ListVars lists all stack-frame local variables (including args) // for given thread (lowest-level supported by language, // e.g., Task if supported, else Thread), and frame number. ListVars(threadID int, frame int) ([]*Variable, error) // GetVar returns a variable for given thread (lowest-level supported by // language -- e.g., Task if supported, else Thread), and frame number, // from given expression, which depending on debugger can be a full // expression (e.g., path, address with cast, etc) GetVar(expr string, threadID int, frame int) (*Variable, error) // FollowPtr fills in the Child of given Variable // with retrieved value. Uses last eval scope. FollowPtr(vr *Variable) error // SetVar sets the value of a variable. // for given thread (lowest-level supported by language, // e.g., Task if supported, else Thread), and frame number. SetVar(name, value string, threadID int, frame int) error // ListSources lists all source files in the process matching filter. ListSources(filter string) ([]string, error) // ListFuncs lists all functions in the process matching filter. ListFuncs(filter string) ([]string, error) // ListTypes lists all types in the process matching filter. ListTypes(filter string) ([]string, error) // WriteToConsole writes given message string to the debugger's output console. // message should end in newline WriteToConsole(msg string) }
GiDebug is the interface for all supported debuggers. It is based directly on the Delve Client interface.
type Location ¶
type Location struct { // program counter (address) -- may be subset of multiple PC uint64 `format:"%#X"` // file name (trimmed up to point of project base path) File string // line within file Line int // full path to file FPath string `view:"-" tableview:"-"` // the name of the function Func string }
Location holds program location information.
type Params ¶
type Params struct { // mode for running the debugger Mode Modes `xml:"-" toml:"-" json:"-" view:"-"` // process id number to attach to, for Attach mode PID uint64 `xml:"-" toml:"-" json:"-" view:"-"` // optional extra args to pass to the debugger. Use double-dash -- and then add args to pass args to the executable (double-dash is by itself as a separate arg first) Args []string // status function for debugger updating status StatFunc func(stat Status) `xml:"-" toml:"-" json:"-" view:"-"` // parameters for level of detail on overall list of variables VarList VarParams // parameters for level of detail retrieving a specific variable GetVar VarParams }
Params are overall debugger parameters
type State ¶
type State struct { // currently executing system thread Thread Thread // currently executing task Task Task // true if the process is running and no other information can be collected. Running bool // if true, a Next or Step is already in progress and another should not be attempted until after a Continue NextUp bool // if true, the program has exited Exited bool // indicates the exit status if Exited ExitStatus int // error communicated to client -- if non-empty, something bad happened Err error // if this is > 0, then we just hit that tracepoint -- the Continue process will continue execution CurTrace int }
State represents the current immediate execution state of the debugger.
type Status ¶
type Status int32 //enums:enum
Status of the debugger
const ( // NotInit is not initialized NotInit Status = iota // Error means the debugger has an error -- usually from building Error // Building is building the exe for debugging Building // Ready means executable is built and ready to start (or restarted) Ready // Running means the process is running Running // Stopped means the process has stopped // (at a breakpoint, crash, or from single stepping) Stopped // Breakpoint means the process has stopped at a breakpoint Breakpoint // Finished means the process has finished running. // See console for output and return value etc Finished )
const StatusN Status = 8
StatusN is the highest valid value for type Status, plus one.
func StatusValues ¶
func StatusValues() []Status
StatusValues returns all possible values for the type Status.
func (Status) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Status) SetString ¶
SetString sets the Status value from its string representation, and returns an error if the string is invalid.
func (*Status) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Task ¶
type Task struct { // task identifier ID int // program counter (address) -- may be subset of multiple PC uint64 `format:"%#X"` // file name (trimmed up to point of project base path) File string // line within file Line int // full path to file FPath string `tableview:"-" tableview:"-"` // the name of the function Func string // id of the current Thread this task is running on Thread int `format:"%#X"` // where did this task first start running? StartLoc Location `tableview:"-"` // at what point was this task launched from another task? LaunchLoc Location `tableview:"-"` }
Task is an optional finer-grained, lighter-weight thread, e.g., a goroutine in the Go language. if GiDebug HasTasks() == false then it is not used.
type Thread ¶
type Thread struct { // thread identifier ID int `format:"%#X"` // program counter (address) -- may be subset of multiple PC uint64 `format:"%#X"` // file name (trimmed up to point of project base path) File string // line within file Line int // full path to file FPath string `tableview:"-"` // the name of the function Func string // id of the current Task within this system thread (if relevant) Task int }
Thread is a system-level thread within the debugged process. For many languages, this is synonymous with functional threads, but if HasTasks() is true from GiDebug, then there are separate Task constructs as well, which provide a finer-grained processing within the Thread. For example, go routines in Go are represented by Tasks in the GiDebug framework.
func ThreadByID ¶
ThreadByID returns the given thread by ID from full list, and index. returns nil, -1 if not found.
type VarParams ¶
type VarParams struct { // requests pointers to be automatically dereferenced -- this can be very dangerous in terms of size of variable data returned and is not recommended. FollowPointers bool `def:"false"` // how far to recurse when evaluating nested types. MaxRecurse int // the maximum number of bytes read from a string MaxStringLen int // the maximum number of elements read from an array, a slice or a map. MaxArrayValues int // the maximum number of fields read from a struct, -1 will read all fields. MaxStructFields int }
VarParams are parameters controlling how much detail the debugger reports about variables.
type Variable ¶
type Variable struct { ki.Node // value of variable -- may be truncated if long Value string `inactive:"-" width:"60"` // type of variable as a string expression (shortened for display) TypeStr string `inactive:"-"` // type of variable as a string expression (full length) FullTypeStr string `view:"-" inactive:"-"` // kind of element Kind syms.Kinds `inactive:"-"` // own elemental value of variable (blank for composite types) ElValue string `inactive:"-" view:"-"` // length of variable (slices, maps, strings etc) Len int64 `inactive:"-"` // capacity of vaiable Cap int64 `inactive:"-" tableview:"-"` // address where variable is located in memory Addr uintptr `inactive:"-"` // if true, the variable is stored in the main memory heap, not the stack Heap bool `inactive:"-"` // location where the variable was defined in source Loc Location `inactive:"-" tableview:"-"` // if kind is a list type (array, slice), and elements are primitive types, this is the contents List []string `tableview:"-"` // if kind is a map, and elements are primitive types, this is the contents Map map[string]string `tableview:"-"` // if kind is a map, and elements are not primitive types, this is the contents MapVar map[string]*Variable `tableview:"-"` // our debugger -- for getting further variable data Dbg GiDebug `view:"-"` }
Variable describes a variable. It is a Ki tree type so that full tree can be visualized.
func NewVariable ¶
NewVariable adds a new Variable with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.
func (*Variable) CopyFieldsFrom ¶
func (*Variable) FollowPtr ¶
func (vr *Variable) FollowPtr()
FollowPtr retrieves the contents of this pointer and adds it as a child.
func (*Variable) SetAddr ¶
SetAddr sets the [Variable.Addr]: address where variable is located in memory
func (*Variable) SetDbg ¶
SetDbg sets the [Variable.Dbg]: our debugger -- for getting further variable data
func (*Variable) SetElValue ¶
SetElValue sets the [Variable.ElValue]: own elemental value of variable (blank for composite types)
func (*Variable) SetFullTypeStr ¶
SetFullTypeStr sets the [Variable.FullTypeStr]: type of variable as a string expression (full length)
func (*Variable) SetHeap ¶
SetHeap sets the [Variable.Heap]: if true, the variable is stored in the main memory heap, not the stack
func (*Variable) SetLen ¶
SetLen sets the [Variable.Len]: length of variable (slices, maps, strings etc)
func (*Variable) SetList ¶
SetList sets the [Variable.List]: if kind is a list type (array, slice), and elements are primitive types, this is the contents
func (*Variable) SetLoc ¶
SetLoc sets the [Variable.Loc]: location where the variable was defined in source
func (*Variable) SetMap ¶
SetMap sets the [Variable.Map]: if kind is a map, and elements are primitive types, this is the contents
func (*Variable) SetMapVar ¶
SetMapVar sets the [Variable.MapVar]: if kind is a map, and elements are not primitive types, this is the contents
func (*Variable) SetTypeStr ¶
SetTypeStr sets the [Variable.TypeStr]: type of variable as a string expression (shortened for display)
func (*Variable) SetValue ¶
SetValue sets the [Variable.Value]: value of variable -- may be truncated if long
func (*Variable) TypeInfo ¶
TypeInfo returns a string of type information -- if newlines, then include newlines between each item (else tabs)
func (*Variable) ValueString ¶
func (vr *Variable) ValueString(newlines bool, ident int, maxdepth, maxlen int, outType bool) string
ValueString returns the value of the variable, integrating over sub-elements if newlines, each element is separated by a new line, and indented. Generally this should be used to set the Value field after getting new data. The maxdepth and maxlen parameters provide constraints on the detail provided by this string. outType indicates whether to output type name