debugger

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package debugger is the core of Kukel's debuggers (TODO.md Q60, Q77): breakpoints, stepping, the stop at an exception nothing catches, and reading and changing the program's values. Its front ends are kukel debug (commands on a terminal) and kukel dap (the Debug Adapter Protocol, for editors).

The program runs a copy of its code with a BREAK at the start of every line (bytecode.Debuggable); the VM calls Session.Hook there, and Session.UncaughtHook where an exception nothing catches is thrown. Where the session decides to stop, it calls its Front, on the program's goroutine: the program waits until Stopped returns. Only the main interpreter stops; workers run on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assign

func Assign(m *vm.VM, i int, name string, v value.Value) bool

Assign gives the variable name, as Lookup finds it in frame i, the value v: a variable of the frame, a data member of this, a static data member, a global variable. It reports whether there is one that can change.

func Check added in v0.31.0

func Check(src string) error

Check reports what keeps Eval from evaluating src anywhere (it does not parse, or it has a call, an assignment, ...), or nil: for the condition of a breakpoint, when it is set.

func CheckHit

func CheckHit(cond string) error

CheckHit reports what is wrong with a hit count condition, or nil.

func Eval

func Eval(m *vm.VM, i int, src string) (value.Value, error)

Eval evaluates an expression as the function of frame i sees its names: literals, names (Lookup), the operators, ?:, indexing and members, vector and map literals. Nothing it does changes the program: calls, assignments, ++, new and function literals are refused.

func Interpolate

func Interpolate(m *vm.VM, frame int, msg string) string

Interpolate gives msg with each {expression} in it replaced by its value (as print shows it), or the error; {{ and }} are a { and a }.

func Lookup

func Lookup(m *vm.VM, i int, name string) (value.Value, bool)

Lookup finds a name as the function of frame i sees it: this, a variable, a data member of this, a static data member of its class, a global of its module, a global; or a qualified name: C::x (a static data member, of the module's class C first) or a module's global (util::count).

func SameFile

func SameFile(file, name string) bool

SameFile tells whether the file of a function is the one a breakpoint names: the same path, or the same name.

func Show added in v0.31.0

func Show(v value.Value) string

Show gives v as print shows it (Repr), shortened for the debugger: at most 100 elements of each vector or map, and about 1000 characters in all; "…" stands for what is left out. A value inside itself shows as [...], {...} or C{...}, as with Repr.

Types

type Breakpoint

type Breakpoint struct {
	ID             int
	File           string // the file of the function whose line it is
	Line           int
	Func           string
	Cond, Hit, Log string
	// contains filtered or unexported fields
}

Breakpoint stops the program at a line of a file. A function breakpoint (Func names the function) stops where a call of it starts, at its first line, and not where a loop on that line comes back to it. With Cond, it stops only when the condition is true there; with Hit, only when the count of its hits so far meets it ("3": the 3rd time, ">= 3", "% 2", ...); with Log, it shows the message instead of stopping, with {expression}s in it replaced by their values.

type Front

type Front interface {
	// Stopped is called when the program stops (on the program's
	// goroutine); the program goes on when it returns: as one of Continue,
	// Step, Next and Finish said, or ended by the error it returns.
	Stopped(m *vm.VM, s Stop) error
	// Log shows the message of a logpoint.
	Log(msg string)
}

Front is what a debugger shows the user and asks.

type Session

type Session struct {
	Prog *bytecode.Program
	// contains filtered or unexported fields
}

Session is the state of a debugger.

func New

func New(prog *bytecode.Program, front Front, stopOnEntry bool) *Session

New starts a session of prog (made by bytecode.Debuggable); with stopOnEntry it stops at the first line that runs.

func (*Session) Attach

func (s *Session) Attach(m *vm.VM)

Attach makes m stop as the session says.

func (*Session) Breaks

func (s *Session) Breaks() []Breakpoint

Breaks gives the breakpoints, in the order they were set.

func (*Session) Clear

func (s *Session) Clear(drop func(b *Breakpoint) bool)

Clear removes the breakpoints for which drop is true.

func (*Session) CodeLine

func (s *Session) CodeLine(file string, line int) (string, int, error)

CodeLine gives the first line with code at or after line in file, and the file's name as the program has it.

func (*Session) Continue

func (s *Session) Continue()

Continue, Step, Next and Finish say how the program goes on after a stop, at the frame depth of the stop (len(m.Frames())).

func (*Session) Finish

func (s *Session) Finish(depth int)

func (*Session) Function

func (s *Session) Function(name string) *bytecode.Function

Function finds a function by its name ("main", "Shape::area", "util::f").

func (*Session) Hook

func (s *Session) Hook(m *vm.VM) error

Hook runs at the start of every line (VM.Debug): it stops where the mode, a pause or a breakpoint says.

func (*Session) Next

func (s *Session) Next(depth int)

func (*Session) Pause

func (s *Session) Pause()

func (*Session) Paused

func (s *Session) Paused() bool

func (*Session) SetBreak

func (s *Session) SetBreak(b Breakpoint) (bp *Breakpoint, note string, err error)

SetBreak sets a breakpoint at a line of a file (the first line with code at or after it: the breakpoint's Line), or with a function's name at its first line. A note says when the line moved. A condition must be one Eval can evaluate (Check), a hit count one CheckHit takes.

func (*Session) SetUncaught

func (s *Session) SetUncaught(stop bool)

SetUncaught says whether the program stops where an exception nothing catches is thrown (it does when the session starts); from any goroutine.

func (*Session) Step

func (s *Session) Step()

func (*Session) UncaughtHook

func (s *Session) UncaughtHook(m *vm.VM, re *vm.RuntimeError) error

UncaughtHook stops where an exception is thrown that nothing catches (VM.DebugUncaught), unless SetUncaught(false): the frames can be looked at; the program ends when the front end lets it go on.

type Sources

type Sources map[string][]string

Sources reads source lines for showing, once per file.

func (Sources) Count added in v0.31.0

func (src Sources) Count(file string) int

Count gives the number of lines of file (0 if it cannot be read).

func (Sources) Line

func (src Sources) Line(file string, n int) (string, bool)

Line gives line n (1-based) of file.

type Stop

type Stop struct {
	Reason string           // "entry", "step", "breakpoint", "function breakpoint", "pause" or "exception"
	Breaks []int            // the breakpoints it stopped at
	Thrown *vm.RuntimeError // for "exception"
}

Stop says why the program stopped.

Jump to

Keyboard shortcuts

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