Debian Codegraph @

starlark/debug.go

raw
1 package starlark
2
3 import (
4 "go.starlark.net/syntax"
5 )
6
7 // This file defines an experimental API for the debugging tools.
8 // Some of these declarations expose details of internal packages.
9 // (The debugger makes liberal use of exported fields of unexported types.)
10 // Breaking changes may occur without notice.
11
12 // A Binding is the name and position of a binding identifier.
13 type Binding struct {
14 Name string
15 Pos syntax.Position
16 }
17
18 // NumLocals returns the number of local variables of this frame.
19 // It is zero unless fr.Callable() is a *Function.
20 func (fr *frame) NumLocals() int { return len(fr.locals) }
21
22 // Local returns the binding (name and binding position) and value of
23 // the i'th local variable of the frame's function.
24 // Beware: the value may be nil if it has not yet been assigned!
25 //
26 // The index i must be less than [NumLocals].
27 // Local may be called only while the frame is active.
28 //
29 // This function is provided only for debugging tools.
30 func (fr *frame) Local(i int) (Binding, Value) {
31 return Binding(fr.callable.(*Function).funcode.Locals[i]), fr.locals[i]
32 }
33
34 // DebugFrame is the debugger API for a frame of the interpreter's call stack.
35 //
36 // Most applications have no need for this API; use CallFrame instead.
37 //
38 // It may be tempting to use this interface when implementing built-in
39 // functions. Beware that reflection over the call stack is easily
40 // abused, leading to built-in functions whose behavior is mysterious
41 // and unpredictable.
42 //
43 // Clients must not retain a DebugFrame nor call any of its methods once
44 // the current built-in call has returned or execution has resumed
45 // after a breakpoint as this may have unpredictable effects, including
46 // but not limited to retention of object that would otherwise be garbage.
47 type DebugFrame interface {
48 Callable() Callable // returns the frame's function
49 NumLocals() int // returns the number of local variables in this frame
50 Local(i int) (Binding, Value) // returns the binding and value of the (Starlark) frame's ith local variable
51 Position() syntax.Position // returns the current position of execution in this frame
52 }
53
54 // DebugFrame returns the debugger interface for
55 // the specified frame of the interpreter's call stack.
56 // Frame numbering is as for Thread.CallFrame: 0 <= depth < thread.CallStackDepth().
57 //
58 // This function is intended for use in debugging tools.
59 // Most applications should have no need for it; use CallFrame instead.
60 func (thread *Thread) DebugFrame(depth int) DebugFrame { return thread.frameAt(depth) }