cdebug

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotStartedErr = errors.New("debugger not started")

	IsRunningErr = errors.New("debugger is currently running and cannot return info")
)
View Source
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

View Source
var VariableType = types.AddType(&types.Type{Name: "cogentcore.org/cogent/code/cdebug.Variable", IDName: "variable", Doc: "Variable describes a variable.  It is a tree type so that full tree\ncan be visualized.", Embeds: []types.Field{{Name: "NodeBase"}}, Fields: []types.Field{{Name: "Value", Doc: "value of variable -- may be truncated if long"}, {Name: "TypeStr", Doc: "type of variable as a string expression (shortened for display)"}, {Name: "FullTypeStr", Doc: "type of variable as a string expression (full length)"}, {Name: "Kind", Doc: "kind of element"}, {Name: "ElValue", Doc: "own elemental value of variable (blank for composite types)"}, {Name: "Len", Doc: "length of variable (slices, maps, strings etc)"}, {Name: "Cap", Doc: "capacity of vaiable"}, {Name: "Addr", Doc: "address where variable is located in memory"}, {Name: "Heap", Doc: "if true, the variable is stored in the main memory heap, not the stack"}, {Name: "Loc", Doc: "location where the variable was defined in source"}, {Name: "List", Doc: "if kind is a list type (array, slice), and elements are primitive types, this is the contents"}, {Name: "Map", Doc: "if kind is a map, and elements are primitive types, this is the contents"}, {Name: "MapVar", Doc: "if kind is a map, and elements are not primitive types, this is the contents"}, {Name: "Dbg", Doc: "our debugger -- for getting further variable data"}}, Instance: &Variable{}})

VariableType is the types.Type for Variable

Functions

func SortBreaks

func SortBreaks(brk []*Break)

SortBreaks sorts breaks by id

func SortVars

func SortVars(vrs []*Variable)

SortVars sorts vars by name

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

func (as *AllState) AddBreak(fpath string, line int) *Break

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

func (as *AllState) BreakByFile(fpath string, line int) (*Break, int)

BreakByFile returns the given breakpoint by file path and line from list. returns nil, -1 if not found.

func (*AllState) BreakByID

func (as *AllState) BreakByID(id int) (*Break, int)

BreakByID returns the given breakpoint by ID from full list, and index. returns nil, -1 if not found.

func (*AllState) DeleteBreakByFile

func (as *AllState) DeleteBreakByFile(fpath string, line int) bool

DeleteBreakByFile deletes given break by File and Line from full list. Returns true if deleted.

func (*AllState) DeleteBreakByID

func (as *AllState) DeleteBreakByID(id int) bool

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

func (as *AllState) StackFrame(idx int) *Frame

StackFrame safely returns the given stack frame -- nil if out of range

func (*AllState) VarByName

func (as *AllState) VarByName(varNm string) *Variable

VarByName returns variable with the given name, or nil if not found

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:"-" width:"80"`

	// 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

func BreakByFile(bks []*Break, fpath string, line int) (*Break, int)

BreakByFile returns the given breakpoint by file path and line from list. returns nil, -1 if not found.

func BreakByID

func BreakByID(bks []*Break, id int) (*Break, int)

BreakByID returns the given breakpoint by ID from full list, and index. 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 `width:"80"`

	// 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.Buffer, 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 `width:"80"`
}

Location holds program location information.

type Modes

type Modes int32

Modes are different modes of running the debugger

const (
	// Exec means debug a standard executable program
	Exec Modes = iota

	// Test means debug a testing program
	Test

	// Attach means attach to an already-running process
	Attach
)

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).
	// For Debug test, must use -test.run instead of plain -run to specify tests to run.
	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.

func (*State) String

func (st *State) String() string

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) Desc

func (i Status) Desc() string

Desc returns the description of the Status value.

func (Status) Int64

func (i Status) Int64() int64

Int64 returns the Status value as an int64.

func (Status) MarshalText

func (i Status) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Status) SetInt64

func (i *Status) SetInt64(in int64)

SetInt64 sets the Status value from an int64.

func (*Status) SetString

func (i *Status) SetString(s string) error

SetString sets the Status value from its string representation, and returns an error if the string is invalid.

func (Status) String

func (i Status) String() string

String returns the string representation of this Status value.

func (*Status) UnmarshalText

func (i *Status) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Status) Values

func (i Status) Values() []enums.Enum

Values returns all possible values for the type Status.

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 `width:"80"`

	// 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.

func TaskByID

func TaskByID(thrs []*Task, id int) (*Task, int)

TaskByID returns the given thread by ID from full list, and index. returns nil, -1 if not found.

func (*Task) String

func (th *Task) String() string

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 `width:"80"`

	// 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

func ThreadByID(thrs []*Thread, id int) (*Thread, int)

ThreadByID returns the given thread by ID from full list, and index. returns nil, -1 if not found.

func (*Thread) String

func (th *Thread) String() string

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 `default:"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 {
	tree.NodeBase

	// 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 tree type so that full tree can be visualized.

