package debug

import "github.com/open-policy-agent/opa/debug"

Package debug EXPERIMENTAL: This package is under active development and is subject to change.

Index

Constants

const (
	ExceptionEventType  = "exception"
	StdoutEventType     = "stdout"
	StoppedEventType    = "stopped"
	TerminatedEventType = "terminated"
	ThreadEventType     = "thread"
)

Types

type Breakpoint

type Breakpoint interface {
	ID() BreakpointID
	Location() location.Location
}

type BreakpointID

type BreakpointID int

type Debugger

type Debugger interface {
	// LaunchEval starts a new eval debug session with the given LaunchEvalProperties.
	// The returned session is in a stopped state, and must be resumed to start execution.
	LaunchEval(ctx context.Context, props LaunchEvalProperties) (Session, error)
}

Debugger is the interface for launching OPA debugger Session(s). This implementation is similar in structure to the Debug Adapter Protocol (DAP) to make such integrations easier, but is not intended to be a direct implementation. See: https://microsoft.github.io/debug-adapter-protocol/specification

EXPERIMENTAL: These interfaces are under active development and is subject to change.

func NewDebugger

func NewDebugger(options ...DebuggerOption) Debugger

type DebuggerOption

type DebuggerOption func(*debugger)

func SetEventHandler

func SetEventHandler(handler EventHandler) DebuggerOption

func SetLogger

func SetLogger(logger logging.Logger) DebuggerOption

type Event

type Event struct {
	Type    EventType
	Thread  ThreadID
	Message string
	// contains filtered or unexported fields
}

func (Event) String

func (d Event) String() string

type EventHandler

type EventHandler func(Event)

type EventType

type EventType string

type FrameID

type FrameID int

type LaunchEvalProperties

type LaunchEvalProperties struct {
	LaunchProperties
	Query     string
	Input     interface{}
	InputPath string
}

type LaunchProperties

type LaunchProperties struct {
	BundlePaths  []string
	DataPaths    []string
	StopOnResult bool
	StopOnEntry  bool
	StopOnFail   bool
	EnablePrint  bool
	SkipOps      []topdown.Op
	RuleIndexing bool
}

func (LaunchProperties) String

func (lp LaunchProperties) String() string

type LaunchTestProperties

type LaunchTestProperties struct {
	LaunchProperties
	Run string
}

type Scope

type Scope interface {
	// Name returns the human-readable name of the scope.
	Name() string

	// NamedVariables returns the number of named variables in the scope.
	NamedVariables() int

	// VariablesReference returns a reference to the variables in the scope.
	VariablesReference() VarRef

	// Location returns the in-source location of the scope.
	Location() *location.Location
}

Scope represents the variable state of a StackFrame.

type Session

type Session interface {
	// Resume resumes execution of the thread with the given ID.
	Resume(threadID ThreadID) error

	// ResumeAll resumes execution of all threads in the session.
	ResumeAll() error

	// StepOver executes the next expression in the current scope and then stops on the next expression in the same scope,
	// not stopping on expressions in sub-scopes; e.g. execution of referenced rule, called function, comprehension, or every expression.
	//
	// Example 1:
	//
	//	allow if {
	//	  x := f(input) >-+
	//	  x == 1        <-+
	//	}
	//
	// Example 2:
	//
	//	allow if {
	//	  every x in l { >-+
	//	    x < 10         |
	//	  }                |
	//	  input.x == 1   <-+
	//	}
	StepOver(threadID ThreadID) error

	// StepIn executes the next expression in the current scope and then stops on the next expression in the same scope or sub-scope;
	// stepping into any referenced rule, called function, comprehension, or every expression.
	//
	// Example 1:
	//
	//	allow if {
	//	  x := f(input) >-+
	//	  x == 1          |
	//	}                 |
	//	                  |
	//	f(x) := y if {  <-+
	//	  y := x + 1
	//	}
	//
	// Example 2:
	//
	//	allow if {
	//	  every x in l { >-+
	//	    x < 10       <-+
	//	  }
	//	  input.x == 1
	//	}
	StepIn(threadID ThreadID) error

	// StepOut steps out of the current scope (rule, function, comprehension, every expression) and stops on the next expression in the parent scope.
	//
	// Example 1:
	//
	//	allow if {
	//	  x := f(input) <-+
	//	  x == 1          |
	//	}                 |
	//	                  |
	//	f(x) := y if {    |
	//	  y := x + 1    >-+
	//	}
	//
	// Example 2:
	//
	//	allow if {
	//	  every x in l {
	//	    x < 10       >-+
	//	  }                |
	//	  input.x == 1   <-+
	//	}
	StepOut(threadID ThreadID) error

	// Threads returns a list of all threads in the session.
	Threads() ([]Thread, error)

	// Breakpoints returns a list of all set breakpoints.
	Breakpoints() ([]Breakpoint, error)

	// AddBreakpoint sets a breakpoint at the given location.
	AddBreakpoint(loc location.Location) (Breakpoint, error)

	// RemoveBreakpoint removes a given breakpoint.
	// The removed breakpoint is returned. If the breakpoint does not exist, nil is returned.
	RemoveBreakpoint(ID BreakpointID) (Breakpoint, error)

	// ClearBreakpoints removes all breakpoints.
	ClearBreakpoints() error

	// StackTrace returns the StackTrace for the thread with the given ID.
	// The stack trace is ordered from the most recent frame to the least recent frame.
	StackTrace(threadID ThreadID) (StackTrace, error)

	// Scopes returns the Scope list for the frame with the given ID.
	Scopes(frameID FrameID) ([]Scope, error)

	// Variables returns the Variable list for the given reference.
	Variables(varRef VarRef) ([]Variable, error)

	// Terminate stops all threads in the session.
	Terminate() error
}

type StackFrame

type StackFrame interface {
	// ID returns the unique identifier for the frame.
	ID() FrameID

	// Name returns the human-readable name of the frame.
	Name() string

	// Location returns the location of the frame in the source code.
	Location() *location.Location

	// Thread returns the ID of the thread that the frame is associated with.
	Thread() ThreadID

	// String returns a human-readable string representation of the frame.
	String() string

	// Equal returns true if the frame is equal to the other frame.
	Equal(other StackFrame) bool
}

type StackTrace

type StackTrace []StackFrame

StackTrace represents a StackFrame stack.

func (StackTrace) Equal

func (s StackTrace) Equal(other StackTrace) bool

type Thread

type Thread interface {
	ID() ThreadID
	Name() string
}

type ThreadID

type ThreadID int

type VarRef

type VarRef int

type Variable

type Variable interface {
	// Name returns the name of the variable.
	Name() string

	// Type returns the type of the variable.
	Type() string

	// Value returns the value of the variable.
	Value() string

	// VariablesReference returns a reference to the variables that are children of this variable.
	// E.g. this variable is a collection, such as an array, set, or object.
	VariablesReference() VarRef
}

Source Files

breakpoint.go debugger.go event.go frame.go latch.go thread.go trace.go variable.go

Version
v0.68.0
Published
Aug 29, 2024
Platform
js/wasm
Imports
18 packages
Last checked
32 minutes ago

Tools for package owners.