func NewVariable

func NewVariable(parent tree.Node, name ...string) *Variable

NewVariable adds a new Variable with the given name to the given parent: Variable describes a variable. It is a tree type so that full tree can be visualized.

func (*Variable) FollowPtr

func (vr *Variable) FollowPtr()

FollowPtr retrieves the contents of this pointer and adds it as a child.

func (*Variable) Label

func (vr *Variable) Label() string

Label satisfies the core.Labeler interface for showing name = value

func (*Variable) New

func (t *Variable) New() tree.Node

New returns a new *Variable value

func (*Variable) NodeType added in v0.0.2

func (t *Variable) NodeType() *types.Type

NodeType returns the *types.Type of Variable

func (*Variable) SetAddr

func (t *Variable) SetAddr(v uintptr) *Variable

SetAddr sets the [Variable.Addr]: address where variable is located in memory

func (*Variable) SetCap

func (t *Variable) SetCap(v int64) *Variable

SetCap sets the [Variable.Cap]: capacity of vaiable

func (*Variable) SetDbg

func (t *Variable) SetDbg(v GiDebug) *Variable

SetDbg sets the [Variable.Dbg]: our debugger -- for getting further variable data

func (*Variable) SetElValue

func (t *Variable) SetElValue(v string) *Variable

SetElValue sets the [Variable.ElValue]: own elemental value of variable (blank for composite types)

func (*Variable) SetFullTypeStr

func (t *Variable) SetFullTypeStr(v string) *Variable

SetFullTypeStr sets the [Variable.FullTypeStr]: type of variable as a string expression (full length)

func (*Variable) SetHeap

func (t *Variable) SetHeap(v bool) *Variable

SetHeap sets the [Variable.Heap]: if true, the variable is stored in the main memory heap, not the stack

func (*Variable) SetKind

func (t *Variable) SetKind(v syms.Kinds) *Variable

SetKind sets the [Variable.Kind]: kind of element

func (*Variable) SetLen

func (t *Variable) SetLen(v int64) *Variable

SetLen sets the [Variable.Len]: length of variable (slices, maps, strings etc)

func (*Variable) SetList

func (t *Variable) SetList(v ...string) *Variable

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

func (t *Variable) SetLoc(v Location) *Variable

SetLoc sets the [Variable.Loc]: location where the variable was defined in source

func (*Variable) SetMap

func (t *Variable) SetMap(v map[string]string) *Variable

SetMap sets the [Variable.Map]: if kind is a map, and elements are primitive types, this is the contents

func (*Variable) SetMapVar

func (t *Variable) SetMapVar(v map[string]*Variable) *Variable

SetMapVar sets the [Variable.MapVar]: if kind is a map, and elements are not primitive types, this is the contents

func (*Variable) SetTypeStr

func (t *Variable) SetTypeStr(v string) *Variable

SetTypeStr sets the [Variable.TypeStr]: type of variable as a string expression (shortened for display)

func (*Variable) SetValue

func (t *Variable) SetValue(v string) *Variable

SetValue sets the [Variable.Value]: value of variable -- may be truncated if long

func (*Variable) TypeInfo

func (vr *Variable) TypeInfo(newlines bool) string

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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